1package com.android.launcher3.util;
2
3/**
4 * Copyright (C) 2015 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19import android.content.ComponentName;
20import android.os.UserHandle;
21
22import java.util.Arrays;
23
24public class ComponentKey {
25
26    public final ComponentName componentName;
27    public final UserHandle user;
28
29    private final int mHashCode;
30
31    public ComponentKey(ComponentName componentName, UserHandle user) {
32        Preconditions.assertNotNull(componentName);
33        Preconditions.assertNotNull(user);
34        this.componentName = componentName;
35        this.user = user;
36        mHashCode = Arrays.hashCode(new Object[] {componentName, user});
37
38    }
39
40    @Override
41    public int hashCode() {
42        return mHashCode;
43    }
44
45    @Override
46    public boolean equals(Object o) {
47        ComponentKey other = (ComponentKey) o;
48        return other.componentName.equals(componentName) && other.user.equals(user);
49    }
50
51    /**
52     * Encodes a component key as a string of the form [flattenedComponentString#userId].
53     */
54    @Override
55    public String toString() {
56        return componentName.flattenToString() + "#" + user;
57    }
58}