1 /* 2 * Copyright (C) 2023 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 package com.android.internal.widget.remotecompose.core.operations.utilities; 17 18 import android.annotation.Nullable; 19 20 /** 21 * Support a standardized interface to commands that contain arrays All commands that implement 22 * array access will be collected in a map in the state TODO refactor to DataAccess, 23 * FloatArrayAccess, ListAccess, MapAccess 24 */ 25 public interface ArrayAccess { 26 /** 27 * Get a value as a float for an index 28 * 29 * @param index position in the collection 30 * @return 31 */ getFloatValue(int index)32 float getFloatValue(int index); 33 34 /** 35 * If the objects have id's return the id 36 * 37 * @param index index of the object 38 * @return id or -1 if no id is available 39 */ getId(int index)40 default int getId(int index) { 41 return 0; 42 } 43 44 /** 45 * Get the backing array of float if available for float arrays 46 * 47 * @return 48 */ 49 @Nullable getFloats()50 float[] getFloats(); 51 52 /** 53 * Get the length of the collection 54 * 55 * @return length of the collection 56 */ getLength()57 int getLength(); 58 59 /** 60 * Get the value as an integer if available 61 * 62 * @param index the position in the collection 63 * @return it value as and integer 64 */ getIntValue(int index)65 default int getIntValue(int index) { 66 return (int) getFloatValue(index); 67 } 68 } 69