javolution.util.internal.collection.UnmodifiableCollectionImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javolution-core-java-msftbx
Show all versions of javolution-core-java-msftbx
Only the Java Core part of Javolution library, with slight modifications for use in MSFTBX.
The newest version!
/*
* Javolution - Java(TM) Solution for Real-Time and Embedded Systems
* Copyright (C) 2012 - Javolution (http://javolution.org/)
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software is
* freely granted, provided that this notice is preserved.
*/
package javolution.util.internal.collection;
import java.util.Iterator;
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
/**
* An unmodifiable view over a collection.
*/
public class UnmodifiableCollectionImpl extends CollectionView {
/** Read-Only Iterator. */
private class IteratorImpl implements Iterator {
private final Iterator targetIterator = target().iterator();
@Override
public boolean hasNext() {
return targetIterator.hasNext();
}
@Override
public E next() {
return targetIterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException("Read-Only Collection.");
}
}
private static final long serialVersionUID = 0x600L; // Version.
public UnmodifiableCollectionImpl(CollectionService target) {
super(target);
}
@Override
public boolean add(E element) {
throw new UnsupportedOperationException("Read-Only Collection.");
}
@Override
public void clear() {
throw new UnsupportedOperationException("Read-Only Collection.");
}
@Override
public Equality super E> comparator() {
return target().comparator();
}
@Override
public boolean contains(Object obj) {
return target().contains(obj);
}
@Override
public boolean isEmpty() {
return target().isEmpty();
}
@Override
public Iterator iterator() {
return new IteratorImpl();
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException("Read-Only Collection.");
}
@Override
public int size() {
return target().size();
}
@SuppressWarnings("unchecked")
@Override
public CollectionService[] split(int n, boolean updateable) {
CollectionService[] subTargets = target().split(n, updateable);
CollectionService[] result = new CollectionService[subTargets.length];
for (int i = 0; i < subTargets.length; i++) {
result[i] = new UnmodifiableCollectionImpl(subTargets[i]);
}
return result;
}
}