All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.landawn.abacus.util.ImmutableNavigableSet Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.2.4
Show newest version
/*
 * Copyright (C) 2017 HaiYang Li
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.landawn.abacus.util;

import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author Haiyang Li
 * @param 
 * @since 1.1.4
 */
public final class ImmutableNavigableSet extends ImmutableSortedSet implements NavigableSet { //NOSONAR

    @SuppressWarnings("rawtypes")
    private static final ImmutableNavigableSet EMPTY = new ImmutableNavigableSet(N.emptyNavigableSet());

    private final NavigableSet navigableSet;

    ImmutableNavigableSet(NavigableSet navigableSet) {
        super(navigableSet);
        this.navigableSet = (NavigableSet) navigableSet;
    }

    /**
     *
     * @param 
     * @return
     */
    public static  ImmutableNavigableSet empty() {
        return EMPTY;
    }

    /**
     *
     * @param 
     * @param e
     * @return
     */
    public static > ImmutableNavigableSet just(T e) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @param e3 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2, final T e3) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2, e3)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @param e3 
     * @param e4 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2, final T e3, final T e4) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2, e3, e4)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @param e3 
     * @param e4 
     * @param e5 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2, final T e3, final T e4, final T e5) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2, e3, e4, e5)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @param e3 
     * @param e4 
     * @param e5 
     * @param e6 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2, final T e3, final T e4, final T e5, final T e6) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2, e3, e4, e5, e6)));
    }

    /**
     * 
     *
     * @param  
     * @param e1 
     * @param e2 
     * @param e3 
     * @param e4 
     * @param e5 
     * @param e6 
     * @param e7 
     * @return 
     */
    public static > ImmutableNavigableSet of(final T e1, final T e2, final T e3, final T e4, final T e5, final T e6,
            final T e7) {
        return new ImmutableNavigableSet<>(new TreeSet<>(N.asList(e1, e2, e3, e4, e5, e6, e7)));
    }

    /**
     *
     * @param 
     * @param sortedSet
     * @return
     */
    public static  ImmutableNavigableSet copyOf(final SortedSet sortedSet) {
        if (N.isNullOrEmpty(sortedSet)) {
            return empty();
        }

        return new ImmutableNavigableSet<>(new TreeSet<>(sortedSet));
    }

    /**
     *
     * @param 
     * @param navigableSet
     * @return an {@code ImmutableNavigableSet} backed by the specified {@code navigableSet}
     * @deprecated the ImmutableNavigableSet may be modified through the specified {@code navigableSet}
     */
    @Deprecated
    public static  ImmutableNavigableSet wrap(final NavigableSet navigableSet) {
        if (navigableSet == null) {
            return empty();
        } else if (navigableSet instanceof ImmutableNavigableSet) {
            return (ImmutableNavigableSet) navigableSet;
        }

        return new ImmutableNavigableSet<>(navigableSet);
    }

    /**
     * 
     *
     * @param  
     * @param sortedSet 
     * @return 
     * @throws UnsupportedOperationException 
     * @deprecated throws {@code UnsupportedOperationException}
     */
    @Deprecated
    public static  ImmutableSortedSet wrap(final SortedSet sortedSet) throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     *
     * @param e
     * @return
     */
    @Override
    public E lower(E e) {
        return navigableSet.lower(e);
    }

    /**
     *
     * @param e
     * @return
     */
    @Override
    public E floor(E e) {
        return navigableSet.floor(e);
    }

    /**
     *
     * @param e
     * @return
     */
    @Override
    public E ceiling(E e) {
        return navigableSet.ceiling(e);
    }

    /**
     *
     * @param e
     * @return
     */
    @Override
    public E higher(E e) {
        return navigableSet.higher(e);
    }

    /**
     * 
     *
     * @return 
     * @throws UnsupportedOperationException 
     * @deprecated - UnsupportedOperationException
     */
    @Deprecated
    @Override
    public E pollFirst() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     * 
     *
     * @return 
     * @throws UnsupportedOperationException 
     * @deprecated - UnsupportedOperationException
     */
    @Deprecated
    @Override
    public E pollLast() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    /**
     * 
     *
     * @return 
     */
    @Override
    public ImmutableNavigableSet descendingSet() {
        return wrap(navigableSet.descendingSet());
    }

    /**
     * 
     *
     * @return 
     */
    @Override
    public ObjIterator descendingIterator() {
        return ObjIterator.of(navigableSet.descendingIterator());
    }

    /**
     *
     * @param fromElement
     * @param fromInclusive
     * @param toElement
     * @param toInclusive
     * @return
     */
    @Override
    public ImmutableNavigableSet subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) {
        return wrap(navigableSet.subSet(fromElement, fromInclusive, toElement, toInclusive));
    }

    /**
     *
     * @param toElement
     * @param inclusive
     * @return
     */
    @Override
    public ImmutableNavigableSet headSet(E toElement, boolean inclusive) {
        return wrap(navigableSet.headSet(toElement, inclusive));
    }

    /**
     *
     * @param fromElement
     * @param inclusive
     * @return
     */
    @Override
    public ImmutableNavigableSet tailSet(E fromElement, boolean inclusive) {
        return wrap(navigableSet.tailSet(fromElement, inclusive));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy