Example usage for java.util AbstractSet AbstractSet

List of usage examples for java.util AbstractSet AbstractSet

Introduction

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

Prototype

protected AbstractSet() 

Source Link

Document

Sole constructor.

Usage

From source file:ArrayMap.java

public Set entrySet() {
    if (entries == null) {
        entries = new AbstractSet() {
            public void clear() {
                list.clear();//from  www  . ja  v a  2  s. com
            }

            public Iterator iterator() {
                return list.iterator();
            }

            public int size() {
                return list.size();
            }
        };
    }
    return entries;
}

From source file:com.google.gwt.dev.util.collect.IdentityHashSetTest.java

@SuppressWarnings("unchecked")
@Override/* w ww  . j av  a2  s  . c  o  m*/
public Collection makeConfirmedCollection() {
    final java.util.IdentityHashMap map = new java.util.IdentityHashMap();
    return new AbstractSet() {
        @Override
        public boolean add(Object e) {
            return map.put(e, e) == null;
        }

        @Override
        public Iterator iterator() {
            return map.keySet().iterator();
        }

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

From source file:therian.util.TypeVariableMap.java

@Override
public Set<Map.Entry<TypeVariable<?>, Type>> entrySet() {
    final Set<Map.Entry<TypeVariable<?>, Type>> wrappedEntries = wrapped.entrySet();
    return new AbstractSet<Map.Entry<TypeVariable<?>, Type>>() {

        @Override// ww  w . j  a v  a  2 s.c  o m
        public Iterator<java.util.Map.Entry<TypeVariable<?>, Type>> iterator() {
            final Iterator<java.util.Map.Entry<TypeVariable<?>, Type>> wrappedIterator = wrappedEntries
                    .iterator();
            return new Iterator<Map.Entry<TypeVariable<?>, Type>>() {

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

                @Override
                public Map.Entry<TypeVariable<?>, Type> next() {
                    final Map.Entry<TypeVariable<?>, Type> wrappedEntry = wrappedIterator.next();
                    return new Map.Entry<TypeVariable<?>, Type>() {

                        @Override
                        public TypeVariable<?> getKey() {
                            return wrappedEntry.getKey();
                        }

                        @Override
                        public Type getValue() {
                            return wrappedEntry.getValue();
                        }

                        @Override
                        public Type setValue(Type value) {
                            return wrappedEntry.setValue(value);
                        }

                        @Override
                        public String toString() {
                            return TypeVariableMap.toString(getKey()) + '='
                                    + TypeVariableMap.toString(getValue());
                        }
                    };
                }

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

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

    };
}

From source file:com.tussle.script.StackedBindings.java

public Set<Map.Entry<String, Object>> entrySet() {
    if (entrySet == null)
        entrySet = new AbstractSet<Map.Entry<String, Object>>() {
            public Iterator<Map.Entry<String, Object>> iterator() {
                return IteratorUtils.transformedIterator(bindingMap.entrySet().iterator(),
                        StackedBindingsEntry::new);
            }//from   w w w  .ja  v a 2 s.c o m

            public int size() {
                return bindingMap.size();
            }
        };
    return entrySet;
}

From source file:com.conwet.silbops.model.Advertise.java

/**
 * @throws UnsupportedOperationException since there is no real need to
 * duplicate elements.//w w  w  .  j a v  a2  s . c o m
 */
@Override
public Set<Entry<Attribute, Attribute>> entries() {

    return new AbstractSet<Entry<Attribute, Attribute>>() {

        @Override
        public Iterator<Entry<Attribute, Attribute>> iterator() {

            final Iterator<Attribute> iterator = attributes.iterator();

            return new Iterator<Entry<Attribute, Attribute>>() {

                @Override
                public boolean hasNext() {

                    return iterator.hasNext();
                }

                @Override
                public Entry<Attribute, Attribute> next() {

                    Attribute attribute = iterator.next();

                    return new SimpleImmutableEntry<>(attribute, attribute);
                }

                @Override
                public void remove() {

                    throw new UnsupportedOperationException("Read-only iterator.");
                }
            };
        }

        @Override
        public int size() {

            return attributes.size();
        }
    };
}

From source file:MultiMap.java

public Set entrySet() {
    int size = 0;
    Iterator iterKeys = map.entrySet().iterator();
    while (iterKeys.hasNext()) {
        Map.Entry entry = (Map.Entry) iterKeys.next();
        Collection values = (Collection) entry.getValue();
        Iterator iterValues = values.iterator();
        while (iterValues.hasNext()) {
            size++;//from  www. jav a2 s  .co  m
            iterValues.next();
        }
    }

    final int finalSize = size;

    final Iterator entries = map.entrySet().iterator();

    return new AbstractSet() {
        int pos = 0;
        Map.Entry entry;
        Iterator values;

        public Iterator iterator() {
            return new Iterator() {
                public void remove() {
                    throw new UnsupportedOperationException();
                }

                public boolean hasNext() {
                    return pos != finalSize;
                }

                public Object next() {
                    while (true) {
                        if (entry == null) {
                            entry = (Map.Entry) entries.next();
                            values = ((Collection) entry.getValue()).iterator();
                        }
                        Object key = entry.getKey();
                        if (values.hasNext()) {
                            Object value = values.next();
                            pos++;
                            return new Entry(key, value);
                        } else {
                            entry = null;
                        }
                    }
                }
            };
        }

        public int size() {
            return finalSize;
        }
    };
}

From source file:ListOrderedMap.java

public Set keySet() {
    return new AbstractSet() {
        public int size() {
            return map.size();
        }//from   w  w w. j a va 2  s .  c o  m

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

        public void clear() {
            ListOrderedMap.this.clear();
        }

        public Iterator iterator() {
            return new Iterator() {
                Object last = null;
                Iterator keys = lst.iterator();

                public Object next() {
                    return last = keys.next();
                }

                public boolean hasNext() {
                    return keys.hasNext();
                }

                public void remove() {
                    keys.remove();
                    map.remove(last);
                }
            };
        }
    };
}

From source file:com.tussle.script.StackedBindings.java

public Set<String> keySet() {
    if (keySet == null)
        keySet = new AbstractSet<String>() {
            public Iterator<String> iterator() {
                return IteratorUtils.transformedIterator(bindingMap.entrySet().iterator(), Entry::getKey);
            }/*  w w  w  .  ja  v  a2 s  .c  o m*/

            public int size() {
                return bindingMap.size();
            }
        };
    return keySet;
}

From source file:MicroMap.java

/**
 * @see java.util.Map#keySet()//from w  ww .jav a2 s  . c  o  m
 */
public Set keySet() {
    return new AbstractSet() {
        public Iterator iterator() {
            return new Iterator() {
                public boolean hasNext() {
                    return index < MicroMap.this.size();
                }

                public Object next() {
                    index++;

                    return key;
                }

                public void remove() {
                    MicroMap.this.clear();
                }

                int index;
            };
        }

        public int size() {
            return MicroMap.this.size();
        }
    };
}

From source file:MicroMap.java

/**
 * @see java.util.Map#keySet()//  w w w  .  jav  a  2 s. c  o  m
 */
public Set<K> keySet() {
    return new AbstractSet<K>() {
        @Override
        public Iterator<K> iterator() {
            return new Iterator<K>() {
                public boolean hasNext() {
                    return index < MicroMap.this.size();
                }

                public K next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    index++;

                    return key;
                }

                public void remove() {
                    MicroMap.this.clear();
                }

                int index;
            };
        }

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