• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE;
20 
21 import android.annotation.NonNull;
22 import android.annotation.SystemApi;
23 import android.car.annotation.AddedInOrBefore;
24 import android.car.builtin.os.ParcelHelper;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 import android.util.ArraySet;
28 
29 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
30 import com.android.car.internal.util.AnnotationValidations;
31 
32 import java.util.Collections;
33 import java.util.Objects;
34 import java.util.Set;
35 
36 /**
37  * Layer dependencies for single Vehicle Map Service layer.
38  *
39  * Dependencies are treated as <b>hard</b> dependencies, meaning that an offered layer will not be
40  * reported as available until all dependent layers are also available.
41  *
42  * @hide
43  */
44 @SystemApi
45 public final class VmsLayerDependency implements Parcelable {
46     /**
47      * Layer that has dependencies
48      */
49     private final @NonNull VmsLayer mLayer;
50 
51     /**
52      * Layers that the given layer depends on
53      */
54     private @NonNull Set<VmsLayer> mDependencies;
55 
onConstructed()56     private void onConstructed() {
57         mDependencies = Collections.unmodifiableSet(mDependencies);
58     }
59 
parcelDependencies(Parcel dest)60     private void parcelDependencies(Parcel dest) {
61         ParcelHelper.writeArraySet(dest, new ArraySet<>(mDependencies));
62     }
63 
64     @SuppressWarnings("unchecked")
unparcelDependencies(Parcel in)65     private Set<VmsLayer> unparcelDependencies(Parcel in) {
66         return (Set<VmsLayer>) ParcelHelper.readArraySet(in, VmsLayer.class.getClassLoader());
67     }
68 
69     /**
70      * Creates a new VmsLayerDependency without dependencies.
71      *
72      * @param layer
73      *   Layer that has no dependencies
74      */
VmsLayerDependency(@onNull VmsLayer layer)75     public VmsLayerDependency(@NonNull VmsLayer layer) {
76         this(layer, Collections.emptySet());
77     }
78 
79     /**
80      * Creates a new VmsLayerDependency.
81      *
82      * @param layer
83      *   Layer that has dependencies
84      * @param dependencies
85      *   Layers that the given layer depends on
86      */
VmsLayerDependency( @onNull VmsLayer layer, @NonNull Set<VmsLayer> dependencies)87     public VmsLayerDependency(
88             @NonNull VmsLayer layer,
89             @NonNull Set<VmsLayer> dependencies) {
90         this.mLayer = layer;
91         AnnotationValidations.validate(
92                 NonNull.class, null, mLayer);
93         this.mDependencies = dependencies;
94         AnnotationValidations.validate(
95                 NonNull.class, null, mDependencies);
96 
97         onConstructed();
98     }
99 
100     /**
101      * Layer that has dependencies
102      */
103     @AddedInOrBefore(majorVersion = 33)
getLayer()104     public @NonNull VmsLayer getLayer() {
105         return mLayer;
106     }
107 
108     /**
109      * Layers that the given layer depends on
110      */
111     @AddedInOrBefore(majorVersion = 33)
getDependencies()112     public @NonNull Set<VmsLayer> getDependencies() {
113         return mDependencies;
114     }
115 
116     @Override
toString()117     public String toString() {
118         // You can override field toString logic by defining methods like:
119         // String fieldNameToString() { ... }
120 
121         return "VmsLayerDependency { " +
122                 "layer = " + mLayer + ", " +
123                 "dependencies = " + mDependencies +
124         " }";
125     }
126 
127     @Override
equals(@ndroid.annotation.Nullable Object o)128     public boolean equals(@android.annotation.Nullable Object o) {
129         // You can override field equality logic by defining either of the methods like:
130         // boolean fieldNameEquals(VmsLayerDependency other) { ... }
131         // boolean fieldNameEquals(FieldType otherValue) { ... }
132 
133         if (this == o) return true;
134         if (o == null || getClass() != o.getClass()) return false;
135         @SuppressWarnings("unchecked")
136         VmsLayerDependency that = (VmsLayerDependency) o;
137         //noinspection PointlessBooleanExpression
138         return true
139                 && Objects.equals(mLayer, that.mLayer)
140                 && Objects.equals(mDependencies, that.mDependencies);
141     }
142 
143     @Override
hashCode()144     public int hashCode() {
145         // You can override field hashCode logic by defining methods like:
146         // int fieldNameHashCode() { ... }
147 
148         int _hash = 1;
149         _hash = 31 * _hash + Objects.hashCode(mLayer);
150         _hash = 31 * _hash + Objects.hashCode(mDependencies);
151         return _hash;
152     }
153 
154     @Override
155     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)156     public void writeToParcel(@NonNull Parcel dest, int flags) {
157         // You can override field parcelling by defining methods like:
158         // void parcelFieldName(Parcel dest, int flags) { ... }
159 
160         dest.writeTypedObject(mLayer, flags);
161         parcelDependencies(dest);
162     }
163 
164     @Override
165     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
166     @AddedInOrBefore(majorVersion = 33)
describeContents()167     public int describeContents() { return 0; }
168 
169     /** @hide */
170     @SuppressWarnings({"unchecked", "RedundantCast"})
VmsLayerDependency(@onNull Parcel in)171     /* package-private */ VmsLayerDependency(@NonNull Parcel in) {
172         // You can override field unparcelling by defining methods like:
173         // static FieldType unparcelFieldName(Parcel in) { ... }
174 
175         VmsLayer layer = (VmsLayer) in.readTypedObject(VmsLayer.CREATOR);
176         Set<VmsLayer> dependencies = unparcelDependencies(in);
177 
178         this.mLayer = layer;
179         AnnotationValidations.validate(
180                 NonNull.class, null, mLayer);
181         this.mDependencies = dependencies;
182         AnnotationValidations.validate(
183                 NonNull.class, null, mDependencies);
184 
185         onConstructed();
186     }
187 
188     @AddedInOrBefore(majorVersion = 33)
189     public static final @NonNull Parcelable.Creator<VmsLayerDependency> CREATOR
190             = new Parcelable.Creator<VmsLayerDependency>() {
191         @Override
192         public VmsLayerDependency[] newArray(int size) {
193             return new VmsLayerDependency[size];
194         }
195 
196         @Override
197         public VmsLayerDependency createFromParcel(@NonNull Parcel in) {
198             return new VmsLayerDependency(in);
199         }
200     };
201 }
202