org.evosuite.utils.ListUtil 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 org.evosuite.*;
import java.util.*;
import java.util.Properties;
public abstract class ListUtil {
/**
* tail
*
* @param list a {@link java.util.List} object.
* @param a T object.
* @return a {@link java.util.List} object.
*/
public static List tail(List list) {
return list.subList(1, list.size());
}
/**
* anyEquals
*
* @param list a {@link java.util.List} object.
* @param obj a T object.
* @param a T object.
* @return a boolean.
*/
public static boolean anyEquals(List list, T obj) {
for (T item : list) {
if (item.equals(obj)) {
return true;
}
}
return false;
}
/**
* shuffledList
*
* @param list a {@link java.util.List} object.
* @param a T object.
* @return a {@link java.util.List} object.
*/
public static List shuffledList(List list) {
ArrayList result = new ArrayList(list);
Collections.shuffle(result);
return result;
}
/**
* shuffledList
*
* @param list a {@link java.util.List} object.
* @param rnd a {@link java.util.Random} object.
* @param a T object.
* @return a {@link java.util.List} object.
*/
public static List shuffledList(List list, Random rnd) {
ArrayList result = new ArrayList(list);
Collections.shuffle(result, rnd);
return result;
}
private static int getIndex(List> population) {
double r = Randomness.nextDouble();
double d = org.evosuite.Properties.RANK_BIAS
- Math.sqrt((org.evosuite.Properties.RANK_BIAS * org.evosuite.Properties.RANK_BIAS)
- (4.0 * (org.evosuite.Properties.RANK_BIAS - 1.0) * r));
int length = population.size();
d = d / 2.0 / (org.evosuite.Properties.RANK_BIAS - 1.0);
//this is not needed because population is sorted based on Maximization
//if(maximize)
// d = 1.0 - d; // to do that if we want to have Maximisation
int index = (int) (length * d);
return index;
}
public static T selectRankBiased(List list) {
int index = getIndex(list);
return list.get(index);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy