Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 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 | |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 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 | */ |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 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 | |
| 37 | public VmsAssociatedLayer(VmsLayer layer, Set<Integer> publisherIds) { |
| 38 | mLayer = layer; |
| 39 | mPublisherIds = Collections.unmodifiableSet(publisherIds); |
| 40 | } |
| 41 | |
| 42 | public VmsLayer getVmsLayer() { |
| 43 | return mLayer; |
| 44 | } |
| 45 | |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 46 | public Set<Integer> getPublisherIds() { |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 47 | return mPublisherIds; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 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 |
| 68 | public void writeToParcel(Parcel out, int flags) { |
| 69 | out.writeParcelable(mLayer, flags); |
| 70 | out.writeArray(mPublisherIds.toArray()); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 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 |
Asaf Rosenfeld | 9e1c315 | 2018-02-02 08:47:10 -0800 | [diff] [blame] | 83 | public int hashCode() { |
| 84 | return Objects.hash(mLayer, mPublisherIds); |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Asaf Rosenfeld | 9e1c315 | 2018-02-02 08:47:10 -0800 | [diff] [blame] | 88 | public int describeContents() { |
| 89 | return 0; |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | private VmsAssociatedLayer(Parcel in) { |
| 93 | mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); |
| 94 | |
Asaf Rosenfeld | 9e1c315 | 2018-02-02 08:47:10 -0800 | [diff] [blame] | 95 | Object[] objects = in.readArray(Integer.class.getClassLoader()); |
| 96 | Integer[] integers = Arrays.copyOf(objects, objects.length, Integer[].class); |
| 97 | |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 98 | mPublisherIds = Collections.unmodifiableSet( |
Asaf Rosenfeld | 9e1c315 | 2018-02-02 08:47:10 -0800 | [diff] [blame] | 99 | new HashSet<>(Arrays.asList(integers))); |
Asaf Rosenfeld | 4390053 | 2017-06-16 11:16:55 -0700 | [diff] [blame] | 100 | } |
Asaf Rosenfeld | 9e1c315 | 2018-02-02 08:47:10 -0800 | [diff] [blame] | 101 | } |