asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [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 | |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 17 | package android.car.vms; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 18 | |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
| 26 | * A VMS Layer which can be subscribed to by VMS clients. |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 27 | * |
| 28 | * @hide |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 29 | */ |
Asaf Rosenfeld | 39e4f03 | 2017-09-16 11:33:50 -0700 | [diff] [blame] | 30 | @SystemApi |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 31 | public final class VmsLayer implements Parcelable { |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 32 | |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 33 | // The layer Type. |
| 34 | private int mType; |
| 35 | |
| 36 | // The layer Subtype. |
| 37 | private int mSubtype; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 38 | |
| 39 | // The layer version. |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 40 | private int mVersion; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 41 | |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 42 | public VmsLayer(int type, int subtype, int version) { |
| 43 | mType = type; |
| 44 | mSubtype = subtype; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 45 | mVersion = version; |
| 46 | } |
| 47 | |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 48 | public int getType() { |
| 49 | return mType; |
| 50 | } |
| 51 | |
| 52 | public int getSubtype() { |
| 53 | return mSubtype; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | public int getVersion() { |
| 57 | return mVersion; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Checks the two objects for equality by comparing their IDs and Versions. |
| 62 | * |
| 63 | * @param o the {@link VmsLayer} to which this one is to be checked for equality |
| 64 | * @return true if the underlying objects of the VmsLayer are both considered equal |
| 65 | */ |
| 66 | @Override |
| 67 | public boolean equals(Object o) { |
| 68 | if (!(o instanceof VmsLayer)) { |
| 69 | return false; |
| 70 | } |
| 71 | VmsLayer p = (VmsLayer) o; |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 72 | return Objects.equals(p.mType, mType) && |
| 73 | Objects.equals(p.mSubtype, mSubtype) && |
| 74 | Objects.equals(p.mVersion, mVersion); |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Compute a hash code similarly tp {@link android.util.Pair} |
| 79 | * |
| 80 | * @return a hashcode of the Pair |
| 81 | */ |
| 82 | @Override |
| 83 | public int hashCode() { |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 84 | return Objects.hash(mType, mSubtype, mVersion); |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public String toString() { |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 89 | return "VmsLayer{ Type: " + mType + ", Sub type: " + mSubtype + ", Version: " + mVersion + "}"; |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 90 | } |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 91 | |
| 92 | |
| 93 | // Parcelable related methods. |
| 94 | public static final Parcelable.Creator<VmsLayer> CREATOR = new |
| 95 | Parcelable.Creator<VmsLayer>() { |
| 96 | public VmsLayer createFromParcel(Parcel in) { |
| 97 | return new VmsLayer(in); |
| 98 | } |
| 99 | |
| 100 | public VmsLayer[] newArray(int size) { |
| 101 | return new VmsLayer[size]; |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | @Override |
| 106 | public void writeToParcel(Parcel out, int flags) { |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 107 | out.writeInt(mType); |
| 108 | out.writeInt(mSubtype); |
Asaf Rosenfeld | 58e180b | 2017-07-27 21:06:30 -0700 | [diff] [blame] | 109 | out.writeInt(mVersion); |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public int describeContents() { |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | private VmsLayer(Parcel in) { |
| 118 | readFromParcel(in); |
| 119 | } |
| 120 | |
| 121 | private void readFromParcel(Parcel in) { |
Asaf Rosenfeld | 2e45d81 | 2017-08-31 23:51:12 -0700 | [diff] [blame] | 122 | mType = in.readInt(); |
| 123 | mSubtype = in.readInt(); |
Asaf Rosenfeld | 58e180b | 2017-07-27 21:06:30 -0700 | [diff] [blame] | 124 | mVersion = in.readInt(); |
Antonio Cortes | 0bd67c3 | 2017-03-13 08:02:40 -0700 | [diff] [blame] | 125 | } |
asafro | e102dc6 | 2017-02-23 14:54:11 -0800 | [diff] [blame] | 126 | } |