org.jhotdraw8.icollection.facade.ReadOnlyNavigableMapFacade Maven / Gradle / Ivy
/*
* @(#)ReadOnlyNavigableMapFacade.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.icollection.facade;
import org.jhotdraw8.icollection.readonly.ReadOnlyNavigableMap;
import org.jspecify.annotations.Nullable;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Spliterator;
import java.util.function.Function;
import java.util.function.IntSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;
/**
* Provides a {@link ReadOnlyNavigableMap} facade to a set of {@code ReadOnlyNavigableMap} functions.
*
* @param the key type
* @param the value type
* @author Werner Randelshofer
*/
public class ReadOnlyNavigableMapFacade extends ReadOnlyMapFacade
implements ReadOnlyNavigableMap {
private final Supplier> firstEntryFunction;
private final Supplier> lastEntryFunction;
private final Supplier>> reverseIteratorFunction;
private final int characteristics;
final Function> ceilingFunction;
final Function> floorFunction;
final Function> higherFunction;
final Function> lowerFunction;
private final Supplier> comparatorSupplier;
public ReadOnlyNavigableMapFacade(NavigableMap target) {
super(target);
this.firstEntryFunction = target::firstEntry;
this.lastEntryFunction = target::lastEntry;
this.reverseIteratorFunction = () -> target.reversed().sequencedEntrySet().iterator();
this.characteristics = Spliterator.ORDERED | Spliterator.SIZED | Spliterator.DISTINCT;
this.comparatorSupplier = target::comparator;
this.ceilingFunction = target::ceilingEntry;
this.floorFunction = target::floorEntry;
this.higherFunction = target::higherEntry;
this.lowerFunction = target::lowerEntry;
}
public ReadOnlyNavigableMapFacade(
Supplier>> iteratorFunction,
Supplier>> reverseIteratorFunction,
IntSupplier sizeFunction,
Predicate