@Override List<V> createValues() { return new AbstractSequentialList<V>() { @Override public int size() { return size; } @Override public ListIterator<V> listIterator(int index) { final NodeIterator nodeItr = new NodeIterator(index); return new TransformedListIterator<Entry<K, V>, V>(nodeItr) { @Override V transform(Entry<K, V> entry) { return entry.getValue(); } @Override public void set(V value) { nodeItr.setValue(value); } }; } }; }
/** * {@inheritDoc} * * <p>If the multimap is modified while an iteration over the list is in * progress (except through the iterator's own {@code add}, {@code set} or * {@code remove} operations) the results of the iteration are undefined. * * <p>The returned list is not serializable and does not have random access. */ @Override public List<V> get(final @Nullable K key) { return new AbstractSequentialList<V>() { @Override public int size() { KeyList<K, V> keyList = keyToKeyList.get(key); return (keyList == null) ? 0 : keyList.count; } @Override public ListIterator<V> listIterator(int index) { return new ValueForKeyIterator(key, index); } }; }
@Override List<Entry<K, V>> createEntries() { @WeakOuter class EntriesImpl extends AbstractSequentialList<Entry<K, V>> { @Override public int size() { return size; } @Override public ListIterator<Entry<K, V>> listIterator(int index) { return new NodeIterator(index); } @Override public void forEach(Consumer<? super Entry<K, V>> action) { checkNotNull(action); for (Node<K, V> node = head; node != null; node = node.next) { action.accept(node); } } } return new EntriesImpl(); }
@Override List<Entry<K, V>> createEntries() { @WeakOuter class EntriesImpl extends AbstractSequentialList<Entry<K, V>> { @Override public int size() { return size; } @Override public ListIterator<Entry<K, V>> listIterator(int index) { return new NodeIterator(index); } } return new EntriesImpl(); }
/** * {@inheritDoc} * * <p>The iterator generated by the returned collection traverses the entries * in the order they were added to the multimap. Because the entries may have * duplicates and follow the insertion ordering, this method returns a {@link * List}, instead of the {@link Collection} specified in the {@link * ListMultimap} interface. * * <p>An entry's {@link Entry#getKey} method always returns the same key, * regardless of what happens subsequently. As long as the corresponding * key-value mapping is not removed from the multimap, {@link Entry#getValue} * returns the value from the multimap, which may change over time, and {@link * Entry#setValue} modifies that value. Removing the mapping from the * multimap does not alter the value returned by {@code getValue()}, though a * subsequent {@code setValue()} call won't update the multimap but will lead * to a revised value being returned by {@code getValue()}. */ @Override public List<Entry<K, V>> entries() { List<Entry<K, V>> result = entries; if (result == null) { @WeakOuter class LinkedListMultimapEntries extends AbstractSequentialList<Entry<K, V>> { @Override public int size() { return size; } @Override public ListIterator<Entry<K, V>> listIterator(int index) { return new TransformedListIterator<Node<K, V>, Entry<K, V>>(new NodeIterator(index)) { @Override Entry<K, V> transform(Node<K, V> node) { return createEntry(node); } }; } } entries = result = new LinkedListMultimapEntries(); } return result; }
public Test testsForAbstractSequentialList() { return ListTestSuiteBuilder .using(new TestStringListGenerator () { @Override protected List<String> create(final String[] elements) { // For this test we trust ArrayList works final List<String> list = new ArrayList<String>(); Collections.addAll(list, elements); return new AbstractSequentialList<String>() { @Override public int size() { return list.size(); } @Override public ListIterator<String> listIterator(int index) { return list.listIterator(index); } }; } }) .named("AbstractSequentialList") .withFeatures( ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY) .suppressing(suppressForAbstractSequentialList()) .createTestSuite(); }
/** * @tests {@link java.util.AbstractSequentialList#addAll(int, java.util.Collection)} */ @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "Doesn't verify all exceptions according to the specification.", method = "addAll", args = {int.class, java.util.Collection.class} ) public void test_addAll_ILCollection() { AbstractSequentialList<String> al = new ASLT<String>(); String[] someList = { "Aardvark" , "Bear" , "Chimpanzee", "Duck" }; Collection<String> c = Arrays.asList(someList); al.addAll(c); assertTrue("Should return true", al.addAll(2, c)); }
/** * {@inheritDoc} * * <p>The iterator generated by the returned collection traverses the entries * in the order they were added to the multimap. Because the entries may have * duplicates and follow the insertion ordering, this method returns a {@link * List}, instead of the {@link Collection} specified in the {@link * ListMultimap} interface. * * <p>An entry's {@link Entry#getKey} method always returns the same key, * regardless of what happens subsequently. As long as the corresponding * key-value mapping is not removed from the multimap, {@link Entry#getValue} * returns the value from the multimap, which may change over time, and {@link * Entry#setValue} modifies that value. Removing the mapping from the * multimap does not alter the value returned by {@code getValue()}, though a * subsequent {@code setValue()} call won't update the multimap but will lead * to a revised value being returned by {@code getValue()}. */ @Override public List<Entry<K, V>> entries() { List<Entry<K, V>> result = entries; if (result == null) { entries = result = new AbstractSequentialList<Entry<K, V>>() { @Override public int size() { return keyCount.size(); } @Override public ListIterator<Entry<K, V>> listIterator(int index) { return new TransformedListIterator<Node<K, V>, Entry<K, V>>(new NodeIterator(index)) { @Override Entry<K, V> transform(Node<K, V> node) { return createEntry(node); } }; } }; } return result; }
/** * {@inheritDoc} * * <p>If the multimap is modified while an iteration over the list is in progress (except through * the iterator's own {@code add}, {@code set} or {@code remove} operations) the results of the * iteration are undefined. * * <p>The returned list is not serializable and does not have random access. */ @Override public List<V> get(final @NullableDecl K key) { return new AbstractSequentialList<V>() { @Override public int size() { KeyList<K, V> keyList = keyToKeyList.get(key); return (keyList == null) ? 0 : keyList.count; } @Override public ListIterator<V> listIterator(int index) { return new ValueForKeyIterator(key, index); } }; }
public FramedGraph load() { Graph graph = TinkerGraph.open(); final FramedGraph framedGraph = new DelegatingFramedGraph(graph, true, JAVA_TYPE_TYPES); // Interfaces Vertex collection = makeInterface(graph, Collection.class); Vertex list = makeInterface(graph, List.class); // Classes Vertex obj = makeClass(graph, null, Object.class); Vertex abstrCollection = makeClass(graph, obj, AbstractCollection.class, collection); Vertex abstrList = makeClass(graph, abstrCollection, AbstractList.class, list); Vertex abstrSeqList = makeClass(graph, abstrList, AbstractSequentialList.class, list); makeClass(graph, abstrList, ArrayList.class, list); makeClass(graph, abstrSeqList, LinkedList.class, list, collection); return framedGraph; }
private Collection<Class<? extends Collection>> getCollectionTypes() { Collection<Class<? extends Collection>> result = new HashSet<>(); result.add(List.class); result.add(NavigableSet.class); result.add(Set.class); result.add(SortedSet.class); result.add(AbstractCollection.class); result.add(AbstractList.class); result.add(AbstractSequentialList.class); result.add(AbstractSet.class); result.add(ArrayList.class); result.add(ConcurrentSkipListSet.class); result.add(CopyOnWriteArrayList.class); result.add(CopyOnWriteArraySet.class); //result.add(EnumSet.class); // Specialized collection excluded in test result.add(HashSet.class); result.add(LinkedHashSet.class); result.add(LinkedList.class); result.add(Stack.class); result.add(TreeSet.class); result.add(Vector.class); return result; }
public List<E> basicList() { return new AbstractSequentialList<E>() { @Override public ListIterator<E> listIterator(int index) { return basicListIterator(index); } @Override public int size() { return AbstractSequentialInternalEList.this.size(); } }; }
public Result testIterator() { final Object elems[] = { "0", new Integer(25), "aaa", "string with spaces", new Object(), new MyAbstractSequentialList(), }; AbstractSequentialList l = new MyAbstractSequentialList(); Iterator i = l.iterator(); for (int j = 0; j < elems.length; j++) { l.add(j, elems[j]); } int k = 0; while (i.hasNext()) { if (!i.next().equals(elems[k++])) { return failed("next returns wrong value: index=" + k + "element=" + elems[k]); } } return passed(); }
public List<E> basicList() { return new AbstractSequentialList<E>() { private static final long serialVersionUID = 1L; @Override public ListIterator<E> listIterator(int index) { return basicListIterator(index); } @Override public int size() { return AbstractSequentialInternalEList.this.size(); } }; }
@Override List<Entry<K, V>> createEntries() { return new AbstractSequentialList<Entry<K, V>>() { @Override public int size() { return size; } @Override public ListIterator<Entry<K, V>> listIterator(int index) { return new NodeIterator(index); } }; }
@Override List<V> createValues() { @WeakOuter class ValuesImpl extends AbstractSequentialList<V> { @Override public int size() { return size; } @Override public ListIterator<V> listIterator(int index) { final NodeIterator nodeItr = new NodeIterator(index); return new TransformedListIterator<Entry<K, V>, V>(nodeItr) { @Override V transform(Entry<K, V> entry) { return entry.getValue(); } @Override public void set(V value) { nodeItr.setValue(value); } }; } } return new ValuesImpl(); }