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 com.android.cts.verifier.audio.peripheralprofile; 18 19 public class ListsHelper { isMatch(int[] a, int[] b)20 static public boolean isMatch(int[] a, int[] b) { 21 if (a.length != b.length) { 22 return false; 23 } 24 25 int len = a.length; 26 for (int index = 0; index < len; index++) { 27 if (a[index] != b[index]) { 28 return false; 29 } 30 } 31 32 return true; 33 } 34 hasValue(int[] a, int value)35 static private boolean hasValue(int[] a, int value) { 36 // one can't use indexOf on an int[], so just scan. 37 for (int aVal : a) { 38 if (aVal == value) { 39 return true; 40 } 41 } 42 43 return false; 44 } 45 46 /** 47 * return true if the values in "a" are a subset of those in "b". 48 * Assume values are represented no more than once in each array. 49 */ isSubset(int[] a, int[] b)50 static public boolean isSubset(int[] a, int[] b) { 51 if (a.length > b.length) { 52 return false; 53 } 54 55 for (int aVal : a) { 56 if (!hasValue(b, aVal)) { 57 return false; 58 } 59 } 60 61 return true; 62 } 63 textFormatHex(int[] list)64 static public String textFormatHex(int[] list) { 65 StringBuilder sb = new StringBuilder(); 66 sb.append("["); 67 for (int index = 0; index < list.length; index++) { 68 sb.append("0x" + Integer.toHexString(list[index])); 69 if (index < list.length-1) { 70 sb.append(", "); 71 } 72 } 73 sb.append("]"); 74 return sb.toString(); 75 } 76 textFormatDecimal(int[] list)77 static public String textFormatDecimal(int[] list) { 78 StringBuilder sb = new StringBuilder(); 79 sb.append("["); 80 for (int index = 0; index < list.length; index++) { 81 sb.append("0x" + list[index]); 82 if (index < list.length-1) { 83 sb.append(", "); 84 } 85 } 86 sb.append("]"); 87 return sb.toString(); 88 } 89 } 90