Example usage for java.util Set Set

List of usage examples for java.util Set Set

Introduction

In this page you can find the example usage for java.util Set Set.

Prototype

Set

Source Link

Usage

From source file:Main.java

static <E> Set<E> ungrowableSet(final Set<E> s) {
    return new Set<E>() {

        @Override//from   w w w.j a va  2 s  . c  o  m
        public int size() {
            return s.size();
        }

        @Override
        public boolean isEmpty() {
            return s.isEmpty();
        }

        @Override
        public boolean contains(Object o) {
            return s.contains(o);
        }

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

        @Override
        public <T> T[] toArray(T[] a) {
            return s.toArray(a);
        }

        @Override
        public String toString() {
            return s.toString();
        }

        @Override
        public Iterator<E> iterator() {
            return s.iterator();
        }

        @Override
        public boolean equals(Object o) {
            return s.equals(o);
        }

        @Override
        public int hashCode() {
            return s.hashCode();
        }

        @Override
        public void clear() {
            s.clear();
        }

        @Override
        public boolean remove(Object o) {
            return s.remove(o);
        }

        @Override
        public boolean containsAll(Collection<?> coll) {
            return s.containsAll(coll);
        }

        @Override
        public boolean removeAll(Collection<?> coll) {
            return s.removeAll(coll);
        }

        @Override
        public boolean retainAll(Collection<?> coll) {
            return s.retainAll(coll);
        }

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

        @Override
        public boolean addAll(Collection<? extends E> coll) {
            throw new UnsupportedOperationException();
        }

    };

}

From source file:com.evolveum.midpoint.prism.xnode.MapXNode.java

@NotNull
public Set<java.util.Map.Entry<QName, XNode>> entrySet() {
    Set<java.util.Map.Entry<QName, XNode>> entries = new Set<Map.Entry<QName, XNode>>() {

        @Override/*from w  ww. j  a  v  a2  s .  c o  m*/
        public int size() {
            return subnodes.size();
        }

        @Override
        public boolean isEmpty() {
            return subnodes.isEmpty();
        }

        @Override
        public boolean contains(Object o) {
            return subnodes.contains(o);
        }

        @Override
        public Iterator<java.util.Map.Entry<QName, XNode>> iterator() {
            return (Iterator) subnodes.iterator();
        }

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

        @Override
        public <T> T[] toArray(T[] a) {
            return subnodes.toArray(a);
        }

        @Override
        public boolean add(java.util.Map.Entry<QName, XNode> e) {
            throw new UnsupportedOperationException();
            //            put(e.getKey(), e.getValue());
            //            return true;
        }

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

        @Override
        public boolean containsAll(Collection<?> c) {
            return subnodes.containsAll(c);
        }

        @Override
        public boolean addAll(Collection<? extends java.util.Map.Entry<QName, XNode>> 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();
        }
    };
    return entries;
}

From source file:com.github.jsonj.JsonObject.java

@Override
public Set<Entry<String, JsonElement>> entrySet() {
    final Set<Entry<Integer, JsonElement>> entrySet = intMap.entrySet();
    return new Set<Map.Entry<String, JsonElement>>() {

        @Override/*www  .  jav a 2  s .c  o m*/
        public boolean add(java.util.Map.Entry<String, JsonElement> e) {
            throw new UnsupportedOperationException("entry set is immutable");
        }

        @Override
        public boolean addAll(Collection<? extends java.util.Map.Entry<String, JsonElement>> c) {
            throw new UnsupportedOperationException("entry set is immutable");
        }

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

        @Override
        public boolean contains(Object o) {
            throw new UnsupportedOperationException("not supported");
        }

        @Override
        public boolean containsAll(Collection<?> c) {
            throw new UnsupportedOperationException("not supported");
        }

        @Override
        public boolean isEmpty() {
            return entrySet.isEmpty();
        }

        @Override
        public Iterator<Entry<String, JsonElement>> iterator() {
            return new Iterator<Entry<String, JsonElement>>() {
                private final Iterator<Entry<Integer, JsonElement>> it = entrySet.iterator();

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

                @Override
                public Entry<String, JsonElement> next() {
                    final Entry<Integer, JsonElement> next = it.next();
                    return new Entry<String, JsonElement>() {

                        @Override
                        public String getKey() {
                            EfficientString es = EfficientString.get(next.getKey());
                            return es.toString();
                        }

                        @Override
                        public JsonElement getValue() {
                            return next.getValue();
                        }

                        @Override
                        public JsonElement setValue(JsonElement value) {
                            throw new UnsupportedOperationException("immutable entry");
                        }
                    };
                }

                @Override
                public void remove() {
                    it.remove();
                }
            };
        }

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

        @Override
        public boolean removeAll(Collection<?> c) {
            throw new UnsupportedOperationException("entry set is immutable");
        }

        @Override
        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedOperationException("entry set is immutable");
        }

        @Override
        public int size() {
            return entrySet.size();
        }

        @Override
        public Object[] toArray() {
            @SuppressWarnings("unchecked")
            Entry<String, JsonElement>[] result = new Entry[entrySet.size()];
            int i = 0;
            for (final Entry<Integer, JsonElement> e : entrySet) {
                result[i] = new Entry<String, JsonElement>() {

                    @Override
                    public String getKey() {
                        EfficientString es = EfficientString.get(e.getKey());
                        return es.toString();
                    }

                    @Override
                    public JsonElement getValue() {
                        return e.getValue();
                    }

                    @Override
                    public JsonElement setValue(JsonElement value) {
                        throw new UnsupportedOperationException("immutable");
                    }
                };
                i++;
            }
            return result;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> T[] toArray(T[] a) {
            return (T[]) toArray();
        }
    };
}

From source file:com.isentropy.accumulo.collections.AccumuloSortedMap.java

/**
 * set is read only//  w w  w.  j a v a 2s. c  o m
 */
@Override
public Set<K> keySet() {
    final AccumuloSortedMap<K, V> enclosing = this;
    return new Set<K>() {

        @Override
        public boolean add(Object e) {
            throw new UnsupportedOperationException();
        }

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

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

        @Override
        public boolean contains(Object o) {
            return enclosing.containsKey(o);
        }

        @Override
        public boolean containsAll(Collection c) {
            for (Object o : c) {
                if (!contains(o)) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean isEmpty() {
            return enclosing.isEmpty();
        }

        @Override
        public Iterator iterator() {
            return new KeySetIterator(enclosing.iterator());
        }

        @Override
        public boolean remove(Object o) {
            return false;
        }

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

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

        @Override
        public int size() {
            return enclosing.size();
        }

        @Override
        public Object[] toArray() {
            Object[] o = new Object[size()];
            return toArray(o);
        }

        @Override
        public Object[] toArray(Object[] a) {
            Iterator i = iterator();
            int c = 0;
            for (; i.hasNext() && c < a.length;) {
                a[c++] = i.next();
            }
            return a;
        }
    };
}

From source file:mondrian.olap.Util.java

public static <T> Set<T> newIdentityHashSetFake() {
    final HashMap<T, Boolean> map = new HashMap<T, Boolean>();
    return new Set<T>() {
        public int size() {
            return map.size();
        }/*w  w w .j a  v  a2 s  .  c o  m*/

        public boolean isEmpty() {
            return map.isEmpty();
        }

        public boolean contains(Object o) {
            return map.containsKey(o);
        }

        public Iterator<T> iterator() {
            return map.keySet().iterator();
        }

        public Object[] toArray() {
            return map.keySet().toArray();
        }

        public <T> T[] toArray(T[] a) {
            return map.keySet().toArray(a);
        }

        public boolean add(T t) {
            return map.put(t, Boolean.TRUE) == null;
        }

        public boolean remove(Object o) {
            return map.remove(o) == Boolean.TRUE;
        }

        public boolean containsAll(Collection<?> c) {
            return map.keySet().containsAll(c);
        }

        public boolean addAll(Collection<? extends T> c) {
            throw new UnsupportedOperationException();
        }

        public boolean retainAll(Collection<?> c) {
            throw new UnsupportedOperationException();
        }

        public boolean removeAll(Collection<?> c) {
            throw new UnsupportedOperationException();
        }

        public void clear() {
            map.clear();
        }
    };
}