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.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import com.android.internal.util.Preconditions; 25 26 import java.util.*; 27 28 /** 29 * A Vehicle Map Service layer with a list of publisher IDs it is associated with. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public final class VmsAssociatedLayer implements Parcelable { 35 private final VmsLayer mLayer; 36 private final Set<Integer> mPublisherIds; 37 38 /** 39 * Constructs a new layer offering. 40 * 41 * @param layer layer being offered 42 * @param publisherIds IDs of publishers associated with the layer 43 */ VmsAssociatedLayer(@onNull VmsLayer layer, @NonNull Set<Integer> publisherIds)44 public VmsAssociatedLayer(@NonNull VmsLayer layer, @NonNull Set<Integer> publisherIds) { 45 mLayer = Preconditions.checkNotNull(layer, "layer cannot be null"); 46 mPublisherIds = Collections.unmodifiableSet(publisherIds); 47 } 48 49 /** 50 * @return layer being offered 51 */ 52 @NonNull getVmsLayer()53 public VmsLayer getVmsLayer() { 54 return mLayer; 55 } 56 57 /** 58 * @return IDs of publishers associated with the layer 59 */ 60 @NonNull getPublisherIds()61 public Set<Integer> getPublisherIds() { 62 return mPublisherIds; 63 } 64 65 @Override toString()66 public String toString() { 67 return "VmsAssociatedLayer{ VmsLayer: " + mLayer + ", Publishers: " + mPublisherIds + "}"; 68 } 69 70 public static final Parcelable.Creator<VmsAssociatedLayer> CREATOR = 71 new Parcelable.Creator<VmsAssociatedLayer>() { 72 public VmsAssociatedLayer createFromParcel(Parcel in) { 73 return new VmsAssociatedLayer(in); 74 } 75 76 public VmsAssociatedLayer[] newArray(int size) { 77 return new VmsAssociatedLayer[size]; 78 } 79 }; 80 81 @Override writeToParcel(Parcel out, int flags)82 public void writeToParcel(Parcel out, int flags) { 83 out.writeParcelable(mLayer, flags); 84 out.writeArray(mPublisherIds.toArray()); 85 } 86 87 @Override equals(Object o)88 public boolean equals(Object o) { 89 if (!(o instanceof VmsAssociatedLayer)) { 90 return false; 91 } 92 VmsAssociatedLayer p = (VmsAssociatedLayer) o; 93 return Objects.equals(p.mLayer, mLayer) && p.mPublisherIds.equals(mPublisherIds); 94 } 95 96 @Override hashCode()97 public int hashCode() { 98 return Objects.hash(mLayer, mPublisherIds); 99 } 100 101 @Override describeContents()102 public int describeContents() { 103 return 0; 104 } 105 VmsAssociatedLayer(Parcel in)106 private VmsAssociatedLayer(Parcel in) { 107 mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); 108 109 Object[] objects = in.readArray(Integer.class.getClassLoader()); 110 Integer[] integers = Arrays.copyOf(objects, objects.length, Integer[].class); 111 112 mPublisherIds = Collections.unmodifiableSet( 113 new HashSet<>(Arrays.asList(integers))); 114 } 115 } 116