All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.evosuite.utils.ArrayUtil Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
package org.evosuite.utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
public abstract class ArrayUtil {
	/**
	 * 

asSet

* * @param values a T object. * @param a T object. * @return a {@link java.util.Set} object. */ @SuppressWarnings("unchecked") public static Set asSet(T... values) { return new HashSet(Arrays.asList(values)); } /** Constant DEFAULT_JOIN_SEPARATOR="IterUtil.DEFAULT_JOIN_SEPARATOR" */ public static final String DEFAULT_JOIN_SEPARATOR = IterUtil.DEFAULT_JOIN_SEPARATOR; /** *

box

* * @param array an array of int. * @return an array of {@link java.lang.Integer} objects. */ public static Integer[] box(int[] array) { Integer[] result = new Integer[array.length]; /* Can't use System.arraycopy() -- it doesn't do boxing */ for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } /** *

box

* * @param array an array of long. * @return an array of {@link java.lang.Long} objects. */ public static Long[] box(long[] array) { Long[] result = new Long[array.length]; /* Can't use System.arraycopy() -- it doesn't do boxing */ for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } /** *

box

* * @param array an array of byte. * @return an array of {@link java.lang.Byte} objects. */ public static Byte[] box(byte[] array) { Byte[] result = new Byte[array.length]; /* Can't use System.arraycopy() -- it doesn't do boxing */ for (int i = 0; i < array.length; i++) { result[i] = array[i]; } return result; } /** *

join

* * @param array an array of {@link java.lang.Object} objects. * @param separator a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static String join(Object[] array, String separator) { return StringUtils.join(array, separator); } /** *

join

* * @param array an array of {@link java.lang.Object} objects. * @return a {@link java.lang.String} object. */ public static String join(Object[] array) { return StringUtils.join(array, DEFAULT_JOIN_SEPARATOR); } /** *

join

* * @param array an array of long. * @param separator a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static String join(long[] array, String separator) { return join(box(array), separator); } /** *

join

* * @param array an array of long. * @return a {@link java.lang.String} object. */ public static String join(long[] array) { return join(array, DEFAULT_JOIN_SEPARATOR); } /** *

join

* * @param array an array of byte. * @param separator a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static String join(byte[] array, String separator) { return join(box(array), separator); } /** *

join

* * @param array an array of byte. * @return a {@link java.lang.String} object. */ public static String join(byte[] array) { return join(array, DEFAULT_JOIN_SEPARATOR); } /** *

contains

* * @param array * @param object * @return true if array contains an instance equals to object */ public static boolean contains(Object[] array, Object object) { for (Object obj : array) { if(obj == object) return true; else if (obj != null && obj.equals(object)) return true; else if (object instanceof String && obj.toString().equals(object)) // TODO: Does this check really make sense? return true; } return false; } /** * * @param arr * @param obj * @return */ public static Object[] append(Object[] arr, Object obj) { final int N = arr.length; arr = Arrays.copyOf(arr, N + 1); arr[N] = obj; return arr; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy