Debian Codegraph @

core/java/android/os/ParcelUuid.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2009 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.os;
18
19 import android.annotation.Nullable;
20 import android.compat.annotation.UnsupportedAppUsage;
21
22 import java.util.UUID;
23
24 /**
25 * This class is a Parcelable wrapper around {@link UUID} which is an
26 * immutable representation of a 128-bit universally unique
27 * identifier.
28 */
29 public final class ParcelUuid implements Parcelable {
30
31 private final UUID mUuid;
32
33 /**
34 * Constructor creates a ParcelUuid instance from the
35 * given {@link UUID}.
36 *
37 * @param uuid UUID
38 */
39 public ParcelUuid(UUID uuid) {
40 mUuid = uuid;
41 }
42
43 /**
44 * Creates a new ParcelUuid from a string representation of {@link UUID}.
45 *
46 * @param uuid
47 * the UUID string to parse.
48 * @return a ParcelUuid instance.
49 * @throws NullPointerException
50 * if {@code uuid} is {@code null}.
51 * @throws IllegalArgumentException
52 * if {@code uuid} is not formatted correctly.
53 */
54 public static ParcelUuid fromString(String uuid) {
55 return new ParcelUuid(UUID.fromString(uuid));
56 }
57
58 /**
59 * Get the {@link UUID} represented by the ParcelUuid.
60 *
61 * @return UUID contained in the ParcelUuid.
62 */
63 public UUID getUuid() {
64 return mUuid;
65 }
66
67 /**
68 * Returns a string representation of the ParcelUuid
69 * For example: 0000110B-0000-1000-8000-00805F9B34FB will be the return value.
70 *
71 * @return a String instance.
72 */
73 @Override
74 public String toString() {
75 return mUuid.toString();
76 }
77
78
79 @Override
80 public int hashCode() {
81 return mUuid.hashCode();
82 }
83
84 /**
85 * Compares this ParcelUuid to another object for equality. If {@code object}
86 * is not {@code null}, is a ParcelUuid instance, and all bits are equal, then
87 * {@code true} is returned.
88 *
89 * @param object
90 * the {@code Object} to compare to.
91 * @return {@code true} if this ParcelUuid is equal to {@code object}
92 * or {@code false} if not.
93 */
94 @Override
95 public boolean equals(@Nullable Object object) {
96 if (object == null) {
97 return false;
98 }
99
100 if (this == object) {
101 return true;
102 }
103
104 if (!(object instanceof ParcelUuid)) {
105 return false;
106 }
107
108 ParcelUuid that = (ParcelUuid) object;
109
110 return (this.mUuid.equals(that.mUuid));
111 }
112
113 public static final @android.annotation.NonNull Parcelable.Creator<ParcelUuid> CREATOR =
114 new Parcelable.Creator<ParcelUuid>() {
115 @UnsupportedAppUsage
116 public ParcelUuid createFromParcel(Parcel source) {
117 long mostSigBits = source.readLong();
118 long leastSigBits = source.readLong();
119 UUID uuid = new UUID(mostSigBits, leastSigBits);
120 return new ParcelUuid(uuid);
121 }
122
123 public ParcelUuid[] newArray(int size) {
124 return new ParcelUuid[size];
125 }
126 };
127
128 public int describeContents() {
129 return 0;
130 }
131
132 public void writeToParcel(Parcel dest, int flags) {
133 dest.writeLong(mUuid.getMostSignificantBits());
134 dest.writeLong(mUuid.getLeastSignificantBits());
135 }
136 }