Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Collection/testlibrary/ExtendsAbstractCollection.java
38828 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.util.AbstractCollection;23import java.util.HashSet;24import java.util.AbstractSet;25import java.util.ArrayList;26import java.util.Collection;27import java.util.Iterator;28import java.util.function.Supplier;2930/**31* @library32*33* A simple mutable collection implementation that provides only default34* implementations of all methods. ie. none of the Collection interface default35* methods have overridden implementations.36*37* @param <E> type of collection elements38*/39public class ExtendsAbstractCollection<E> extends AbstractCollection<E> {4041protected final Collection<E> coll;4243public ExtendsAbstractCollection() {44this(ArrayList<E>::new);45}4647public ExtendsAbstractCollection(Collection<E> source) {48this();49coll.addAll(source);50}5152protected ExtendsAbstractCollection(Supplier<Collection<E>> backer) {53this.coll = backer.get();54}5556public boolean add(E element) {57return coll.add(element);58}5960public boolean remove(Object element) {61return coll.remove(element);62}6364public Iterator<E> iterator() {65return new Iterator<E>() {66Iterator<E> source = coll.iterator();6768public boolean hasNext() {69return source.hasNext();70}7172public E next() {73return source.next();74}7576public void remove() {77source.remove();78}79};80}8182public int size() {83return coll.size();84}85}868788