1 package 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 19 import android.content.ComponentName; 20 import android.os.UserHandle; 21 22 import java.util.Arrays; 23 24 public class ComponentKey { 25 26 public final ComponentName componentName; 27 public final UserHandle user; 28 29 private final int mHashCode; 30 ComponentKey(ComponentName componentName, UserHandle user)31 public ComponentKey(ComponentName componentName, UserHandle user) { 32 if (componentName == null || user == null) { 33 throw new NullPointerException(); 34 } 35 this.componentName = componentName; 36 this.user = user; 37 mHashCode = Arrays.hashCode(new Object[] {componentName, user}); 38 39 } 40 41 @Override hashCode()42 public int hashCode() { 43 return mHashCode; 44 } 45 46 @Override equals(Object o)47 public boolean equals(Object o) { 48 ComponentKey other = (ComponentKey) o; 49 return other.componentName.equals(componentName) && other.user.equals(user); 50 } 51 52 /** 53 * Encodes a component key as a string of the form [flattenedComponentString#userId]. 54 */ 55 @Override toString()56 public String toString() { 57 return componentName.flattenToString() + "#" + user; 58 } 59 }