| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.print; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.compat.annotation.UnsupportedAppUsage; |
| 22 |
import android.content.ComponentName; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import com.android.internal.util.Preconditions; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public final class PrinterId implements Parcelable { |
| 32 |
|
| 33 |
private final @NonNull ComponentName mServiceName; |
| 34 |
|
| 35 |
private final @NonNull String mLocalId; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public PrinterId(@NonNull ComponentName serviceName, @NonNull String localId) { |
| 46 |
mServiceName = serviceName; |
| 47 |
mLocalId = localId; |
| 48 |
} |
| 49 |
|
| 50 |
private PrinterId(@NonNull Parcel parcel) { |
| 51 |
mServiceName = Preconditions.checkNotNull((ComponentName) parcel.readParcelable(null, android.content.ComponentName.class)); |
| 52 |
mLocalId = Preconditions.checkNotNull(parcel.readString()); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
@UnsupportedAppUsage |
| 63 |
public @NonNull ComponentName getServiceName() { |
| 64 |
return mServiceName; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public @NonNull String getLocalId() { |
| 74 |
return mLocalId; |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public int describeContents() { |
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
public void writeToParcel(Parcel parcel, int flags) { |
| 84 |
parcel.writeParcelable(mServiceName, flags); |
| 85 |
parcel.writeString(mLocalId); |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
public boolean equals(@Nullable Object object) { |
| 90 |
if (this == object) { |
| 91 |
return true; |
| 92 |
} |
| 93 |
if (object == null) { |
| 94 |
return false; |
| 95 |
} |
| 96 |
if (getClass() != object.getClass()) { |
| 97 |
return false; |
| 98 |
} |
| 99 |
PrinterId other = (PrinterId) object; |
| 100 |
if (!mServiceName.equals(other.mServiceName)) { |
| 101 |
return false; |
| 102 |
} |
| 103 |
if (!mLocalId.equals(other.mLocalId)) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
return true; |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public int hashCode() { |
| 111 |
final int prime = 31; |
| 112 |
int hashCode = 1; |
| 113 |
hashCode = prime * hashCode + mServiceName.hashCode(); |
| 114 |
hashCode = prime * hashCode + mLocalId.hashCode(); |
| 115 |
return hashCode; |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public String toString() { |
| 120 |
StringBuilder builder = new StringBuilder(); |
| 121 |
builder.append("PrinterId{"); |
| 122 |
builder.append("serviceName=").append(mServiceName.flattenToString()); |
| 123 |
builder.append(", localId=").append(mLocalId); |
| 124 |
builder.append('}'); |
| 125 |
return builder.toString(); |
| 126 |
} |
| 127 |
|
| 128 |
public static final @android.annotation.NonNull Parcelable.Creator<PrinterId> CREATOR = |
| 129 |
new Creator<PrinterId>() { |
| 130 |
@Override |
| 131 |
public PrinterId createFromParcel(Parcel parcel) { |
| 132 |
return new PrinterId(parcel); |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public PrinterId[] newArray(int size) { |
| 137 |
return new PrinterId[size]; |
| 138 |
} |
| 139 |
}; |
| 140 |
} |