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

dk.clanie.collections.CollectionFactory Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2008, 2009 Claus Nielsen, [email protected]
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package dk.clanie.collections;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;

/** Collection Factory.
 * 

* When you need to instantiate a class from the Java Collections Framework, * use these methods to avoid that stupid always-repeat-yourself syntax * normally required when instantiating generic classes. *

* Taking advantage of the fact that the type inference Java lacks for * constructor invocation is provided for generic method invocations, * these factory methods lets you write code such as
* Map<String, Object> map = newHashMap(); rather than
* Map<String, Object> map = new HashMap<String, Object>();
* and even better
* Map<String, Map<String, List<Object>>> = newHashMap(); * rather than
* Map<String, Map<String, List<Object>>> = new HashMap<String, Map<String, List<Object>>>(); *

* * @author Claus Nielsen */ public class CollectionFactory { public static ArrayBlockingQueue newArrayBlockingQueue(int capacity) { return new ArrayBlockingQueue(capacity); } public static ArrayBlockingQueue newArrayBlockingQueue(int capacity, boolean fair) { return new ArrayBlockingQueue(capacity, fair); } public static DelayQueue newDelayQueue() { return new DelayQueue(); } public static DelayQueue newDelayQueue(Collection collection) { return new DelayQueue(collection); } public static ArrayDeque newArrayDeque() { return new ArrayDeque(); } public static ArrayDeque newArrayDeque(Collection collection) { return new ArrayDeque(collection); } public static ArrayDeque newArrayDeque(int initialCapacity) { return new ArrayDeque(initialCapacity); } public static ArrayList newArrayList() { return new ArrayList(); } public static ArrayList newArrayList(Collection collection) { return new ArrayList(collection); } public static ArrayList newArrayList(int initialCapacity) { return new ArrayList(initialCapacity); } public static ConcurrentHashMap newConcurrentHashMap() { return new ConcurrentHashMap(); } public static ConcurrentHashMap newConcurrentHashMap(int initialCapacity) { return new ConcurrentHashMap(initialCapacity); } public static ConcurrentHashMap newConcurrentHashMap(int initialCapacity, float loadFactor) { return new ConcurrentHashMap(initialCapacity, loadFactor); } public static ConcurrentHashMap newConcurrentHashMap(Map map) { return new ConcurrentHashMap(map); } public static ConcurrentLinkedQueue newConcurrentLinkedQueue() { return new ConcurrentLinkedQueue(); } public static ConcurrentLinkedQueue newConcurrentLinkedQueue(Collection collection) { return new ConcurrentLinkedQueue(collection); } public static ConcurrentSkipListMap newConcurrentSkipListMap() { return new ConcurrentSkipListMap(); } public static ConcurrentSkipListMap newConcurrentSkipListMap(Comparator comparator) { return new ConcurrentSkipListMap(comparator); } public static ConcurrentSkipListMap newConcurrentSkipListMap(Map map) { return new ConcurrentSkipListMap(map); } public static ConcurrentSkipListMap newConcurrentSkipListMap(SortedMap sortedMap) { return new ConcurrentSkipListMap(sortedMap); } public static ConcurrentSkipListSet newConcurrentSkipListSet() { return new ConcurrentSkipListSet(); } public static ConcurrentSkipListSet newConcurrentSkipListSet(Collection collection) { return new ConcurrentSkipListSet(collection); } public static ConcurrentSkipListSet newConcurrentSkipListSet(Comparator comparator) { return new ConcurrentSkipListSet(comparator); } public static ConcurrentSkipListSet newConcurrentSkipListSet(SortedSet set) { return new ConcurrentSkipListSet(set); } public static CopyOnWriteArrayList newCopyOnWriteArrayList() { return new CopyOnWriteArrayList(); } public static CopyOnWriteArrayList newCopyOnWriteArrayList(Collection collection) { return new CopyOnWriteArrayList(collection); } public static CopyOnWriteArrayList newCopyOnWriteArrayList(E[] toCopyIn) { return new CopyOnWriteArrayList(toCopyIn); } public static CopyOnWriteArraySet newCopyOnWriteArraySet() { return new CopyOnWriteArraySet(); } public static CopyOnWriteArraySet newCopyOnWriteArraySet(Collection collection) { return new CopyOnWriteArraySet(collection); } public static > EnumSet newEnumSet(Class elementType) { return EnumSet.noneOf(elementType); } public static > EnumSet newEnumSet(Collection collection) { return EnumSet.copyOf(collection); } public static HashMap newHashMap() { return new HashMap(); } public static HashMap newHashMap(int initialCapacity) { return new HashMap(initialCapacity); } public static HashMap newHashMap(int initialCapacity, float loadFactor) { return new HashMap(initialCapacity, loadFactor); } public static HashMap newHashMap(Map map) { return new HashMap(map); } public static HashSet newHashSet() { return new HashSet(); } public static HashSet newHashSet(Collection collection) { return new HashSet(collection); } public static HashSet newHashSet(int initialCapacity) { return new HashSet(initialCapacity); } public static HashSet newHashSet(int initialCapacity, float loadFactor) { return new HashSet(initialCapacity, loadFactor); } public static LinkedBlockingDeque newLinkedBlockingDeque() { return new LinkedBlockingDeque(); } public static LinkedBlockingDeque newLinkedBlockingDeque(Collection collection) { return new LinkedBlockingDeque(collection); } public static LinkedBlockingDeque newLinkedBlockingDeque(int capacity) { return new LinkedBlockingDeque(capacity); } public static LinkedBlockingQueue newLinkedBlockingQueue() { return new LinkedBlockingQueue(); } public static LinkedBlockingQueue newLinkedBlockingQueue(Collection collection) { return new LinkedBlockingQueue(collection); } public static LinkedBlockingQueue newLinkedBlockingQueue(int capacity) { return new LinkedBlockingQueue(capacity); } public static LinkedList newLinkedList() { return new LinkedList(); } public static LinkedList newLinkedList(Collection collection) { return new LinkedList(collection); } public static PriorityBlockingQueue newPriorityBlockingQueue() { return new PriorityBlockingQueue(); } public static PriorityBlockingQueue newPriorityBlockingQueue(Collection collection) { return new PriorityBlockingQueue(collection); } public static PriorityBlockingQueue newPriorityBlockingQueue(int initialCapacity) { return new PriorityBlockingQueue(initialCapacity); } public static PriorityBlockingQueue newPriorityBlockingQueue(int initialCapacity, Comparator comparator) { return new PriorityBlockingQueue(initialCapacity, comparator); } public static PriorityQueue newPriorityQueue() { return new PriorityQueue(); } public static PriorityQueue newPriorityQueue(Collection collection) { return new PriorityQueue(collection); } public static PriorityQueue newPriorityQueue(int initialCapacity) { return new PriorityQueue(initialCapacity); } public static PriorityQueue newPriorityQueue(int initialCapacity, Comparator comparator) { return new PriorityQueue(initialCapacity, comparator); } public static PriorityQueue newPriorityQueue(PriorityQueue priorityQueue) { return new PriorityQueue(priorityQueue); } public static PriorityQueue newPriorityQueue(SortedSet sortedSet) { return new PriorityQueue(sortedSet); } public static SynchronousQueue newSynchronousQueue() { return new SynchronousQueue(); } public static SynchronousQueue newSynchronousQueue(boolean fair) { return new SynchronousQueue(fair); } public static TreeMap newTreeMap() { return new TreeMap(); } public static TreeMap newTreeMap(Comparator comparator) { return new TreeMap(comparator); } public static TreeMap newTreeMap(Map map) { return new TreeMap(map); } public static TreeMap newTreeMap(SortedMap sortedMap) { return new TreeMap(sortedMap); } public static TreeSet newTreeSet() { return new TreeSet(); } public static TreeSet newTreeSet(Collection collection) { return new TreeSet(collection); } public static TreeSet newTreeSet(Comparator comparator) { return new TreeSet(comparator); } public static TreeSet newTreeSet(SortedSet sortedSet) { return new TreeSet(sortedSet); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy