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

com.brein.time.timeintervals.collections.UnmodifiableIntervalCollection Maven / Gradle / Ivy

package com.brein.time.timeintervals.collections;

import com.brein.time.timeintervals.filters.IntervalFilter;
import com.brein.time.timeintervals.indexes.IntervalValueComparator;
import com.brein.time.timeintervals.intervals.IInterval;

import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Stream;

public class UnmodifiableIntervalCollection implements IntervalCollection {

    private transient final IntervalCollection wrappedCollection;

    public UnmodifiableIntervalCollection(final IntervalCollection wrappedCollection) {
        this.wrappedCollection = wrappedCollection;
    }

    @Override
    public boolean add(final IInterval interval) {
        throw new IllegalStateException("Collection is unmodifiable.");
    }

    @Override
    public boolean remove(final IInterval interval) {
        throw new IllegalStateException("Collection is unmodifiable.");
    }

    @Override
    public boolean isEmpty() {
        return wrappedCollection.isEmpty();
    }

    @Override
    public int size() {
        return wrappedCollection.size();
    }

    @Override
    public Collection find(final IInterval interval, final IntervalValueComparator cmp) {
        return wrappedCollection.find(interval, cmp);
    }

    @Override
    public Collection find(final IInterval interval,
                                      final IntervalValueComparator cmp,
                                      final IntervalFilter filter) {
        return wrappedCollection.find(interval, cmp, filter);
    }

    @Override
    public Stream stream() {
        return wrappedCollection.stream();
    }

    @Override
    public String getUniqueIdentifier() {
        return wrappedCollection.getUniqueIdentifier();
    }

    @Override
    public Iterator iterator() {
        final Iterator it = wrappedCollection.iterator();
        return new Iterator() {

            @Override
            public boolean hasNext() {
                return it.hasNext();
            }

            @Override
            public IInterval next() {
                return it.next();
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy