org.jhotdraw8.icollection.facade.ReadOnlySequencedCollectionFacade Maven / Gradle / Ivy
/*
* @(#)ReadOnlySequencedCollectionFacade.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.icollection.facade;
import org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection;
import org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet;
import java.util.Iterator;
import java.util.SequencedCollection;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.IntSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;
/**
* Provides a {@link ReadOnlySequencedSet} facade to a set of {@code Set} functions.
*
* @param the element type
* @author Werner Randelshofer
*/
public class ReadOnlySequencedCollectionFacade extends ReadOnlyCollectionFacade
implements ReadOnlySequencedCollection {
final Supplier getFirstFunction;
final Supplier getLastFunction;
final Supplier> reverseIteratorFunction;
public ReadOnlySequencedCollectionFacade(SequencedCollection c) {
this(c::iterator, () -> c.reversed().iterator(), c::size,
c::contains, c::getFirst, c::getLast, Spliterator.SIZED);
}
public ReadOnlySequencedCollectionFacade(Supplier> iteratorFunction,
Supplier> reverseIteratorFunction,
IntSupplier sizeFunction,
Predicate