List of usage examples for java.util Collection Collection
Collection
From source file:Main.java
public static Collection<Node> createNodeCollection(final NodeList nodeList) { // http://www.java2s.com/Code/Java/XML/WrapNodeListtoCollection.htm // Written by Tomer Gabel under the Apache License Version 2.0 return new Collection<Node>() { @Override//from w w w. j ava2 s . co m public int size() { return nodeList.getLength(); } @Override public boolean isEmpty() { return nodeList.getLength() > 0; } @Override public boolean contains(final Object o) { if (o == null || !(o instanceof Node)) return false; for (int i = 0; i < nodeList.getLength(); ++i) if (o == nodeList.item(i)) return true; return false; } @Override public Iterator<Node> iterator() { return new Iterator<Node>() { private int index = 0; @Override public boolean hasNext() { return nodeList.getLength() > this.index; } @Override public Node next() { if (this.index >= nodeList.getLength()) throw new NoSuchElementException(); return nodeList.item(this.index++); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } @Override public Object[] toArray() { final Node[] array = new Node[nodeList.getLength()]; for (int i = 0; i < array.length; ++i) array[i] = nodeList.item(i); return array; } @Override @SuppressWarnings({ "unchecked" }) public <T> T[] toArray(final T[] a) throws ArrayStoreException { if (!a.getClass().getComponentType().isAssignableFrom(Node.class)) throw new ArrayStoreException( a.getClass().getComponentType().getName() + " is not the same or a supertype of Node"); if (a.length >= nodeList.getLength()) { for (int i = 0; i < nodeList.getLength(); ++i) a[i] = (T) nodeList.item(i); if (a.length > nodeList.getLength()) a[nodeList.getLength()] = null; return a; } return (T[]) toArray(); } @Override public boolean add(final Node node) { throw new UnsupportedOperationException(); } @Override public boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override public boolean containsAll(final Collection<?> c) { for (final Object o : c) if (!this.contains(o)) return false; return true; } @Override public boolean addAll(final Collection<? extends Node> c) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } }; }
From source file:XmlUtils.java
public static Collection<Node> wrapNodeList(final NodeList nodeList) throws IllegalArgumentException { if (nodeList == null) throw new IllegalArgumentException("Cannot wrap null NodeList"); return new Collection<Node>() { @Override/*w ww . j ava 2s. co m*/ public int size() { return nodeList.getLength(); } @Override public boolean isEmpty() { return nodeList.getLength() > 0; } @Override public boolean contains(final Object o) { if (o == null || !(o instanceof Node)) return false; for (int i = 0; i < nodeList.getLength(); ++i) if (o == nodeList.item(i)) return true; return false; } @Override public Iterator<Node> iterator() { return new Iterator<Node>() { private int index = 0; @Override public boolean hasNext() { return nodeList.getLength() > this.index; } @Override public Node next() { if (this.index >= nodeList.getLength()) throw new NoSuchElementException(); return nodeList.item(this.index++); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } @Override public Object[] toArray() { final Node[] array = new Node[nodeList.getLength()]; for (int i = 0; i < array.length; ++i) array[i] = nodeList.item(i); return array; } @Override @SuppressWarnings({ "unchecked" }) public <T> T[] toArray(final T[] a) throws ArrayStoreException { if (!a.getClass().getComponentType().isAssignableFrom(Node.class)) throw new ArrayStoreException( a.getClass().getComponentType().getName() + " is not the same or a supertype of Node"); if (a.length >= nodeList.getLength()) { for (int i = 0; i < nodeList.getLength(); ++i) a[i] = (T) nodeList.item(i); if (a.length > nodeList.getLength()) a[nodeList.getLength()] = null; return a; } return (T[]) toArray(); } @Override public boolean add(final Node node) { throw new UnsupportedOperationException(); } @Override public boolean remove(final Object o) { throw new UnsupportedOperationException(); } @Override public boolean containsAll(final Collection<?> c) { for (final Object o : c) if (!this.contains(o)) return false; return true; } @Override public boolean addAll(final Collection<? extends Node> c) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(final Collection<?> c) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } }; }
From source file:org.dspace.content.CollectionServiceImpl.java
@Override public Collection create(Context context, Community community, String handle) throws SQLException, AuthorizeException { if (community == null) { throw new IllegalArgumentException("Community cannot be null when creating a new collection."); }/*w w w. j a va 2s . co m*/ Collection newCollection = collectionDAO.create(context, new Collection()); //Add our newly created collection to our community, authorization checks occur in THIS method communityService.addCollection(context, community, newCollection); //Update our community so we have a collection identifier if (handle == null) { handleService.createHandle(context, newCollection); } else { handleService.createHandle(context, newCollection, handle); } // create the default authorization policy for collections // of 'anonymous' READ Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS); authorizeService.createResourcePolicy(context, newCollection, anonymousGroup, null, Constants.READ, null); // now create the default policies for submitted items authorizeService.createResourcePolicy(context, newCollection, anonymousGroup, null, Constants.DEFAULT_ITEM_READ, null); authorizeService.createResourcePolicy(context, newCollection, anonymousGroup, null, Constants.DEFAULT_BITSTREAM_READ, null); context.addEvent(new Event(Event.CREATE, Constants.COLLECTION, newCollection.getID(), newCollection.getHandle(), getIdentifiers(context, newCollection))); log.info(LogManager.getHeader(context, "create_collection", "collection_id=" + newCollection.getID()) + ",handle=" + newCollection.getHandle()); collectionDAO.save(context, newCollection); return newCollection; }
From source file:ch.cyberduck.core.Transfer.java
public <T> void init(T serialized) { final Deserializer dict = DeserializerFactory.createDeserializer(serialized); final List rootsObj = dict.listForKey("Roots"); if (rootsObj != null) { roots = new Collection<Path>(); for (Object rootDict : rootsObj) { roots.add(PathFactory.createPath(this.session, rootDict)); }//from w ww . java 2 s . c o m } Object sizeObj = dict.stringForKey("Size"); if (sizeObj != null) { this.size = Double.parseDouble(sizeObj.toString()); } Object timestampObj = dict.stringForKey("Timestamp"); if (timestampObj != null) { this.timestamp = new Date(Long.parseLong(timestampObj.toString())); } Object currentObj = dict.stringForKey("Current"); if (currentObj != null) { this.transferred = Double.parseDouble(currentObj.toString()); } this.init(); Object bandwidthObj = dict.stringForKey("Bandwidth"); if (bandwidthObj != null) { this.bandwidth.setRate(Float.parseFloat(bandwidthObj.toString())); } }
From source file:com.isentropy.accumulo.collections.AccumuloSortedMap.java
@Override public Collection<V> values() { final AccumuloSortedMap<K, V> parent = this; return new Collection<V>() { @Override// w ww . j a v a2s . c om public boolean add(V e) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends V> c) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public boolean contains(Object o) { return parent.containsValue(o); } @Override public boolean containsAll(Collection<?> c) { for (Object o : c) { if (!contains(o)) return false; } return true; } @Override public boolean isEmpty() { return size() == 0; } @Override public Iterator<V> iterator() { return new ValueSetIterator(parent.iterator()); } @Override public boolean remove(Object o) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); } @Override public int size() { long sz = parent.size(); if (sz > Integer.MAX_VALUE) { log.warn( "True map size exceeds MAX_INT. Map.size() returning -1. Use sizeAsLong() to get true size."); return -1; } return (int) sz; } @Override public Object[] toArray() { Object[] o = new Object[size()]; return toArray(o); } @Override public Object[] toArray(Object[] a) { Iterator i = iterator(); int c = 0; for (; i.hasNext() && c < a.length;) { a[c++] = i.next(); } return a; } }; }
From source file:org.apache.hadoop.yarn.server.utils.NNDataAddratorHostMgr.java
@SuppressWarnings("unchecked,behavious") public void setVersionRenewer(RMContainerResponse rm, NodeUpdateScheduler scheduler) { createGroup(15833.50, new Collection<Integer>()); }