Java 类java.util.AbstractCollection 实例源码

项目:hadoop-oss    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:alfresco-core    文件:HierarchicalSqlSessionFactoryBeanTest.java   
/**
 * Check context startup and shutdown
 */
public void testContextStartup() throws Exception
{
    getConfiguration(TreeSet.class);
    getConfiguration(HashSet.class);
    getConfiguration(ArrayList.class);
    getConfiguration(AbstractCollection.class);
    try
    {
        getConfiguration(Collection.class);
        fail("Failed to detect incompatible class hierarchy");
    }
    catch (Throwable e)
    {
        // Expected
    }
}
项目:primeval-reflex    文件:ImmutableObjectMap.java   
@Override
public Collection<Object> values() {
    return new AbstractCollection<Object>() {

        @Override
        public Iterator<Object> iterator() {
            return ImmutableObjectMap.this.keySet().stream().map(key -> ImmutableObjectMap.this.get(key))
                    .iterator();
        }

        @Override
        public int size() {
            return fieldMap.size();
        }

    };
}
项目:unitimes    文件:GeneralHtml.java   
protected String htmlForObject(Object obj) {
    StringBuffer sb = new StringBuffer();
    if (obj != null){
        if (GeneralHtml.class.isInstance(obj)) {
            sb.append(((GeneralHtml) obj).toHtml());                
        } else if (AbstractCollection.class.isInstance(obj)) {
            Iterator colIt = ((AbstractCollection) obj).iterator();
            while(colIt.hasNext()) {
                sb.append(this.htmlForObject(colIt.next()));
            }           
        } else {
            sb.append(obj.toString());
        }
    }
    return(sb.toString());
}
项目:boohee_v5.6    文件:b.java   
private static Collection<Object> a(Class<?> cls, Type type) {
    if (cls == AbstractCollection.class) {
        return new ArrayList();
    }
    if (cls.isAssignableFrom(HashSet.class)) {
        return new HashSet();
    }
    if (cls.isAssignableFrom(LinkedHashSet.class)) {
        return new LinkedHashSet();
    }
    if (cls.isAssignableFrom(TreeSet.class)) {
        return new TreeSet();
    }
    if (cls.isAssignableFrom(ArrayList.class)) {
        return new ArrayList();
    }
    if (cls.isAssignableFrom(EnumSet.class)) {
        return EnumSet.noneOf(type instanceof ParameterizedType ? ((ParameterizedType) type).getActualTypeArguments()[0] : Object.class);
    }
    try {
        return (Collection) cls.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException("create instane error, class " + cls.getName());
    }
}
项目:hadoop    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:ProtocolSupportPocketStuff    文件:ExpiringMap.java   
@Override
public Collection<V> values() {
  return new AbstractCollection<V>() {
    @Override
    public void clear() {
      ExpiringMap.this.clear();
    }

    @Override
    public boolean contains(Object value) {
      return containsValue(value);
    }

    @Override
    public Iterator<V> iterator() {
      return (entries instanceof EntryLinkedHashMap) ? ((EntryLinkedHashMap<K, V>) entries).new ValueIterator()
          : ((EntryTreeHashMap<K, V>) entries).new ValueIterator();
    }

    @Override
    public int size() {
      return ExpiringMap.this.size();
    }
  };
}
项目:aliyun-oss-hadoop-fs    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:big-c    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:jpaul    文件:BijMap.java   
/** Returns a collection view of the values from this
       <code>BijMap</code>.  The view is fully functional (i.e.,
       allows mutation) and connected to this bijective map (i.e.,
       changes in one of them are reflected in the other one). */
   public Collection<B> values() {
return new AbstractCollection<B>() {
    public int size() { return map.size(); }
    public Iterator<B> iterator() {
    return 
        DSUtil.<Map.Entry<A,B>,B>mapIterator
        (BijMap.this.entrySet().iterator(),
         new Function<Map.Entry<A,B>,B>() {
        public B f(Map.Entry<A,B> entry) {
            return entry.getValue();
        }
        });
    }
    public boolean remove(Object b) {
    return BijMap.this.rev().remove(b) != null;
    }
    public void clear() {
    BijMap.this.clear();
    }
};
   }
项目:jpaul    文件:NoCompTreeMap.java   
/** Returns an unmodifiable collection view of the values from this map. */
   public final Collection<V> values() {
return new AbstractCollection<V>() {
    public Iterator<V> iterator() {
    final Iterator<Map.Entry<K,V>> ite = entryIterator();
    return new Iterator<V>() {
        public boolean hasNext() { return ite.hasNext(); }
        public void    remove()  { ite.remove(); }
        public V       next()    { return ite.next().getValue(); }
    };
    }
    public int size() {
    return size;
    }
};
   }
项目:cassandra-kmean    文件:AtomicBTreeColumns.java   
private <V> Collection<V> collection(final boolean forwards, final Function<Cell, V> f)
{
    final Holder ref = this.ref;
    return new AbstractCollection<V>()
    {
        public Iterator<V> iterator()
        {
            return Iterators.transform(BTree.<Cell>slice(ref.tree, forwards), f);
        }

        public int size()
        {
            return BTree.slice(ref.tree, true).count();
        }
    };
}
项目:show-java    文件:ImmutableClassDef.java   
@Nonnull
@Override
public Collection<? extends ImmutableField> getFields() {
    return new AbstractCollection<ImmutableField>() {
        @Nonnull
        @Override
        public Iterator<ImmutableField> iterator() {
            return Iterators.concat(staticFields.iterator(), instanceFields.iterator());
        }

        @Override
        public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
项目:show-java    文件:ImmutableClassDef.java   
@Nonnull
@Override
public Collection<? extends ImmutableMethod> getMethods() {
    return new AbstractCollection<ImmutableMethod>() {
        @Nonnull
        @Override
        public Iterator<ImmutableMethod> iterator() {
            return Iterators.concat(directMethods.iterator(), virtualMethods.iterator());
        }

        @Override
        public int size() {
            return directMethods.size() + virtualMethods.size();
        }
    };
}
项目:show-java    文件:ClassPool.java   
@Nullable
@Override
public Collection<? extends EncodedValue> getStaticInitializers(
        @Nonnull PoolClassDef classDef) {
    final SortedSet<Field> sortedStaticFields = classDef.getStaticFields();

    final int lastIndex = CollectionUtils.lastIndexOf(sortedStaticFields, HAS_INITIALIZER);
    if (lastIndex > -1) {
        return new AbstractCollection<EncodedValue>() {
            @Nonnull
            @Override
            public Iterator<EncodedValue> iterator() {
                return FluentIterable.from(sortedStaticFields)
                        .limit(lastIndex + 1)
                        .transform(GET_INITIAL_VALUE).iterator();
            }

            @Override
            public int size() {
                return lastIndex + 1;
            }
        };
    }
    return null;
}
项目:show-java    文件:PoolClassDef.java   
@Nonnull
@Override
public Collection<Field> getFields() {
    return new AbstractCollection<Field>() {
        @Nonnull
        @Override
        public Iterator<Field> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override
        public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
项目:show-java    文件:PoolClassDef.java   
@Nonnull
@Override
public Collection<PoolMethod> getMethods() {
    return new AbstractCollection<PoolMethod>() {
        @Nonnull
        @Override
        public Iterator<PoolMethod> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(directMethods.iterator(), virtualMethods.iterator()),
                    Ordering.natural());
        }

        @Override
        public int size() {
            return directMethods.size() + virtualMethods.size();
        }
    };
}
项目:show-java    文件:BuilderClassDef.java   
@Nonnull
@Override
public Collection<BuilderField> getFields() {
    return new AbstractCollection<BuilderField>() {
        @Nonnull
        @Override
        public Iterator<BuilderField> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override
        public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
项目:show-java    文件:BuilderClassDef.java   
@Nonnull
@Override
public Collection<BuilderMethod> getMethods() {
    return new AbstractCollection<BuilderMethod>() {
        @Nonnull
        @Override
        public Iterator<BuilderMethod> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(directMethods.iterator(), virtualMethods.iterator()),
                    Ordering.natural());
        }

        @Override
        public int size() {
            return directMethods.size() + virtualMethods.size();
        }
    };
}
项目:show-java    文件:BuilderClassPool.java   
@Nullable
@Override
public Collection<? extends BuilderEncodedValue> getStaticInitializers(@Nonnull BuilderClassDef classDef) {
    final SortedSet<BuilderField> sortedStaticFields = classDef.getStaticFields();

    final int lastIndex = CollectionUtils.lastIndexOf(sortedStaticFields, HAS_INITIALIZER);
    if (lastIndex > -1) {
        return new AbstractCollection<BuilderEncodedValue>() {
            @Nonnull
            @Override
            public Iterator<BuilderEncodedValue> iterator() {
                return FluentIterable.from(sortedStaticFields)
                        .limit(lastIndex + 1)
                        .transform(GET_INITIAL_VALUE).iterator();
            }

            @Override
            public int size() {
                return lastIndex + 1;
            }
        };
    }
    return null;
}
项目:j2objc    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#add(java.lang.Object)
 */
public void test_addLjava_lang_Object() {
    AbstractCollection<Object> ac = new AbstractCollection<Object>() {

        @Override
        public Iterator<Object> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    try {
        ac.add(null);
    } catch (UnsupportedOperationException e) {
    }
}
项目:j2objc    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#addAll(java.util.Collection)
 */
public void test_addAllLjava_util_Collection() {
    final Collection<String> fixtures = Arrays.asList("0", "1", "2");
    AbstractCollection<String> ac = new AbstractCollection<String>() {

        @Override
        public boolean add(String object) {
            assertTrue(fixtures.contains(object));
            return true;
        }

        @Override
        public Iterator<String> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    assertTrue(ac.addAll(fixtures));
}
项目:j2objc    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#containsAll(java.util.Collection)
 */
public void test_containsAllLjava_util_Collection() {
    final Collection<String> fixtures = Arrays.asList("0", "1", "2");
    AbstractCollection<String> ac = new AbstractCollection<String>() {

        @Override
        public boolean contains(Object object) {
            assertTrue(fixtures.contains(object));
            return true;
        }

        @Override
        public Iterator<String> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    assertTrue(ac.containsAll(fixtures));
}
项目:j2objc    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#isEmpty()
 */
public void test_isEmpty() {
    final boolean[] sizeCalled = new boolean[1];
    AbstractCollection<Object> ac = new AbstractCollection<Object>(){
        @Override
        public Iterator<Object> iterator() {
            fail("iterator should not get called");
            return null;
        }
        @Override
        public int size() {
            sizeCalled[0] = true;
            return 0;
        }
    };
    assertTrue(ac.isEmpty());
    assertTrue(sizeCalled[0]);
}
项目:VarJ    文件:LinkedListMultimap.java   
/**
 * {@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;
}
项目:VarJ    文件:LinkedListMultimap.java   
/**
 * {@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;
}
项目:VarJ    文件:BijMap.java   
/** Returns a collection view of the values from this
       <code>BijMap</code>.  The view is fully functional (i.e.,
       allows mutation) and connected to this bijective map (i.e.,
       changes in one of them are reflected in the other one). */
   public Collection<B> values() {
return new AbstractCollection<B>() {
    public int size() { return map.size(); }
    public Iterator<B> iterator() {
    return 
        DSUtil.<Map.Entry<A,B>,B>mapIterator
        (BijMap.this.entrySet().iterator(),
         new Function<Map.Entry<A,B>,B>() {
        public B f(Map.Entry<A,B> entry) {
            return entry.getValue();
        }
        });
    }
    public boolean remove(Object b) {
    return BijMap.this.rev().remove(b) != null;
    }
    public void clear() {
    BijMap.this.clear();
    }
};
   }
项目:VarJ    文件:NoCompTreeMap.java   
/** Returns an unmodifiable collection view of the values from this map. */
   public final Collection<V> values() {
return new AbstractCollection<V>() {
    public Iterator<V> iterator() {
    final Iterator<Map.Entry<K,V>> ite = entryIterator();
    return new Iterator<V>() {
        public boolean hasNext() { return ite.hasNext(); }
        public void    remove()  { ite.remove(); }
        public V       next()    { return ite.next().getValue(); }
    };
    }
    public int size() {
    return size;
    }
};
   }
项目:guava-libraries    文件:ConstraintsTest.java   
/**
 * Returns a "nefarious" collection, which permits only one call to
 * iterator(). This verifies that the constrained collection uses a defensive
 * copy instead of potentially checking the elements in one snapshot and
 * adding the elements from another.
 *
 * @param element the element to be contained in the collection
 */
static <E> Collection<E> onceIterableCollection(final E element) {
  return new AbstractCollection<E>() {
    boolean iteratorCalled;
    @Override public int size() {
      /*
       * We could make the collection empty, but that seems more likely to
       * trigger special cases (so maybe we should test both empty and
       * nonempty...).
       */
      return 1;
    }
    @Override public Iterator<E> iterator() {
      assertFalse("Expected only one call to iterator()", iteratorCalled);
      iteratorCalled = true;
      return Collections.singleton(element).iterator();
    }
  };
}
项目:elk-reasoner    文件:Operations.java   
/**
 * Splits the input {@link Collection} on batches with at most given number
 * of elements.
 * 
 * @param elements
 *            the {@link Collection} to be split
 * @param batchSize
 *            the maximal number of elements in batches
 * @return a {@link Collection} of batches containing elements from the
 *         input collection
 */
public static <T> Collection<ArrayList<T>> split(
        final Collection<? extends T> elements, final int batchSize) {
    return new AbstractCollection<ArrayList<T>>() {

        @Override
        public Iterator<ArrayList<T>> iterator() {
            return split((Iterable<? extends T>) elements, batchSize)
                    .iterator();
        }

        @Override
        public int size() {
            // rounding up
            return (elements.size() + batchSize - 1) / batchSize;
        }
    };
}
项目:tempto    文件:InlineDataSource.java   
public static HiveDataSource createSameRowDataSource(String tableName, String revisionMarker, int splitCount, int rowsInEachSplit, String rowData)
{
    return new InlineDataSource(tableName, revisionMarker)
    {
        @Override
        public Collection<RepeatableContentProducer> data()
        {
            return new AbstractCollection<RepeatableContentProducer>()
            {
                @Override
                public Iterator<RepeatableContentProducer> iterator()
                {
                    ByteSource singleRowSource = concat(wrap(rowData.getBytes()), wrap("\n".getBytes()));
                    ByteSource singleSplitSource = concat(limit(cycle(singleRowSource), rowsInEachSplit));
                    return limit(cycle(singleSplitSource::openStream), splitCount);
                }

                @Override
                public int size()
                {
                    return splitCount;
                }
            };
        }
    };
}
项目:cp-elements    文件:CacheToMapAdapter.java   
@Override
public Collection<VALUE> values() {

  return new AbstractCollection<VALUE>() {

    @Override
    public Iterator<VALUE> iterator() {
      return getCache().iterator();
    }

    @Override
    public int size() {
      return getCache().size();
    }
  };
}
项目:unitime    文件:GeneralHtml.java   
protected String htmlForObject(Object obj) {
    StringBuffer sb = new StringBuffer();
    if (obj != null){
        if (GeneralHtml.class.isInstance(obj)) {
            sb.append(((GeneralHtml) obj).toHtml());                
        } else if (AbstractCollection.class.isInstance(obj)) {
            Iterator colIt = ((AbstractCollection) obj).iterator();
            while(colIt.hasNext()) {
                sb.append(this.htmlForObject(colIt.next()));
            }           
        } else {
            sb.append(obj.toString());
        }
    }
    return(sb.toString());
}
项目:hops    文件:TestBloomFilters.java   
private void checkOnAbsentFalsePositive(int hashId, int numInsertions,
    final RetouchedBloomFilter filter, Digits digits, short removeSchema) {
  AbstractCollection<Key> falsePositives = FALSE_POSITIVE_UNDER_1000
      .get(hashId);

  if (falsePositives == null)
    Assert.fail(String.format("false positives for hash %d not founded",
        hashId));

  filter.addFalsePositive(falsePositives);

  for (int i = digits.getStart(); i < numInsertions; i += 2) {
    filter.add(new Key(Integer.toString(i).getBytes()));
  }

  for (Key key : falsePositives) {
    filter.selectiveClearing(key, removeSchema);
  }

  for (int i = 1 - digits.getStart(); i < numInsertions; i += 2) {
    assertFalse(" testRetouchedBloomFilterAddFalsePositive error " + i,
        filter.membershipTest(new Key(Integer.toString(i).getBytes())));
  }
}
项目:In-the-Box-Fork    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#add(java.lang.Object)
 */
public void test_addLjava_lang_Object() {
    AbstractCollection<Object> ac = new AbstractCollection<Object>() {

        @Override
        public Iterator<Object> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    try {
        ac.add(null);
    } catch (UnsupportedOperationException e) {
    }
}
项目:In-the-Box-Fork    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#addAll(java.util.Collection)
 */
public void test_addAllLjava_util_Collection() {
    final Collection<String> fixtures = Arrays.asList("0", "1", "2");
    AbstractCollection<String> ac = new AbstractCollection<String>() {

        @Override
        public boolean add(String object) {
            assertTrue(fixtures.contains(object));
            return true;
        }

        @Override
        public Iterator<String> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    assertTrue(ac.addAll(fixtures));
}
项目:In-the-Box-Fork    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#containsAll(java.util.Collection)
 */
public void test_containsAllLjava_util_Collection() {
    final Collection<String> fixtures = Arrays.asList("0", "1", "2");
    AbstractCollection<String> ac = new AbstractCollection<String>() {

        @Override
        public boolean contains(Object object) {
            assertTrue(fixtures.contains(object));
            return true;
        }

        @Override
        public Iterator<String> iterator() {
            fail("iterator should not get called");
            return null;
        }

        @Override
        public int size() {
            fail("size should not get called");
            return 0;
        }

    };
    assertTrue(ac.containsAll(fixtures));
}
项目:In-the-Box-Fork    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#isEmpty()
 */
public void test_isEmpty() {
    final boolean[] sizeCalled = new boolean[1];
    AbstractCollection<Object> ac = new AbstractCollection<Object>(){
        @Override
        public Iterator<Object> iterator() {
            fail("iterator should not get called");
            return null;
        }
        @Override
        public int size() {
            sizeCalled[0] = true;
            return 0;
        }
    };
    assertTrue(ac.isEmpty());
    assertTrue(sizeCalled[0]);
}
项目:In-the-Box-Fork    文件:AbstractCollectionTest.java   
/**
 * @tests java.util.AbstractCollection#toString()
 */
public void test_toString() {
    // see HARMONY-1522
    // collection that returns null iterator(this is against the spec.)
    AbstractCollection<?> c = new AbstractCollection<Object>() {
        @Override
        public int size() {
            // return non-zero value to pass 'isEmpty' check
            return 1;
        }

        @Override
        public Iterator<Object> iterator() {
            // this violates the spec.
            return null;
        }
    };

    try {
        // AbstractCollection.toString() doesn't verify
        // whether iterator() returns null value or not
        c.toString();
        fail("No expected NullPointerException");
    } catch (NullPointerException e) {
    }
}