java.util.AbstractCollection Java Examples

The following examples show how to use java.util.AbstractCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestBloomFilters.java    From big-c with Apache License 2.0 6 votes vote down vote up
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())));
  }
}
 
Example #2
Source File: Chase.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
public Collection<Integer> en(En2 en2, int o) {
	En2Stuff x = stuff.get(en2);
	// BitSet set = x.ens;
	int top = x.top;
	int size = x.size();
	Collection<Integer> ret = new AbstractCollection<>() {
		@Override
		public synchronized Iterator<Integer> iterator() {
			return Iterators.filter(new UpTo(o, o + top), z -> x.find(z - o) == z - o);
		}

		@Override
		public int size() {
			return size;
		}
	};
	int j = 0;
	for (int i : ret) {
		j++;
	}
	if (j != size) {
		Util.anomaly();
	}
	return ret;
}
 
Example #3
Source File: NonBlockingHashMapLong.java    From Jupiter with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link Collection} view of the values contained in this map.
 * The collection is backed by the map, so changes to the map are reflected
 * in the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from this map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 * <p/>
 * <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator that
 * will never throw {@link ConcurrentModificationException}, and guarantees
 * to traverse elements as they existed upon construction of the iterator,
 * and may (but is not guaranteed to) reflect any modifications subsequent
 * to construction.
 */
public Collection<TypeV> values() {
    return new AbstractCollection<TypeV>() {
        public void clear() {
            NonBlockingHashMapLong.this.clear();
        }

        public int size() {
            return NonBlockingHashMapLong.this.size();
        }

        public boolean contains(Object v) {
            return NonBlockingHashMapLong.this.containsValue(v);
        }

        public Iterator<TypeV> iterator() {
            return new SnapshotV();
        }
    };
}
 
Example #4
Source File: CollectionUtils.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "cast" })
public static List<String> getListStrings(final AbstractCollection collection) {
	if ((null != collection) && (collection.size() > 0)) {
		final List<String> result = new ArrayList<String>();
		if (collection.iterator().next() instanceof Object) {
			// treat as an object
			for (final Object o : collection) {
				if (null != o) {
					result.add(o.toString());
				}
			}

		} else {
			// treat as a primitive
			final Iterator it = collection.iterator();
			while (it.hasNext()) {
				result.add(String.valueOf(it.next()));
			}
		}

		return result;
	}

	return null;
}
 
Example #5
Source File: LookupImpl.java    From Quicksql with MIT License 6 votes vote down vote up
public Collection<Enumerable<V>> values() {
  final Collection<List<V>> lists = map.values();
  return new AbstractCollection<Enumerable<V>>() {
    public Iterator<Enumerable<V>> iterator() {
      return new Iterator<Enumerable<V>>() {
        final Iterator<List<V>> iterator = lists.iterator();

        public boolean hasNext() {
          return iterator.hasNext();
        }

        public Enumerable<V> next() {
          return Linq4j.asEnumerable(iterator.next());
        }

        public void remove() {
          iterator.remove();
        }
      };
    }

    public int size() {
      return lists.size();
    }
  };
}
 
Example #6
Source File: AbstractCollectionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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]);
}
 
Example #7
Source File: NonBlockingHashMap.java    From Jupiter with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link Collection} view of the values contained in this map.
 * The collection is backed by the map, so changes to the map are reflected
 * in the collection, and vice-versa.  The collection supports element
 * removal, which removes the corresponding mapping from this map, via the
 * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
 * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
 * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
 * <p/>
 * <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator that
 * will never throw {@link ConcurrentModificationException}, and guarantees
 * to traverse elements as they existed upon construction of the iterator,
 * and may (but is not guaranteed to) reflect any modifications subsequent
 * to construction.
 */
@Override
public Collection<TypeV> values() {
    return new AbstractCollection<TypeV>() {
        @Override
        public void clear() {
            NonBlockingHashMap.this.clear();
        }

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

        @Override
        public boolean contains(Object v) {
            return NonBlockingHashMap.this.containsValue(v);
        }

        @Override
        public Iterator<TypeV> iterator() {
            return new SnapshotV();
        }
    };
}
 
Example #8
Source File: CfnSpecification.java    From aws-cloudformation-template-schema with Apache License 2.0 6 votes vote down vote up
public Set<Difference> findDiff(CfnSpecification toSpec) {
    return resourceTypes.entrySet().stream()
        .filter(entry -> toSpec.resourceTypes.containsKey(entry.getKey()))
        .collect(
            HashSet::new,
            (diffSet, e) -> {
                if (!toSpec.getResourceTypes().get(e.getKey()).equals(e)) {
                    Difference diff = new Difference();
                    diff.setFromType(e.getValue());
                    diff.setFromVersion(resourceSpecificationVersion);
                    diff.setToType(toSpec.getResourceTypes().get(e.getKey()));
                    diff.setToVersion(toSpec.getResourceSpecificationVersion());
                    diffSet.add(diff);
                }
            },
            AbstractCollection::addAll);
}
 
Example #9
Source File: HiveMap.java    From transport with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Collection<StdData> values() {
  return new AbstractCollection<StdData>() {
    @Override
    public Iterator<StdData> iterator() {
      return new Iterator<StdData>() {
        Iterator mapValueIterator = _mapObjectInspector.getMap(_object).values().iterator();

        @Override
        public boolean hasNext() {
          return mapValueIterator.hasNext();
        }

        @Override
        public StdData next() {
          return HiveWrapper.createStdData(mapValueIterator.next(), _valueObjectInspector, _stdFactory);
        }
      };
    }

    @Override
    public int size() {
      return HiveMap.this.size();
    }
  };
}
 
Example #10
Source File: LocalDataStoreTest.java    From ground-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemovePendingMutation() {
  localDataStore.insertOrUpdateUser(TEST_USER).blockingAwait();
  localDataStore.insertOrUpdateProject(TEST_PROJECT).blockingAwait();
  localDataStore.applyAndEnqueue(TEST_FEATURE_MUTATION).blockingAwait();

  localDataStore
      .removePendingMutations(ImmutableList.of(TEST_FEATURE_MUTATION))
      .test()
      .assertComplete();

  localDataStore
      .getPendingMutations("feature id")
      .test()
      .assertValue(AbstractCollection::isEmpty);
}
 
Example #11
Source File: AbstractCollectionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #12
Source File: LinqyTest.java    From xmlunit with Apache License 2.0 6 votes vote down vote up
@Test
public void countUsesCollectionSizeWhenAvailable() {
    final boolean[] calls = new boolean[2]; // [0] has iterator been called? [1] has size been called?
    int count = Linqy.count(new AbstractCollection() {
        @Override
        public Iterator iterator() {
            calls[0] = true;
            return Arrays.asList(new Object()).iterator();
        }
        @Override
        public int size() {
            calls[1] = true;
            return 1;
        }
    });
    Assert.assertEquals(1, count);
    Assert.assertFalse("iterator has been called", calls[0]);
    Assert.assertTrue("size has not been called", calls[1]);
}
 
Example #13
Source File: HierarchicalSqlSessionFactoryBeanTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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
    }
}
 
Example #14
Source File: ExpiringMap.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@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();
    }
  };
}
 
Example #15
Source File: Operations.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
		}
	};
}
 
Example #16
Source File: ResolvableTypeTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getSuperType() throws Exception {
	ResolvableType type = ResolvableType.forClass(ExtendsList.class).getSuperType();
	assertThat(type.resolve(), equalTo((Class) ArrayList.class));
	type = type.getSuperType();
	assertThat(type.resolve(), equalTo((Class) AbstractList.class));
	type = type.getSuperType();
	assertThat(type.resolve(), equalTo((Class) AbstractCollection.class));
	type = type.getSuperType();
	assertThat(type.resolve(), equalTo((Class) Object.class));
}
 
Example #17
Source File: Client.java    From JFX-Browser with MIT License 5 votes vote down vote up
private static String join(AbstractCollection<String> col, String delimiter) {
	if (col.isEmpty()) return "";
	Iterator<String> iter = col.iterator();
	StringBuffer buffer = new StringBuffer(iter.next());
	while(iter.hasNext()) buffer.append(delimiter).append(iter.next());
	return buffer.toString();
}
 
Example #18
Source File: IncidenceHandlerWithJavaClassVerticesTest.java    From Ferma with Apache License 2.0 5 votes vote down vote up
private Map<String, String> getAbstrListBothDirectionsExtEdges() {
    Map<String, String> edges = new HashMap<>();
    edges.put(AbstractList.class.getName(), AbstractCollection.class.getName());
    edges.put(ArrayList.class.getName(), AbstractList.class.getName());
    edges.put(AbstractSequentialList.class.getName(), AbstractList.class.getName());
    return edges;
}
 
Example #19
Source File: ImmutableClassDef.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@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();
        }
    };
}
 
Example #20
Source File: ImmutableClassDef.java    From AppTroy with Apache License 2.0 5 votes vote down vote up
@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();
        }
    };
}
 
Example #21
Source File: StringUtils.java    From spork with Apache License 2.0 5 votes vote down vote up
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);
        buffer.append(iter.next());
    }
    return buffer.toString();
}
 
Example #22
Source File: ClassUtilTest.java    From common-utils with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void getAllInterfaces() {
    assertEquals(null, ClassUtil.getAllInterfaces(null));
    assertTrue(ClassUtil.getAllInterfaces(Object.class).isEmpty());

    assertFalse(ClassUtil.getAllInterfaces(String.class).isEmpty());
    assertFalse(ClassUtil.getAllInterfaces(Class.class).isEmpty());

    List<Class<?>> supers = ClassUtil.getAllInterfaces(ArrayList.class);
    assertFalse(supers.contains(AbstractList.class));
    assertFalse(supers.contains(AbstractCollection.class));

    assertTrue(supers.contains(List.class));
    assertTrue(supers.contains(RandomAccess.class));
    assertTrue(supers.contains(Iterable.class));
    assertFalse(supers.contains(Object.class));

    assertTrue(ClassUtil.getAllInterfaces(int.class).isEmpty());
    // assertTrue(ClassUtil.getAllInterfaces(int[].class).isEmpty());
    assertFalse(ClassUtil.getAllInterfaces(Integer.class).contains(Number.class));
    assertTrue(ClassUtil.getAllInterfaces(Integer.class).contains(Comparable.class));

    List<Class<?>> list = ClassUtil.getAllInterfaces(Integer[].class);
    assertTrue(list.contains(Cloneable.class));
    assertTrue(list.contains(Serializable.class));

}
 
Example #23
Source File: IterableAdapter.java    From springlets with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public AbstractCollection<S> marshal(Iterable<S> source) throws Exception {

  if (source == null) {
      return (AbstractCollection) Collections.emptyList();
  }

  if (source instanceof AbstractCollection) {
    return (AbstractCollection) source;
  }

  return makeCollection(source);
}
 
Example #24
Source File: WeightedCollectionTest.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCollectionConstructorSemantics()
{
	Collection<Integer> c = new ArrayList<>();
	assertTrue(c.add(I1));
	assertTrue(c.add(I2));
	assertTrue(c.add(null));
	AbstractCollection<Integer> col = new WeightedCollection<>(c);
	assertEquals(3, col.size());
	c.add(4);
	assertEquals(3, col.size());
	col.clear();
	assertEquals(4, c.size());
}
 
Example #25
Source File: IntObjectHashMap.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<V> values() {
    Collection<V> valueCollection = this.valueCollection;
    if (valueCollection == null) {
        this.valueCollection = valueCollection = new AbstractCollection<V>() {
            @Override
            public Iterator<V> iterator() {
                return new Iterator<V>() {
                    final Iterator<Entry<V>> iter = IntObjectHashMap.this.iterator();
                    @Override
                    public boolean hasNext() {
                        return iter.hasNext();
                    }

                    @Override
                    public V next() {
                        return iter.next().value();
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

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

    return valueCollection;
}
 
Example #26
Source File: ConcurrentTLongObjectHashMap.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Collection<T> values() {
  if (this.values == null) {
    this.values = new AbstractCollection<T>() {
      @Override
      public Iterator<T> iterator() {
        return new HashIterator<T>() {
          @Override
          public T next() {
            return nextValue();
          }
        };
      }

      @Override
      public boolean contains(Object v) {
        return ConcurrentTLongObjectHashMap.this.containsValue(v);
      }

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

      @Override
      public boolean isEmpty() {
        return ConcurrentTLongObjectHashMap.this.isEmpty();
      }

      @Override
      public void clear() {
        ConcurrentTLongObjectHashMap.this.clear();
      }
    };
  }
  return this.values;
}
 
Example #27
Source File: LongObjectHashMap.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<V> values() {
    return new AbstractCollection<V>() {
        @Override
        public Iterator<V> iterator() {
            return new Iterator<V>() {
                final PrimitiveIterator iter = new PrimitiveIterator();

                @Override
                public boolean hasNext() {
                    return iter.hasNext();
                }

                @Override
                public V next() {
                    return iter.next().value();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public int size() {
            return size;
        }
    };
}
 
Example #28
Source File: HierarchicalResourceLoaderTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check that resource loading works.
 * 
 * The data available is:
 * <pre>
 * classpatch:resource-loader/
 *    java.util.AbstractCollection
 *    java.util.AbstractList
 *    java.util.TreeSet 
 * </pre>
 * With each folder containing a text file with the name of the folder.
 */
public void testResourceLoading() throws Throwable
{
    // First, do a successful few
    HierarchicalResourceLoader bean;
    Resource resource;

    bean = getLoader(AbstractCollection.class, TreeSet.class);
    resource = bean.getResource(RESOURCE);
    checkResource(resource, "java.util.TreeSet");

    bean = getLoader(AbstractCollection.class, AbstractSet.class);
    resource = bean.getResource(RESOURCE);
    checkResource(resource, "java.util.AbstractCollection");

    bean = getLoader(AbstractCollection.class, AbstractCollection.class);
    resource = bean.getResource(RESOURCE);
    checkResource(resource, "java.util.AbstractCollection");

    bean = getLoader(AbstractCollection.class, ArrayList.class);
    resource = bean.getResource(RESOURCE);
    checkResource(resource, "java.util.AbstractList");

    bean = getLoader(AbstractCollection.class, AbstractList.class);
    resource = bean.getResource(RESOURCE);
    checkResource(resource, "java.util.AbstractList");
}
 
Example #29
Source File: MergingDigest.java    From t-digest with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Centroid> centroids() {
    // we don't actually keep centroid structures around so we have to fake it
    compress();
    return new AbstractCollection<Centroid>() {
        @Override
        public Iterator<Centroid> iterator() {
            return new Iterator<Centroid>() {
                int i = 0;

                @Override
                public boolean hasNext() {
                    return i < lastUsedCell;
                }

                @Override
                public Centroid next() {
                    Centroid rc = new Centroid(mean[i], (int) weight[i], data != null ? data.get(i) : null);
                    i++;
                    return rc;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Default operation");
                }
            };
        }

        @Override
        public int size() {
            return lastUsedCell;
        }
    };
}
 
Example #30
Source File: ImmutableClassDef.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@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();
        }
    };
}