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

com.github.chen0040.glm.utils.CollectionUtils Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
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);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy