1 /* 2 * Copyright (C) 2017 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.car.vms; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import java.util.*; 23 24 /** 25 * A VMS Layer with a list of publisher IDs it is associated with. 26 * 27 * @hide 28 */ 29 public final class VmsAssociatedLayer implements Parcelable { 30 31 // The VmsLayer. 32 private final VmsLayer mLayer; 33 34 // The IDs of the publishers that can publish this VmsLayer. 35 private final Set<Integer> mPublisherIds; 36 VmsAssociatedLayer(VmsLayer layer, Set<Integer> publisherIds)37 public VmsAssociatedLayer(VmsLayer layer, Set<Integer> publisherIds) { 38 mLayer = layer; 39 mPublisherIds = Collections.unmodifiableSet(publisherIds); 40 } 41 getVmsLayer()42 public VmsLayer getVmsLayer() { 43 return mLayer; 44 } 45 getPublisherIds()46 public Set<Integer> getPublisherIds() { 47 return mPublisherIds; 48 } 49 50 @Override toString()51 public String toString() { 52 return "VmsAssociatedLayer{ VmsLayer: " + mLayer + ", Publishers: " + mPublisherIds + "}"; 53 } 54 55 // Parcelable related methods. 56 public static final Parcelable.Creator<VmsAssociatedLayer> CREATOR = 57 new Parcelable.Creator<VmsAssociatedLayer>() { 58 public VmsAssociatedLayer createFromParcel(Parcel in) { 59 return new VmsAssociatedLayer(in); 60 } 61 62 public VmsAssociatedLayer[] newArray(int size) { 63 return new VmsAssociatedLayer[size]; 64 } 65 }; 66 67 @Override writeToParcel(Parcel out, int flags)68 public void writeToParcel(Parcel out, int flags) { 69 out.writeParcelable(mLayer, flags); 70 out.writeArray(mPublisherIds.toArray()); 71 } 72 73 @Override equals(Object o)74 public boolean equals(Object o) { 75 if (!(o instanceof VmsAssociatedLayer)) { 76 return false; 77 } 78 VmsAssociatedLayer p = (VmsAssociatedLayer) o; 79 return Objects.equals(p.mLayer, mLayer) && p.mPublisherIds.equals(mPublisherIds); 80 } 81 82 @Override hashCode()83 public int hashCode() { 84 return Objects.hash(mLayer, mPublisherIds); 85 } 86 87 @Override describeContents()88 public int describeContents() { 89 return 0; 90 } 91 VmsAssociatedLayer(Parcel in)92 private VmsAssociatedLayer(Parcel in) { 93 mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); 94 95 Object[] objects = in.readArray(Integer.class.getClassLoader()); 96 Integer[] integers = Arrays.copyOf(objects, objects.length, Integer[].class); 97 98 mPublisherIds = Collections.unmodifiableSet( 99 new HashSet<>(Arrays.asList(integers))); 100 } 101 } 102