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

autofixture.implementationdetails.CollectionFactory Maven / Gradle / Ivy

There is a newer version: 2.1.10
Show newest version
package autofixture.implementationdetails;

import com.google.common.reflect.TypeToken;

import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.*;

/**
 * Created by astral on 07.02.15.
 */
public class CollectionFactory {
  public static  Map createMapFrom(final T[] keys, final V[] values) {
    final Map map = new HashMap<>();
    for (int i = 0; i < keys.length; ++i) {
      map.put(keys[i], values[i]);
    }
    return map;
  }

  public static  Deque createDequeFrom(final Collection many) {
    return new ArrayDeque<>(many);
  }

  public static  SortedSet createSortedSetFrom(final Collection many) {
    return new TreeSet<>(many);
  }

  public static  Set createSetFrom(final Collection many) {
    return new HashSet<>(many);
  }

  public static  SortedMap createSortedMapFrom(final Map map) {
    return new TreeMap<>(map);
  }

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

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

  public static Stack createEmptyStack() {
    return new Stack<>();
  }

  public static ArrayDeque createEmptyArrayDeque() {
    return new ArrayDeque<>();
  }

  public static ArrayBlockingQueue createEmptyArrayBlockingQueue(final int repeatCount) {
    return new ArrayBlockingQueue<>(repeatCount);
  }

  public static LinkedHashSet createEmptyLinkedHashSet() {
    return new LinkedHashSet<>();
  }

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

  public static ConcurrentLinkedQueue createEmptyConcurrentLinkedQueue() {
    return new ConcurrentLinkedQueue<>();
  }

  public static ConcurrentSkipListSet createEmptyConcurrentSkipListSet() {
    return new ConcurrentSkipListSet<>();
  }

  public static CopyOnWriteArrayList createEmptyCopyOnWriteArrayList() {
    return new CopyOnWriteArrayList<>();
  }

  public static CopyOnWriteArraySet createEmptyCopyOnWriteArraySet() {
    return new CopyOnWriteArraySet<>();
  }

  public static PriorityBlockingQueue createEmptyPriorityBlockingQueue() {
    return new PriorityBlockingQueue<>();
  }

  public static PriorityQueue createEmptyPriorityQueue() {
    return new PriorityQueue<>();
  }

  public static TreeSet createTreeSet() {
    return new TreeSet<>();
  }

  public static Set createEmptySet() {
    return new HashSet<>();
  }

  public static  PriorityQueue createQueueFrom(final Collection many) {
    return new PriorityQueue<>(many);
  }

  public static  T[] createArray(TypeToken type, int length) {
    return (T[]) Array.newInstance(
      type.getRawType(), length);
  }

  public static Map createEmptyHashMap() {
    return new HashMap<>();
  }

  public static Map createEmptySortedMap() {
    return new TreeMap<>();
  }

  public static Map createEmptyTreeMap() {
    return new TreeMap<>();
  }

  public static Map createEmptyNavigableMap() {
    return new TreeMap<>();
  }

  public static Map createEmptyConcurrentHashMap() {
    return new ConcurrentHashMap<>();
  }

  public static Map createEmptyConcurrentSkipListMap() {
    return new ConcurrentSkipListMap<>();
  }

  public static Map createEmptyHashtable() {
    return new Hashtable<>();
  }

  public static Map createEmptyLinkedHashMap() {
    return new LinkedHashMap<>();
  }

  public static Map createEmptyWeakHashMap() {
    return new WeakHashMap<>();
  }

  public static Map createEmptyIdentityHashMap() {
    return new IdentityHashMap<>();
  }

  public static Map createEmptyEnumMap(Class keyType) {
    return new EnumMap(keyType);
  }
}