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

ru.yandex.bolts.collection.impl.UnmodifiableDefaultSetF Maven / Gradle / Ivy

The newest version!
package ru.yandex.bolts.collection.impl;

import java.util.Collection;
import java.util.Set;

import ru.yandex.bolts.collection.IteratorF;
import ru.yandex.bolts.collection.SetF;
import ru.yandex.bolts.collection.Unmodifiable;


public class UnmodifiableDefaultSetF extends DefaultSetF implements Unmodifiable {
    private static final long serialVersionUID = -3357028613260080942L;

    public UnmodifiableDefaultSetF(Set target) {
        super(target);
    }

    @Override
    public SetF unmodifiable() {
        return this;
    }

    @Override
    public boolean add(E o) {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public boolean addAll(Collection c) {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public boolean retainAll(Collection c) {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public boolean removeAll(Collection c) {
        throw new UnsupportedOperationException("immutable");
    }

    @Override
    public IteratorF iterator() {
        return new UnmodifiableDefaultIteratorF<>(target.iterator());
    }

    public static  SetF wrap(Set set) {
        if (set instanceof SetF && set instanceof Unmodifiable) return (SetF) set;
        else return new UnmodifiableDefaultSetF<>(set);
    }
} //~




© 2015 - 2024 Weber Informatics LLC | Privacy Policy