/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.loganalysis.util; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; /** * Utility methods for arrays */ // TODO: Use libTF once this is copied over. public class ArrayUtil { private ArrayUtil() { } /** * Build an array from the provided contents. * *
* The resulting array will be the concatenation of arrays input arrays, in their * original order. *
* * @param arrays the arrays to concatenate * @return the newly constructed array */ public static String[] buildArray(String[]... arrays) { int length = 0; for (String[] array : arrays) { length += array.length; } String[] newArray = new String[length]; int offset = 0; for (String[] array : arrays) { System.arraycopy(array, 0, newArray, offset, array.length); offset += array.length; } return newArray; } /** * Convert a varargs list/array to an {@link List}. This is useful for building instances of * {@link List} by hand. Note that this differs from {@link java.util.Arrays#asList} in that * the returned array is mutable. * * @param inputAry an array, or a varargs list * @return a {@link List} instance with the identical contents */ @SafeVarargs public static