1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.inputmethod.latin.utils; 18 19 import android.util.SparseArray; 20 21 import java.util.ArrayDeque; 22 import java.util.ArrayList; 23 import java.util.Collection; 24 import java.util.Collections; 25 import java.util.HashMap; 26 import java.util.HashSet; 27 import java.util.LinkedList; 28 import java.util.Map; 29 import java.util.TreeMap; 30 import java.util.TreeSet; 31 import java.util.WeakHashMap; 32 import java.util.concurrent.ConcurrentHashMap; 33 import java.util.concurrent.CopyOnWriteArrayList; 34 35 public final class CollectionUtils { 36 private CollectionUtils() { 37 // This utility class is not publicly instantiable. 38 } 39 40 public static <K,V> HashMap<K,V> newHashMap() { 41 return new HashMap<K,V>(); 42 } 43 44 public static <K, V> WeakHashMap<K, V> newWeakHashMap() { 45 return new WeakHashMap<K, V>(); 46 } 47 48 public static <K,V> TreeMap<K,V> newTreeMap() { 49 return new TreeMap<K,V>(); 50 } 51 52 public static <K, V> Map<K,V> newSynchronizedTreeMap() { 53 final TreeMap<K,V> treeMap = newTreeMap(); 54 return Collections.synchronizedMap(treeMap); 55 } 56 57 public static <K,V> ConcurrentHashMap<K,V> newConcurrentHashMap() { 58 return new ConcurrentHashMap<K,V>(); 59 } 60 61 public static <E> HashSet<E> newHashSet() { 62 return new HashSet<E>(); 63 } 64 65 public static <E> TreeSet<E> newTreeSet() { 66 return new TreeSet<E>(); 67 } 68 69 public static <E> ArrayList<E> newArrayList() { 70 return new ArrayList<E>(); 71 } 72 73 public static <E> ArrayList<E> newArrayList(final int initialCapacity) { 74 return new ArrayList<E>(initialCapacity); 75 } 76 77 public static <E> ArrayList<E> newArrayList(final Collection<E> collection) { 78 return new ArrayList<E>(collection); 79 } 80 81 public static <E> LinkedList<E> newLinkedList() { 82 return new LinkedList<E>(); 83 } 84 85 public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() { 86 return new CopyOnWriteArrayList<E>(); 87 } 88 89 public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList( 90 final Collection<E> collection) { 91 return new CopyOnWriteArrayList<E>(collection); 92 } 93 94 public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) { 95 return new CopyOnWriteArrayList<E>(array); 96 } 97 98 public static <E> ArrayDeque<E> newArrayDeque() { 99 return new ArrayDeque<E>(); 100 } 101 102 public static <E> SparseArray<E> newSparseArray() { 103 return new SparseArray<E>(); 104 } 105 } 106