1 /* 2 * Copyright (C) 2023 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.app.admin; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 23 import java.util.HashSet; 24 import java.util.Objects; 25 import java.util.Set; 26 27 /** 28 * @hide 29 */ 30 public final class StringSetPolicyValue extends PolicyValue<Set<String>> { 31 StringSetPolicyValue(@onNull Set<String> value)32 public StringSetPolicyValue(@NonNull Set<String> value) { 33 super(value); 34 } 35 StringSetPolicyValue(Parcel source)36 public StringSetPolicyValue(Parcel source) { 37 this(readValues(source)); 38 } 39 readValues(Parcel source)40 private static Set<String> readValues(Parcel source) { 41 Set<String> values = new HashSet<>(); 42 int size = source.readInt(); 43 for (int i = 0; i < size; i++) { 44 values.add(source.readString()); 45 } 46 return values; 47 } 48 49 @Override equals(@ullable Object o)50 public boolean equals(@Nullable Object o) { 51 if (this == o) return true; 52 if (o == null || getClass() != o.getClass()) return false; 53 StringSetPolicyValue other = (StringSetPolicyValue) o; 54 return Objects.equals(getValue(), other.getValue()); 55 } 56 57 @Override hashCode()58 public int hashCode() { 59 return Objects.hash(getValue()); 60 } 61 62 @Override toString()63 public String toString() { 64 return "StringSetPolicyValue { " + getValue() + " }"; 65 } 66 67 @Override describeContents()68 public int describeContents() { 69 return 0; 70 } 71 72 @Override writeToParcel(@onNull Parcel dest, int flags)73 public void writeToParcel(@NonNull Parcel dest, int flags) { 74 dest.writeInt(getValue().size()); 75 for (String entry : getValue()) { 76 dest.writeString(entry); 77 } 78 } 79 80 @NonNull 81 public static final Creator<StringSetPolicyValue> CREATOR = 82 new Creator<StringSetPolicyValue>() { 83 @Override 84 public StringSetPolicyValue createFromParcel(Parcel source) { 85 return new StringSetPolicyValue(source); 86 } 87 88 @Override 89 public StringSetPolicyValue[] newArray(int size) { 90 return new StringSetPolicyValue[size]; 91 } 92 }; 93 } 94