コード例 #1
0
ファイル: Maps.java プロジェクト: automenta/corenlp
 /**
  * Adds the value to the collection given by map.get(key). A new collection is created using the
  * supplied CollectionFactory.
  */
 public static <K, V, C extends Collection<V>> void putIntoValueCollection(
     Map<K, C> map, K key, V value, CollectionFactory<V> cf) {
   C c = map.get(key);
   if (c == null) {
     c = ErasureUtils.<C>uncheckedCast(cf.newCollection());
     map.put(key, c);
   }
   c.add(value);
 }
コード例 #2
0
 /**
  * Reduces memory consumption to the minimum for representing the values currently stored stored
  * in this object.
  */
 public void compact() {
   if (keys.length > size) {
     Class[] newKeys = new Class[size];
     Object[] newValues = new Object[size];
     System.arraycopy(keys, 0, newKeys, 0, size);
     System.arraycopy(values, 0, newValues, 0, size);
     keys = ErasureUtils.uncheckedCast(newKeys);
     values = newValues;
   }
 }
コード例 #3
0
 public void setCapacity(int newSize) {
   if (size > newSize) {
     throw new RuntimeException("You cannot set capacity to smaller than the current size.");
   }
   Class[] newKeys = new Class[newSize];
   Object[] newValues = new Object[newSize];
   System.arraycopy(keys, 0, newKeys, 0, size);
   System.arraycopy(values, 0, newValues, 0, size);
   keys = ErasureUtils.uncheckedCast(newKeys);
   values = newValues;
 }
コード例 #4
0
 /**
  * Initializes this ArrayCoreMap, pre-allocating arrays to hold up to capacity key,value pairs.
  * This array will grow if necessary.
  *
  * @param capacity Initial capacity of object in key,value pairs
  */
 public ArrayCoreMap(int capacity) {
   keys = ErasureUtils.uncheckedCast(new Class[capacity]);
   values = new Object[capacity];
   // size starts at 0
 }