com.github.chen0040.glm.utils.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-glm Show documentation
Show all versions of java-glm Show documentation
Generalized linear models implemented in Java
package com.github.chen0040.glm.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* Created by xschen on 1/5/2017.
*/
public class CollectionUtils {
public static List clone(List that, Function transformer) {
List result = new ArrayList<>();
for(int i=0; i < that.size(); ++i){
result.add(transformer.apply(that.get(i)));
}
return result;
}
public static List toList(T[] that, Function transformer) {
List result = new ArrayList<>();
for(int i=0; i < that.length; ++i){
result.add(transformer.apply(that[i]));
}
return result;
}
public static List toList(double[] that) {
List result = new ArrayList<>();
for(int i=0; i < that.length; ++i){
result.add(that[i]);
}
return result;
}
public static void exchange(List a, int i, int j) {
T temp = a.get(i);
a.set(i, a.get(j));
a.set(j, temp);
}
}