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

org.infinispan.util.ReadOnlyCollectionAsSet Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.util;

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

/**
 * Assumes that the delegate collection already contains unique elements.
 */
public class ReadOnlyCollectionAsSet implements Set {
   private final Collection delegate;

   public ReadOnlyCollectionAsSet(Collection 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 iterator() {
      return new Iterator() {
         private final Iterator it = delegate.iterator();

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

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

   @Override
   public Object[] toArray() {
      return delegate.toArray();
   }

   @Override
   public  T1[] toArray(T1[] a) {
      return delegate.toArray(a);
   }

   @Override
   public boolean add(T t) {
      throw new UnsupportedOperationException();
   }

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

   @Override
   public boolean containsAll(Collection c) {
      return delegate.containsAll(c);
   }

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

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy