Debian Codegraph @

core/java/android/print/PrinterId.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * This class represents the unique id of a printer.
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 * Creates a new instance.
39 *
40 * @param serviceName The managing print service.
41 * @param localId The locally unique id within the managing service.
42 *
43 * @hide
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 * The id of the print service this printer is managed by.
57 *
58 * @return The print service component name.
59 *
60 * @hide
61 */
62 @UnsupportedAppUsage
63 public @NonNull ComponentName getServiceName() {
64 return mServiceName;
65 }
66
67 /**
68 * Gets the id of this printer which is unique in the context
69 * of the print service that manages it.
70 *
71 * @return The printer name.
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 }