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

org.testng.collections.Lists Maven / Gradle / Ivy

package org.testng.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public final class Lists {

  private Lists() {}

  public static  List newArrayList() {
    return new ArrayList<>();
  }

  public static  List newLinkedList() {
    return new LinkedList<>();
  }

  public static  List newLinkedList(Collection c) {
    return new LinkedList<>(c);
  }

  public static  List newArrayList(Collection c) {
    return new ArrayList<>(c);
  }

  @SafeVarargs
  public static  List newArrayList(K... elements) {
    List result = new ArrayList<>();
    Collections.addAll(result, elements);
    return result;
  }

  public static  List newArrayList(int size) {
    return new ArrayList<>(size);
  }

  public static  List intersection(List list1, List list2) {
    return list1.stream().filter(list2::contains).collect(Collectors.toList());
  }

  public static  List merge(Collection l1, Collection l2) {
    List result = newArrayList(l1);
    result.addAll(l2);
    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy