Home | History | Annotate | Download | only in latin
      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;
     18 
     19 import android.util.SparseArray;
     20 
     21 import java.util.ArrayList;
     22 import java.util.Collection;
     23 import java.util.Collections;
     24 import java.util.HashMap;
     25 import java.util.HashSet;
     26 import java.util.LinkedList;
     27 import java.util.Map;
     28 import java.util.TreeMap;
     29 import java.util.TreeSet;
     30 import java.util.concurrent.ConcurrentHashMap;
     31 import java.util.concurrent.CopyOnWriteArrayList;
     32 
     33 public final class CollectionUtils {
     34     private CollectionUtils() {
     35         // This utility class is not publicly instantiable.
     36     }
     37 
     38     public static <K,V> HashMap<K,V> newHashMap() {
     39         return new HashMap<K,V>();
     40     }
     41 
     42     public static <K,V> TreeMap<K,V> newTreeMap() {
     43         return new TreeMap<K,V>();
     44     }
     45 
     46     public static <K, V> Map<K,V> newSynchronizedTreeMap() {
     47         final TreeMap<K,V> treeMap = newTreeMap();
     48         return Collections.synchronizedMap(treeMap);
     49     }
     50 
     51     public static <K,V> ConcurrentHashMap<K,V> newConcurrentHashMap() {
     52         return new ConcurrentHashMap<K,V>();
     53     }
     54 
     55     public static <E> HashSet<E> newHashSet() {
     56         return new HashSet<E>();
     57     }
     58 
     59     public static <E> TreeSet<E> newTreeSet() {
     60         return new TreeSet<E>();
     61     }
     62 
     63     public static <E> ArrayList<E> newArrayList() {
     64         return new ArrayList<E>();
     65     }
     66 
     67     public static <E> ArrayList<E> newArrayList(final int initialCapacity) {
     68         return new ArrayList<E>(initialCapacity);
     69     }
     70 
     71     public static <E> ArrayList<E> newArrayList(final Collection<E> collection) {
     72         return new ArrayList<E>(collection);
     73     }
     74 
     75     public static <E> LinkedList<E> newLinkedList() {
     76         return new LinkedList<E>();
     77     }
     78 
     79     public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() {
     80         return new CopyOnWriteArrayList<E>();
     81     }
     82 
     83     public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(
     84             final Collection<E> collection) {
     85         return new CopyOnWriteArrayList<E>(collection);
     86     }
     87 
     88     public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(final E[] array) {
     89         return new CopyOnWriteArrayList<E>(array);
     90     }
     91 
     92     public static <E> SparseArray<E> newSparseArray() {
     93         return new SparseArray<E>();
     94     }
     95 }
     96