1 /* 2 * Copyright (C) 2022 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 com.android.car.hal.fakevhal; 18 19 import android.annotation.Nullable; 20 import android.hardware.automotive.vehicle.RawPropValues; 21 import android.hardware.automotive.vehicle.VehiclePropConfig; 22 import android.util.SparseArray; 23 24 import java.util.Objects; 25 26 /** 27 * ConfigDeclaration class contains both configs and initial values of a property. 28 */ 29 public final class ConfigDeclaration { 30 31 private final VehiclePropConfig mConfig; 32 private final RawPropValues mInitialValue; 33 private final SparseArray<RawPropValues> mInitialAreaValuesByAreaId; 34 ConfigDeclaration(VehiclePropConfig config, @Nullable RawPropValues initialValue, SparseArray<RawPropValues> initialAreaValuesByAreaId)35 public ConfigDeclaration(VehiclePropConfig config, @Nullable RawPropValues initialValue, 36 SparseArray<RawPropValues> initialAreaValuesByAreaId) { 37 this.mConfig = Objects.requireNonNull(config, "config cannot be null."); 38 this.mInitialValue = initialValue; 39 this.mInitialAreaValuesByAreaId = Objects.requireNonNull(initialAreaValuesByAreaId, 40 "initialAreaValueByAreaId cannot be null."); 41 } 42 43 @Override toString()44 public String toString() { 45 return new StringBuilder("ConfigDeclaration{ mConfig = ").append(mConfig) 46 .append(", mInitialValue = ").append(mInitialValue) 47 .append(", mInitialAreaValuesByAreaId = ").append(mInitialAreaValuesByAreaId) 48 .append(" }").toString(); 49 } 50 51 @Override equals(Object obj)52 public boolean equals(Object obj) { 53 if (this == obj) { 54 return true; 55 } 56 if (!(obj instanceof ConfigDeclaration)) { 57 return false; 58 } 59 ConfigDeclaration other = (ConfigDeclaration) obj; 60 61 return mConfig.equals(other.getConfig()) 62 && Objects.equals(mInitialValue, other.getInitialValue()) 63 && mInitialAreaValuesByAreaId.contentEquals(other.getInitialAreaValuesByAreaId()); 64 } 65 66 @Override hashCode()67 public int hashCode() { 68 return Objects.hash(mConfig, mInitialValue, mInitialAreaValuesByAreaId.contentHashCode()); 69 } 70 71 /** 72 * Gets the property config. 73 */ getConfig()74 public VehiclePropConfig getConfig() { 75 return mConfig; 76 } 77 78 /** 79 * Gets the initial value for the property. 80 */ getInitialValue()81 public RawPropValues getInitialValue() { 82 return mInitialValue; 83 } 84 85 /** 86 * Gets the area initial values for the property. Key is areaId and value is the initial value. 87 * 88 * @return a Map with mappings between areaId and initial values. 89 */ getInitialAreaValuesByAreaId()90 public SparseArray<RawPropValues> getInitialAreaValuesByAreaId() { 91 return mInitialAreaValuesByAreaId; 92 } 93 } 94