ru.yandex.bolts.collection.impl.UnmodifiableDefaultSetF Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bolts Show documentation
Show all versions of bolts Show documentation
Collections utilities used in various Yandex projects
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 extends E> 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);
}
} //~