@Override public Set<Map.Entry<NameAndAccess, TMember>> entrySet() { return new AbstractSet<Map.Entry<NameAndAccess, TMember>>() { @Override public Iterator<Map.Entry<NameAndAccess, TMember>> iterator() { return Iterators.unmodifiableIterator( new TransformedIterator2<TMember, Map.Entry<NameAndAccess, TMember>>(members.iterator()) { @Override protected Map.Entry<NameAndAccess, TMember> transform(TMember input) { final NameAndAccess[] nameAndAccess = NameAndAccess.of(input); if (nameAndAccess.length > 1) { setAdditionalElement(new AbstractMap.SimpleImmutableEntry<>(nameAndAccess[1], input)); } return new AbstractMap.SimpleImmutableEntry<>(nameAndAccess[0], input); } }); } @Override public int size() { return members.size(); } }; }
@Override public Set<Entry<Range<K>, V>> entrySet() { return new AbstractSet<Entry<Range<K>, V>>() { @SuppressWarnings("unchecked") // it's safe to upcast iterators @Override public Iterator<Entry<Range<K>, V>> iterator() { return (Iterator) entriesByLowerBound.values().iterator(); } @Override public int size() { return entriesByLowerBound.size(); } }; }
@Override public Set<Map.Entry<K, V>> entrySet() { return new AbstractSet<Map.Entry<K, V>>() { @Override public Iterator<java.util.Map.Entry<K, V>> iterator() { return new EntryIterator<>(root); } @Override public boolean contains(Object o) { if (o == null || !(o instanceof Map.Entry)) { return false; } Map.Entry<?, ?> entry = (java.util.Map.Entry<?, ?>) o; return entry.getValue().equals(CopyOnWriteHashMap.this.get(entry.getKey())); } @Override public int size() { return CopyOnWriteHashMap.this.size(); } }; }
/** * {@inheritDoc} */ public final Set<WriteFuture> broadcast(Object message) { // Convert to Set. We do not return a List here because only the // direct caller of MessageBroadcaster knows the order of write // operations. final List<WriteFuture> futures = IoUtil.broadcast(message, getManagedSessions().values()); return new AbstractSet<WriteFuture>() { @Override public Iterator<WriteFuture> iterator() { return futures.iterator(); } @Override public int size() { return futures.size(); } }; }
@Override public void commandRun() { if (zkServer == null) { pw.println(ZK_NOT_SERVING); } else { // clone should be faster than iteration // ie give up the cnxns lock faster AbstractSet<ServerCnxn> cnxns; synchronized (factory.cnxns) { cnxns = new HashSet<ServerCnxn>(factory.cnxns); } for (ServerCnxn c : cnxns) { c.dumpConnectionInfo(pw, false); pw.println(); } pw.println(); } }
@Override public Set<K> keySet() { return new AbstractSet() { @Override public Iterator iterator() { return iterableKeys.iterator(); } @Override public int size() { return iterableKeys.size(); } }; }
/** * Returns a set backed by the given array (i.e. a set that uses object * equality for comparisons). The array must contain no duplicates, its * elements must be sorted in the increasing order of hashcodes (as by * {@link #hashSort(Object[])}), and its contents must not be changed while * it is in use by the returned set. * * @requires all i, j: [0..array.length) | i < j => array[i].hashCode() <= * array[j].hashCode * @return an unmodifiable Set view of the given array */ public static final <T> Set<T> asHashSet(final T[] array) { return new AbstractSet<T>() { public boolean contains(Object o) { return hashBinarySearch(array, o) >= 0; } public Iterator<T> iterator() { return iterate(array); } public int size() { return array.length; } }; }
@Override public Set<Entry<String, Object>> entrySet() { return new AbstractSet<Entry<String,Object>>() { @Override public boolean add(Entry<String, Object> e) { String key = e.getKey(); Object value = e.getValue(); original.put(key, unwrapIncoming(value)); return true; } @Override public int size() { return original.size(); } @Override public Iterator<Entry<String, Object>> iterator() { return ConvertedMap.this.iterator(); } }; }
@Override public Set<Map.Entry<Boolean, T>> entrySet() { return new AbstractSet<Map.Entry<Boolean, T>>() { @Override public Iterator<Map.Entry<Boolean, T>> iterator() { Map.Entry<Boolean, T> falseEntry = new SimpleImmutableEntry<>(false, forFalse); Map.Entry<Boolean, T> trueEntry = new SimpleImmutableEntry<>(true, forTrue); return Arrays.asList(falseEntry, trueEntry).iterator(); } @Override public int size() { return 2; } }; }
public Set<Map.Entry<K, V>> entrySet() { return new AbstractSet<Map.Entry<K, V>>() { public int size() { return map.size(); } public Iterator<Map.Entry<K,V>> iterator() { final Iterator<Map.Entry<K,V>> source = map.entrySet().iterator(); return new Iterator<Map.Entry<K,V>>() { public boolean hasNext() { return source.hasNext(); } public Map.Entry<K,V> next() { return source.next(); } public void remove() { source.remove(); } }; } public boolean add(Map.Entry<K,V> e) { return map.entrySet().add(e); } }; }
@Override @SuppressWarnings ("unchecked") public Set<java.util.Map.Entry<K, V>> entrySet() { if (entries == null) { entries = new AbstractSet<Entry<K, V>>() { @Override public void clear() { throw new UnsupportedOperationException(); } @Override public Iterator<Entry<K, V>> iterator() { return list.iterator(); } @Override public int size() { return list.size(); } }; } return (Set<java.util.Map.Entry<K, V>>) entries; }
@Override public Set<Map.Entry<Boolean, T>> entrySet() { return new AbstractSet<>() { @Override public Iterator<Map.Entry<Boolean, T>> iterator() { Map.Entry<Boolean, T> falseEntry = new SimpleImmutableEntry<>(false, forFalse); Map.Entry<Boolean, T> trueEntry = new SimpleImmutableEntry<>(true, forTrue); return List.of(falseEntry, trueEntry).iterator(); } @Override public int size() { return 2; } }; }
@Override public Set<Map.Entry<K,V>> entrySet() { return new AbstractSet<Map.Entry<K,V>>() { @Override public int size() { return map.size(); } @Override public Iterator<Map.Entry<K,V>> iterator() { final Iterator<Map.Entry<K,V>> source = map.entrySet().iterator(); return new Iterator<Map.Entry<K,V>>() { public boolean hasNext() { return source.hasNext(); } public Map.Entry<K,V> next() { return source.next(); } public void remove() { source.remove(); } }; } @Override public boolean add(Map.Entry<K,V> e) { return map.entrySet().add(e); } }; }
@Override synchronized public Set<K> keySet() { return new AbstractSet<K>() { @Override public int size() { return OidEntityDtoMap.this.size(); } @Override public boolean contains(Object o) { return OidEntityDtoMap.this.containsKey(o); } @Override public Iterator<K> iterator() { return OidEntityDtoMap.this.keys_.iterator(); } }; }
@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { // clone should be faster than iteration // ie give up the cnxns lock faster AbstractSet<ServerCnxn> cnxns; synchronized (factory.cnxns) { cnxns = new HashSet<ServerCnxn>(factory.cnxns); } for (ServerCnxn c : cnxns) { c.dumpConnectionInfo(pw, false); pw.println(); } pw.println(); } }
/** * An implementation of {@link BaseGraph#edges()} defined in terms of {@link #nodes()} and {@link * #successors(Object)}. */ @Override public Set<EndpointPair<N>> edges() { return new AbstractSet<EndpointPair<N>>() { @Override public UnmodifiableIterator<EndpointPair<N>> iterator() { return EndpointPairIterator.of(AbstractBaseGraph.this); } @Override public int size() { return Ints.saturatedCast(edgeCount()); } @Override public boolean contains(@Nullable Object obj) { if (!(obj instanceof EndpointPair)) { return false; } EndpointPair<?> endpointPair = (EndpointPair<?>) obj; return isDirected() == endpointPair.isOrdered() && nodes().contains(endpointPair.nodeU()) && successors(endpointPair.nodeU()).contains(endpointPair.nodeV()); } }; }
@Nonnull @Override public Set<String> getInterfaces() { return new AbstractSet<String>() { @Nonnull @Override public Iterator<String> iterator() { return Iterators.transform(Iterators.forArray(cls.getInterfaces()), new Function<Class, String>() { @Nullable @Override public String apply(@Nullable Class input) { if (input == null) { return null; } return ReflectionUtils.javaToDexName(input.getName()); } }); } @Override public int size() { return cls.getInterfaces().length; } }; }
@Nonnull @Override public Set<? extends Field> getFields() { return new AbstractSet<Field>() { @Nonnull @Override public Iterator<Field> iterator() { return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()), new Function<java.lang.reflect.Field, Field>() { @Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) { return new ReflectionField(input); } }); } @Override public int size() { return cls.getDeclaredFields().length; } }; }
@Override public Set<K> keySet() { final MVMap<K, V> map = this; final Page root = this.root; return new AbstractSet<K>() { @Override public Iterator<K> iterator() { return new Cursor<K, V>(map, root, null); } @Override public int size() { return MVMap.this.size(); } @Override public boolean contains(Object o) { return MVMap.this.containsKey(o); } }; }
@Override public void commandRun() { if (zkServer == null) { pw.println(ZK_NOT_SERVING); } else { // clone should be faster than iteration // ie give up the cnxns lock faster AbstractSet<ServerCnxn> cnxns; synchronized (factory.cnxns) { cnxns = new HashSet<ServerCnxn>(factory.cnxns); } for (ServerCnxn c : cnxns) { c.dumpConnectionInfo(pw, false); } pw.println(); } }
@Test public void classImplementsExtends() throws Exception { ClassName taco = ClassName.get(tacosPackage, "Taco"); ClassName food = ClassName.get("com.squareup.tacos", "Food"); TypeSpec typeSpec = TypeSpec.classBuilder("Taco") .addModifiers(Modifier.ABSTRACT) .superclass(ParameterizedTypeName.get(ClassName.get(AbstractSet.class), food)) .addSuperinterface(Serializable.class) .addSuperinterface(ParameterizedTypeName.get(ClassName.get(Comparable.class), taco)) .build(); assertThat(toString(typeSpec)).isEqualTo("" + "package com.squareup.tacos;\n" + "\n" + "import java.io.Serializable;\n" + "import java.lang.Comparable;\n" + "import java.util.AbstractSet;\n" + "\n" + "abstract class Taco extends AbstractSet<Food> " + "implements Serializable, Comparable<Taco> {\n" + "}\n"); }
@Override public Set<Map.Entry<Boolean, T>> entrySet() { return new AbstractSet<Map.Entry<Boolean, T>>() { @Override public Iterator<Map.Entry<Boolean, T>> iterator() { Map.Entry<Boolean, T> falseEntry = Tuple.of(false, forFalse); Map.Entry<Boolean, T> trueEntry = Tuple.of(true, forTrue); return Arrays.asList(falseEntry, trueEntry).iterator(); } @Override public int size() { return 2; } }; }
@Override public Set<Entry<K,V>> entrySet() { if(entrySet==null) entrySet = new AbstractSet<Entry<K,V>>() { // REQUIRED METHODS OF AbstractSet // @Override public int size() { return size; } @Override public Iterator<Entry<K,V>> iterator() { return new SequenceIterator<Entry<K,V>>(intMap.values().iterator()); } // OVERRIDDEN METHODS OF AbstractSet // @Override public boolean contains(final Object e) { if(!(e instanceof Entry)) return false; V value = get(((Entry<?,?>)e).getKey()); return value!=null && value.equals(((Entry<?,?>)e).getValue()); } }; return entrySet; }
@Override public Set<Entry<Integer,V>> entrySet() { if(entrySet==null) entrySet = new AbstractSet<Entry<Integer,V>>() { // REQUIRED METHODS OF AbstractSet // @Override public int size() { // same as Map return IntTreePMap.this.size(); } @Override public Iterator<Entry<Integer,V>> iterator() { return root.iterator(); } // OVERRIDDEN METHODS OF AbstractSet // @Override public boolean contains(final Object e) { if(!(e instanceof Entry)) return false; V value = get(((Entry<?,?>)e).getKey()); return value!=null && value.equals(((Entry<?,?>)e).getValue()); } }; return entrySet; }
@Override public Set<Entry<String, V>> entrySet() { // TODO: optimize return new AbstractSet<Entry<String, V>>() { @Override public Iterator<Entry<String, V>> iterator() { return new Itr(); } @Override public int size() { return SimpleTrieMap.this.size; } }; }