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.car.annotation.FutureFeature;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.util.Objects;
24 
25 /**
26  * A VMS Layer which can be subscribed to by VMS clients.
27  * Consists of the layer ID and the layer version.
28  *
29  * @hide
30  */
31 @FutureFeature
32 public final class VmsLayer implements Parcelable {
33 
34     // The layer ID.
35     private int mId;
36 
37     // The layer version.
38     private int mVersion;
39 
VmsLayer(int id, int version)40     public VmsLayer(int id, int version) {
41         mId = id;
42         mVersion = version;
43     }
44 
getId()45     public int getId() {
46         return mId;
47     }
48 
getVersion()49     public int getVersion() {
50         return mVersion;
51     }
52 
53     /**
54      * Checks the two objects for equality by comparing their IDs and Versions.
55      *
56      * @param o the {@link VmsLayer} to which this one is to be checked for equality
57      * @return true if the underlying objects of the VmsLayer are both considered equal
58      */
59     @Override
equals(Object o)60     public boolean equals(Object o) {
61         if (!(o instanceof VmsLayer)) {
62             return false;
63         }
64         VmsLayer p = (VmsLayer) o;
65         return Objects.equals(p.mId, mId) && Objects.equals(p.mVersion, mVersion);
66     }
67 
68     /**
69      * Compute a hash code similarly tp {@link android.util.Pair}
70      *
71      * @return a hashcode of the Pair
72      */
73     @Override
hashCode()74     public int hashCode() {
75         return Objects.hash(mId, mVersion);
76     }
77 
78     @Override
toString()79     public String toString() {
80         return "VmsLayer{" + mId + " " + mVersion + "}";
81     }
82 
83 
84     // Parcelable related methods.
85     public static final Parcelable.Creator<VmsLayer> CREATOR = new
86             Parcelable.Creator<VmsLayer>() {
87                 public VmsLayer createFromParcel(Parcel in) {
88                     return new VmsLayer(in);
89                 }
90 
91                 public VmsLayer[] newArray(int size) {
92                     return new VmsLayer[size];
93                 }
94             };
95 
96     @Override
writeToParcel(Parcel out, int flags)97     public void writeToParcel(Parcel out, int flags) {
98         out.writeInt(mId);
99         out.writeInt(mVersion);
100     }
101 
102     @Override
describeContents()103     public int describeContents() {
104         return 0;
105     }
106 
VmsLayer(Parcel in)107     private VmsLayer(Parcel in) {
108         readFromParcel(in);
109     }
110 
readFromParcel(Parcel in)111     private void readFromParcel(Parcel in) {
112         mId = in.readInt();
113         mVersion = in.readInt();
114     }
115 }