Java Code Examples for java.util.AbstractCollection

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Cilia_1, under directory /framework/core/src/main/java/fr/liglab/adele/cilia/util/.

Source file: WeakValueHashMap.java

  24 
vote

/** 
 * Returns a <code>Collection</code> view of the values contained in this map.<p>
 * @return a <code>Collection</code> view of the values containedin this map.
 */
public Collection values(){
  if (values == null) {
    values=new AbstractCollection(){
      public Iterator iterator(){
        return new Iterator(){
          private Iterator i=entrySet().iterator();
          public boolean hasNext(){
            return i.hasNext();
          }
          public Object next(){
            return ((Entry)i.next()).getValue();
          }
          public void remove(){
            i.remove();
          }
        }
;
      }
      public int size(){
        return WeakValueHashMap.this.size();
      }
      public boolean contains(      Object v){
        return WeakValueHashMap.this.containsValue(v);
      }
    }
;
  }
  return values;
}
 

Example 2

From project morphia, under directory /morphia/src/main/java/relocated/morphia/org/apache/commons/collections/.

Source file: ReferenceMap.java

  20 
vote

/** 
 * Returns a collection view of this map's values.
 * @return a collection view of this map's values.
 */
public Collection values(){
  if (values != null)   return values;
  values=new AbstractCollection(){
    public int size(){
      return size;
    }
    public void clear(){
      ReferenceMap.this.clear();
    }
    public Iterator iterator(){
      return new ValueIterator();
    }
  }
;
  return values;
}
 

Example 3

From project teatrove, under directory /trove/src/main/java/org/teatrove/trove/classfile/.

Source file: InstructionList.java

  20 
vote

/** 
 * Returns an immutable collection of all the instructions in this InstructionList.
 */
public Collection getInstructions(){
  return new AbstractCollection(){
    public Iterator iterator(){
      return new Iterator(){
        private Instruction mNext=mFirst;
        public boolean hasNext(){
          return mNext != null;
        }
        public Object next(){
          if (mNext == null) {
            throw new NoSuchElementException();
          }
          Instruction current=mNext;
          mNext=mNext.mNext;
          return current;
        }
        public void remove(){
          throw new UnsupportedOperationException();
        }
      }
;
    }
    public int size(){
      int count=0;
      for (Instruction i=mFirst; i != null; i=i.mNext) {
        count++;
      }
      return count;
    }
  }
;
}
 

Example 4

From project accounted4, under directory /accounted4/accounted4-money/src/main/java/com/accounted4/money/.

Source file: Split.java

  19 
vote

/** 
 * The partitions forming the split.
 * @param divideType Determinant of remainder distribution among partitions
 * @return The partitions with the original money "fairly" distributed.
 */
public Collection<Money> getPartitions(final DivideType divideType){
  return new AbstractCollection<Money>(){
    @Override public Iterator<Money> iterator(){
      return new SplitIterator(divideType);
    }
    @Override public int size(){
      return partitions;
    }
  }
;
}
 

Example 5

From project activemq-apollo, under directory /apollo-util/src/main/scala/org/apache/activemq/apollo/util/.

Source file: TreeMap.java

  19 
vote

public Collection<V> values(){
  return new AbstractCollection<V>(){
    @Override public Iterator<V> iterator(){
      return new ValueIterator();
    }
    @Override public int size(){
      return count;
    }
  }
;
}
 

Example 6

From project android_external_guava, under directory /src/com/google/common/collect/.

Source file: LinkedListMultimap.java

  19 
vote

/** 
 * {@inheritDoc}<p>The iterator generated by the returned collection traverses the values in the order they were added to the multimap.
 */
public Collection<V> values(){
  Collection<V> result=valuesCollection;
  if (result == null) {
    valuesCollection=result=new AbstractCollection<V>(){
      @Override public int size(){
        return keyCount.size();
      }
      @Override public Iterator<V> iterator(){
        final Iterator<Node<K,V>> nodes=new NodeIterator();
        return new Iterator<V>(){
          public boolean hasNext(){
            return nodes.hasNext();
          }
          public V next(){
            return nodes.next().value;
          }
          public void remove(){
            nodes.remove();
          }
        }
;
      }
    }
;
  }
  return result;
}
 

Example 7

From project clj-ds, under directory /src/main/java/com/trifork/clj_ds/.

Source file: APersistentMap.java

  19 
vote

public Collection<V> values(){
  return new AbstractCollection<V>(){
    public Iterator<V> iterator(){
      final Iterator<Map.Entry<K,V>> mi=APersistentMap.this.iterator();
      return new Iterator<V>(){
        public boolean hasNext(){
          return mi.hasNext();
        }
        public V next(){
          return mi.next().getValue();
        }
        public void remove(){
          throw new UnsupportedOperationException();
        }
      }
;
    }
    public int size(){
      return count();
    }
  }
;
}
 

Example 8

From project fastjson, under directory /src/main/java/com/alibaba/fastjson/parser/deserializer/.

Source file: CollectionDeserializer.java

  19 
vote

@SuppressWarnings({"unchecked","rawtypes"}) public <T>T deserialze(DefaultJSONParser parser,Type type,Object fieldName){
  if (parser.getLexer().token() == JSONToken.NULL) {
    parser.getLexer().nextToken(JSONToken.COMMA);
    return null;
  }
  Class<?> rawClass=getRawClass(type);
  Collection list;
  if (rawClass == AbstractCollection.class) {
    list=new ArrayList();
  }
 else   if (rawClass.isAssignableFrom(HashSet.class)) {
    list=new HashSet();
  }
 else   if (rawClass.isAssignableFrom(LinkedHashSet.class)) {
    list=new LinkedHashSet();
  }
 else   if (rawClass.isAssignableFrom(ArrayList.class)) {
    list=new ArrayList();
  }
 else {
    try {
      list=(Collection)rawClass.newInstance();
    }
 catch (    Exception e) {
      throw new JSONException("create instane error, class " + rawClass.getName());
    }
  }
  Type itemType;
  if (type instanceof ParameterizedType) {
    itemType=((ParameterizedType)type).getActualTypeArguments()[0];
  }
 else {
    itemType=Object.class;
  }
  parser.parseArray(itemType,list,fieldName);
  return (T)list;
}
 

Example 9

From project gs-core, under directory /src/org/graphstream/graph/implementations/.

Source file: AbstractGraph.java

  19 
vote

/** 
 * This implementation uses  {@link #getNodeIterator()} and{@link #getNodeCount()}
 * @see org.graphstream.graph.Graph#getNodeSet()
 */
public <T extends Node>Collection<T> getNodeSet(){
  return new AbstractCollection<T>(){
    public Iterator<T> iterator(){
      return getNodeIterator();
    }
    public int size(){
      return getNodeCount();
    }
  }
;
}
 

Example 10

From project guice-jit-providers, under directory /core/test/com/google/inject/.

Source file: TypeLiteralTypeResolutionTest.java

  19 
vote

public void testGetSupertype(){
  TypeLiteral<AbstractList<String>> listOfString=new TypeLiteral<AbstractList<String>>(){
  }
;
  assertEquals(Types.newParameterizedType(AbstractCollection.class,String.class),listOfString.getSupertype(AbstractCollection.class).getType());
  TypeLiteral arrayListOfE=TypeLiteral.get(newParameterizedType(ArrayList.class,ArrayList.class.getTypeParameters()));
  assertEquals(newParameterizedType(AbstractCollection.class,ArrayList.class.getTypeParameters()),arrayListOfE.getSupertype(AbstractCollection.class).getType());
}
 

Example 11

From project indextank-engine, under directory /cojen-2.2.1-sources/org/cojen/classfile/.

Source file: InstructionList.java

  19 
vote

/** 
 * Returns an immutable collection of all the instructions in this InstructionList.
 */
public Collection<Instruction> getInstructions(){
  return new AbstractCollection<Instruction>(){
    public Iterator<Instruction> iterator(){
      return new Iterator<Instruction>(){
        private Instruction mNext=mFirst;
        public boolean hasNext(){
          return mNext != null;
        }
        public Instruction next(){
          if (mNext == null) {
            throw new NoSuchElementException();
          }
          Instruction current=mNext;
          mNext=mNext.mNext;
          return current;
        }
        public void remove(){
          throw new UnsupportedOperationException();
        }
      }
;
    }
    public int size(){
      int count=0;
      for (Instruction i=mFirst; i != null; i=i.mNext) {
        count++;
      }
      return count;
    }
  }
;
}
 

Example 12

From project iPhoroidUI, under directory /src/org/klab/iphoroid/util/.

Source file: Cache.java

  19 
vote

public synchronized Collection<V> values(){
  deleteExpiredEntries();
  return Collections.unmodifiableCollection(new AbstractCollection<V>(){
    Collection<CacheObject<V>> values=map.values();
    public Iterator<V> iterator(){
      return new Iterator<V>(){
        Iterator<CacheObject<V>> it=values.iterator();
        public boolean hasNext(){
          return it.hasNext();
        }
        public V next(){
          return it.next().object;
        }
        public void remove(){
          it.remove();
        }
      }
;
    }
    public int size(){
      return values.size();
    }
  }
);
}
 

Example 13

From project lyo.core, under directory /OSLC4JJenaProvider/src/org/eclipse/lyo/oslc4j/provider/jena/.

Source file: OslcRdfXmlCollectionProvider.java

  19 
vote

@Override public Collection<Object> readFrom(final Class<Collection<Object>> type,final Type genericType,final Annotation[] annotations,final MediaType mediaType,final MultivaluedMap<String,String> map,final InputStream inputStream) throws IOException, WebApplicationException {
  if (genericType instanceof ParameterizedType) {
    final ParameterizedType parameterizedType=(ParameterizedType)genericType;
    final Type[] actualTypeArguments=parameterizedType.getActualTypeArguments();
    if (actualTypeArguments.length == 1) {
      final Type actualTypeArgument=actualTypeArguments[0];
      if (actualTypeArgument instanceof Class) {
        final Object[] objects=readFrom((Class<?>)actualTypeArgument,mediaType,map,inputStream);
        final Collection<Object> collection;
        if ((Collection.class.equals(type)) || (List.class.equals(type)) || (Deque.class.equals(type))|| (Queue.class.equals(type))|| (AbstractCollection.class.equals(type))|| (AbstractList.class.equals(type))|| (AbstractSequentialList.class.equals(type))) {
          collection=new LinkedList<Object>();
        }
 else         if ((Set.class.equals(type)) || (AbstractSet.class.equals(type))) {
          collection=new HashSet<Object>();
        }
 else         if ((SortedSet.class.equals(type)) || (NavigableSet.class.equals(type))) {
          collection=new TreeSet<Object>();
        }
 else {
          try {
            @SuppressWarnings("cast") final Collection<Object> tempCollection=((Collection<Object>)type.newInstance());
            collection=tempCollection;
          }
 catch (          final Exception exception) {
            throw new WebApplicationException(exception,buildBadRequestResponse(exception,mediaType,map));
          }
        }
        collection.addAll(Arrays.asList(objects));
        return collection;
      }
    }
  }
  return null;
}
 

Example 14

From project MobiPerf, under directory /android/src/com/mobiperf/speedometer/.

Source file: MeasurementScheduleConsoleActivity.java

  19 
vote

private void updateConsole(){
  Logger.i("updateConsole() called");
  scheduler=parent.getScheduler();
  if (scheduler != null) {
    AbstractCollection<MeasurementTask> tasks=scheduler.getTaskQueue();
    consoleContent.clear();
    taskMap.clear();
    for (    MeasurementTask task : tasks) {
      String taskStr=task.toString();
      consoleContent.add(taskStr);
      taskMap.put(taskStr,task.getDescription().key);
    }
  }
  updateLastCheckinTime();
}
 

Example 15

From project montysolr, under directory /src/java/invenio/montysolr/jni/.

Source file: PythonMessage.java

  19 
vote

public String toString(){
  Set<Entry<String,Object>> s=this.entrySet();
  StringBuilder out=new StringBuilder();
  for (  Entry<String,Object> e : s) {
    out.append(e.getKey());
    out.append("=");
    Object v=e.getValue();
    if (v instanceof AbstractCollection) {
      if (((AbstractCollection)v).size() > 10) {
        out.append("@" + v.getClass());
      }
 else {
        out.append(v);
      }
    }
 else {
      out.append(v);
    }
    out.append(",");
  }
  return out.toString();
}
 

Example 16

From project morphology, under directory /src/main/java/lv/semti/morphology/attributes/.

Source file: TagSet.java

  19 
vote

public AbstractCollection<String> allowedAttributes(String language){
  LinkedList<String> result=new LinkedList<String>();
  for (  Attribute attribute : attributes) {
    if (language.equals("LV"))     result.add(attribute.attributeLV);
    if (language.equals("EN"))     result.add(attribute.attributeEN);
  }
  return result;
}
 

Example 17

From project pandoroid, under directory /src/com/aregner/pandora/.

Source file: XmlRpc.java

  19 
vote

public static String value(AbstractCollection<?> list){
  StringBuilder result=new StringBuilder("<value><array><data>");
  Iterator<?> listIter=list.iterator();
  while (listIter.hasNext()) {
    result.append(valueGuess(listIter.next()));
  }
  return result.append("</data></array></value>").toString();
}
 

Example 18

From project platform_external_guava, under directory /src/com/google/common/collect/.

Source file: LinkedListMultimap.java

  19 
vote

/** 
 * {@inheritDoc}<p>The iterator generated by the returned collection traverses the values in the order they were added to the multimap.
 */
public Collection<V> values(){
  Collection<V> result=valuesCollection;
  if (result == null) {
    valuesCollection=result=new AbstractCollection<V>(){
      @Override public int size(){
        return keyCount.size();
      }
      @Override public Iterator<V> iterator(){
        final Iterator<Node<K,V>> nodes=new NodeIterator();
        return new Iterator<V>(){
          public boolean hasNext(){
            return nodes.hasNext();
          }
          public V next(){
            return nodes.next().value;
          }
          public void remove(){
            nodes.remove();
          }
        }
;
      }
    }
;
  }
  return result;
}
 

Example 19

From project rozkladpkp-android, under directory /src/org/tyszecki/rozkladpkp/widgets/.

Source file: AttributesButton.java

  19 
vote

public static String join(AbstractCollection<String> s,String delimiter){
  if (s.isEmpty())   return "";
  Iterator<String> iter=s.iterator();
  StringBuffer buffer=new StringBuffer(iter.next());
  while (iter.hasNext())   buffer.append(delimiter).append(iter.next());
  return buffer.toString();
}
 

Example 20

From project salem, under directory /src/haven/.

Source file: Resource.java

  19 
vote

public <L extends Layer>Collection<L> layers(final Class<L> cl,boolean th){
  if (loading && th)   throw (new Loading(this));
  checkerr();
  return (new AbstractCollection<L>(){
    @Override @SuppressWarnings("unused") public int size(){
      int s=0;
      for (      L l : this)       s++;
      return (s);
    }
    @Override public Iterator<L> iterator(){
      return (new Iterator<L>(){
        Iterator<Layer> i=layers.iterator();
        L c=n();
        private L n(){
          while (i.hasNext()) {
            Layer l=i.next();
            if (cl.isInstance(l))             return (cl.cast(l));
          }
          return (null);
        }
        @Override public boolean hasNext(){
          return (c != null);
        }
        @Override public L next(){
          L ret=c;
          if (ret == null)           throw (new NoSuchElementException());
          c=n();
          return (ret);
        }
        @Override public void remove(){
          throw (new UnsupportedOperationException());
        }
      }
);
    }
  }
);
}
 

Example 21

From project sisu-guice, under directory /core/test/com/google/inject/.

Source file: TypeLiteralTypeResolutionTest.java

  19 
vote

public void testGetSupertype(){
  TypeLiteral<AbstractList<String>> listOfString=new TypeLiteral<AbstractList<String>>(){
  }
;
  assertEquals(Types.newParameterizedType(AbstractCollection.class,String.class),listOfString.getSupertype(AbstractCollection.class).getType());
  TypeLiteral arrayListOfE=TypeLiteral.get(newParameterizedType(ArrayList.class,ArrayList.class.getTypeParameters()));
  assertEquals(newParameterizedType(AbstractCollection.class,ArrayList.class.getTypeParameters()),arrayListOfE.getSupertype(AbstractCollection.class).getType());
}
 

Example 22

From project Speedometer, under directory /android/src/com/google/wireless/speed/speedometer/.

Source file: MeasurementScheduleConsoleActivity.java

  19 
vote

private void updateConsole(){
  Logger.i("updateConsole() called");
  scheduler=parent.getScheduler();
  if (scheduler != null) {
    AbstractCollection<MeasurementTask> tasks=scheduler.getTaskQueue();
    consoleContent.clear();
    taskMap.clear();
    for (    MeasurementTask task : tasks) {
      String taskStr=task.toString();
      consoleContent.add(taskStr);
      taskMap.put(taskStr,task.getDescription().key);
    }
  }
  updateLastCheckinTime();
}
 

Example 23

From project vraptor, under directory /vraptor-core/src/test/java/br/com/caelum/vraptor/ioc/.

Source file: AbstractComponentRegistryTest.java

  19 
vote

@Test public void shouldRegisterComponentUsingAllPossibleSupertypes(){
  abstractRegistry.deepRegister(ArrayListSubclass.class);
  verify(registry).register(ArrayListSubclass.class,ArrayListSubclass.class);
  verify(registry).register(ArrayList.class,ArrayListSubclass.class);
  verify(registry).register(List.class,ArrayListSubclass.class);
  verify(registry).register(Collection.class,ArrayListSubclass.class);
  verify(registry).register(Iterable.class,ArrayListSubclass.class);
  verify(registry).register(Cloneable.class,ArrayListSubclass.class);
  verify(registry).register(Serializable.class,ArrayListSubclass.class);
  verify(registry).register(RandomAccess.class,ArrayListSubclass.class);
  verify(registry).register(AbstractList.class,ArrayListSubclass.class);
  verify(registry).register(AbstractCollection.class,ArrayListSubclass.class);
}