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 import java.util.ArrayList; 23 import java.util.Arrays; 24 import java.util.Collections; 25 import java.util.HashSet; 26 import java.util.List; 27 import java.util.Set; 28 29 /** 30 * A dependency for a VMS layer on other VMS layers. 31 * 32 * @hide 33 */ 34 @FutureFeature 35 public final class VmsLayerDependency implements Parcelable { 36 private final VmsLayer mLayer; 37 private final Set<VmsLayer> mDependency; 38 39 /** 40 * Construct a dependency for layer on other layers. 41 */ 42 public VmsLayerDependency(VmsLayer layer, Set<VmsLayer> dependencies) { 43 mLayer = layer; 44 mDependency = Collections.unmodifiableSet(dependencies); 45 } 46 47 /** 48 * Constructs a layer without a dependency. 49 */ 50 public VmsLayerDependency(VmsLayer layer) { 51 mLayer = layer; 52 mDependency = Collections.emptySet(); 53 } 54 55 /** 56 * Checks if a layer has a dependency. 57 */ 58 public boolean hasDependencies() { 59 return (!mDependency.isEmpty()); 60 } 61 62 public VmsLayer getLayer() { 63 return mLayer; 64 } 65 66 /** 67 * Returns the dependencies. 68 */ 69 public Set<VmsLayer> getDependencies() { 70 return mDependency; 71 } 72 73 public static final Parcelable.Creator<VmsLayerDependency> CREATOR = new 74 Parcelable.Creator<VmsLayerDependency>() { 75 public VmsLayerDependency createFromParcel(Parcel in) { 76 return new VmsLayerDependency(in); 77 } 78 public VmsLayerDependency[] newArray(int size) { 79 return new VmsLayerDependency[size]; 80 } 81 }; 82 83 @Override 84 public void writeToParcel(Parcel out, int flags) { 85 out.writeParcelable(mLayer, flags); 86 out.writeParcelableList(new ArrayList<VmsLayer>(mDependency), flags); 87 } 88 89 @Override 90 public int describeContents() { 91 return 0; 92 } 93 94 private VmsLayerDependency(Parcel in) { 95 mLayer = in.readParcelable(VmsLayer.class.getClassLoader()); 96 List<VmsLayer> dependency = new ArrayList<>(); 97 in.readParcelableList(dependency, VmsLayer.class.getClassLoader()); 98 mDependency = Collections.unmodifiableSet(new HashSet<VmsLayer>(dependency)); 99 } 100 }