• 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, int flags)60     private void parcelDependencies(Parcel dest, int flags) {
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
117     @AddedInOrBefore(majorVersion = 33)
toString()118     public String toString() {
119         // You can override field toString logic by defining methods like:
120         // String fieldNameToString() { ... }
121 
122         return "VmsLayerDependency { " +
123                 "layer = " + mLayer + ", " +
124                 "dependencies = " + mDependencies +
125         " }";
126     }
127 
128     @Override
129     @AddedInOrBefore(majorVersion = 33)
equals(@ndroid.annotation.Nullable Object o)130     public boolean equals(@android.annotation.Nullable Object o) {
131         // You can override field equality logic by defining either of the methods like:
132         // boolean fieldNameEquals(VmsLayerDependency other) { ... }
133         // boolean fieldNameEquals(FieldType otherValue) { ... }
134 
135         if (this == o) return true;
136         if (o == null || getClass() != o.getClass()) return false;
137         @SuppressWarnings("unchecked")
138         VmsLayerDependency that = (VmsLayerDependency) o;
139         //noinspection PointlessBooleanExpression
140         return true
141                 && Objects.equals(mLayer, that.mLayer)
142                 && Objects.equals(mDependencies, that.mDependencies);
143     }
144 
145     @Override
146     @AddedInOrBefore(majorVersion = 33)
hashCode()147     public int hashCode() {
148         // You can override field hashCode logic by defining methods like:
149         // int fieldNameHashCode() { ... }
150 
151         int _hash = 1;
152         _hash = 31 * _hash + Objects.hashCode(mLayer);
153         _hash = 31 * _hash + Objects.hashCode(mDependencies);
154         return _hash;
155     }
156 
157     @Override
158     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)159     public void writeToParcel(@NonNull Parcel dest, int flags) {
160         // You can override field parcelling by defining methods like:
161         // void parcelFieldName(Parcel dest, int flags) { ... }
162 
163         dest.writeTypedObject(mLayer, flags);
164         parcelDependencies(dest, flags);
165     }
166 
167     @Override
168     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
169     @AddedInOrBefore(majorVersion = 33)
describeContents()170     public int describeContents() { return 0; }
171 
172     /** @hide */
173     @SuppressWarnings({"unchecked", "RedundantCast"})
VmsLayerDependency(@onNull Parcel in)174     /* package-private */ VmsLayerDependency(@NonNull Parcel in) {
175         // You can override field unparcelling by defining methods like:
176         // static FieldType unparcelFieldName(Parcel in) { ... }
177 
178         VmsLayer layer = (VmsLayer) in.readTypedObject(VmsLayer.CREATOR);
179         Set<VmsLayer> dependencies = unparcelDependencies(in);
180 
181         this.mLayer = layer;
182         AnnotationValidations.validate(
183                 NonNull.class, null, mLayer);
184         this.mDependencies = dependencies;
185         AnnotationValidations.validate(
186                 NonNull.class, null, mDependencies);
187 
188         onConstructed();
189     }
190 
191     @AddedInOrBefore(majorVersion = 33)
192     public static final @NonNull Parcelable.Creator<VmsLayerDependency> CREATOR
193             = new Parcelable.Creator<VmsLayerDependency>() {
194         @Override
195         public VmsLayerDependency[] newArray(int size) {
196             return new VmsLayerDependency[size];
197         }
198 
199         @Override
200         public VmsLayerDependency createFromParcel(@NonNull Parcel in) {
201             return new VmsLayerDependency(in);
202         }
203     };
204 }
205