/* * #%L * Gravia :: Resource * %% * Copyright (C) 2010 - 2014 JBoss by Red Hat * %% * 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. * #L% */ package org.jboss.gravia.utils; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; /** * A Collection that does not allow add operations. * * @author thomas.diesler@jboss.com * @since 21-Mar-2010 */ @SuppressWarnings("rawtypes") public final class RemoveOnlyCollection<T> implements Collection<T> { Collection<T> delegate; @SafeVarargs public RemoveOnlyCollection(T... elements) { if (elements == null) throw new IllegalArgumentException("Null elements"); this.delegate = new ArrayList<T>(Arrays.asList(elements)); } public RemoveOnlyCollection(Collection<T> delegate) { if (delegate == null) throw new IllegalArgumentException("Null delegate"); this.delegate = delegate; } @Override public int size() { return delegate.size(); } @Override public boolean isEmpty() { return delegate.isEmpty(); } @Override public boolean contains(Object o) { return delegate.contains(o); } @Override public Iterator<T> iterator() { return delegate.iterator(); } @Override public Object[] toArray() { return delegate.toArray(); } @Override @SuppressWarnings("unchecked") public Object[] toArray(Object[] a) { return delegate.toArray(a); } @Override public boolean add(Object e) { throw new UnsupportedOperationException(); } @Override public boolean remove(Object o) { return delegate.remove(o); } @Override public boolean containsAll(Collection c) { return delegate.containsAll(c); } @Override public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } @Override public boolean removeAll(Collection c) { return delegate.removeAll(c); } @Override public boolean retainAll(Collection c) { return delegate.removeAll(c); } @Override public void clear() { delegate.clear(); } @Override public int hashCode() { return delegate.hashCode(); } @Override public boolean equals(Object obj) { return delegate.equals(obj); } @Override public String toString() { return delegate.toString(); } }