blob: d3f0e189839d2fde32701126ed52f9ae8e15bdbe [file] [log] [blame]
Asaf Rosenfeld43900532017-06-16 11:16:55 -07001/*
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
17package android.car.vms;
18
Asaf Rosenfeld43900532017-06-16 11:16:55 -070019import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.*;
23
24/**
25 * A VMS Layer with a list of publisher IDs it is associated with.
26 *
27 * @hide
28 */
Asaf Rosenfeld43900532017-06-16 11:16:55 -070029public 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 Rosenfeld2e45d812017-08-31 23:51:12 -070046 public Set<Integer> getPublisherIds() {
Asaf Rosenfeld43900532017-06-16 11:16:55 -070047 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 Rosenfeld9e1c3152018-02-02 08:47:10 -080083 public int hashCode() {
84 return Objects.hash(mLayer, mPublisherIds);
Asaf Rosenfeld43900532017-06-16 11:16:55 -070085 }
86
87 @Override
Asaf Rosenfeld9e1c3152018-02-02 08:47:10 -080088 public int describeContents() {
89 return 0;
Asaf Rosenfeld43900532017-06-16 11:16:55 -070090 }
91
92 private VmsAssociatedLayer(Parcel in) {
93 mLayer = in.readParcelable(VmsLayer.class.getClassLoader());
94
Asaf Rosenfeld9e1c3152018-02-02 08:47:10 -080095 Object[] objects = in.readArray(Integer.class.getClassLoader());
96 Integer[] integers = Arrays.copyOf(objects, objects.length, Integer[].class);
97
Asaf Rosenfeld43900532017-06-16 11:16:55 -070098 mPublisherIds = Collections.unmodifiableSet(
Asaf Rosenfeld9e1c3152018-02-02 08:47:10 -080099 new HashSet<>(Arrays.asList(integers)));
Asaf Rosenfeld43900532017-06-16 11:16:55 -0700100 }
Asaf Rosenfeld9e1c3152018-02-02 08:47:10 -0800101}