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.view.textclassifier; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Binder; 22 import android.os.IBinder; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.util.Locale; 27 import java.util.Objects; 28 import java.util.UUID; 29 30 /** 31 * This class represents the id of a text classification session. 32 */ 33 public final class TextClassificationSessionId implements Parcelable { 34 @NonNull 35 private final String mValue; 36 @NonNull 37 private final IBinder mToken; 38 39 /** 40 * Creates a new instance. 41 * 42 * @hide 43 */ TextClassificationSessionId()44 public TextClassificationSessionId() { 45 this(UUID.randomUUID().toString(), new Binder()); 46 } 47 48 /** 49 * Creates a new instance. 50 * 51 * @param value The internal value. 52 * 53 * @hide 54 */ TextClassificationSessionId(@onNull String value, @NonNull IBinder token)55 public TextClassificationSessionId(@NonNull String value, @NonNull IBinder token) { 56 mValue = Objects.requireNonNull(value); 57 mToken = Objects.requireNonNull(token); 58 } 59 60 /** @hide */ 61 @NonNull getToken()62 public IBinder getToken() { 63 return mToken; 64 } 65 66 @Override equals(@ullable Object o)67 public boolean equals(@Nullable Object o) { 68 if (this == o) return true; 69 if (o == null || getClass() != o.getClass()) return false; 70 TextClassificationSessionId that = (TextClassificationSessionId) o; 71 return Objects.equals(mValue, that.mValue) && Objects.equals(mToken, that.mToken); 72 } 73 74 @Override hashCode()75 public int hashCode() { 76 return Objects.hash(mValue, mToken); 77 } 78 79 @Override toString()80 public String toString() { 81 return String.format(Locale.US, "TextClassificationSessionId {%s}", mValue); 82 } 83 84 @Override writeToParcel(Parcel parcel, int flags)85 public void writeToParcel(Parcel parcel, int flags) { 86 parcel.writeString(mValue); 87 parcel.writeStrongBinder(mToken); 88 } 89 90 @Override describeContents()91 public int describeContents() { 92 return 0; 93 } 94 95 /** 96 * Returns the value of this ID. 97 */ 98 @NonNull getValue()99 public String getValue() { 100 return mValue; 101 } 102 103 @NonNull 104 public static final Parcelable.Creator<TextClassificationSessionId> CREATOR = 105 new Parcelable.Creator<TextClassificationSessionId>() { 106 @Override 107 public TextClassificationSessionId createFromParcel(Parcel parcel) { 108 return new TextClassificationSessionId( 109 parcel.readString(), parcel.readStrongBinder()); 110 } 111 112 @Override 113 public TextClassificationSessionId[] newArray(int size) { 114 return new TextClassificationSessionId[size]; 115 } 116 }; 117 } 118