java.util.AbstractSet

Here are the examples of the java api class java.util.AbstractSet taken from open source projects.

1. HashAdapter#entrySet()

View license
@Override
public Set entrySet() {
    if (entrySet != null) {
        return entrySet;
    }
    return entrySet = new AbstractSet() {

        @Override
        public Iterator iterator() {
            final TemplateModelIterator i;
            try {
                i = getModelEx().keys().iterator();
            } catch (TemplateModelException e) {
                throw new UndeclaredThrowableException(e);
            }
            return new Iterator() {

                public boolean hasNext() {
                    try {
                        return i.hasNext();
                    } catch (TemplateModelException e) {
                        throw new UndeclaredThrowableException(e);
                    }
                }

                public Object next() {
                    final Object key;
                    try {
                        key = wrapper.unwrap(i.next());
                    } catch (TemplateModelException e) {
                        throw new UndeclaredThrowableException(e);
                    }
                    return new Map.Entry() {

                        public Object getKey() {
                            return key;
                        }

                        public Object getValue() {
                            return get(key);
                        }

                        public Object setValue(Object value) {
                            throw new UnsupportedOperationException();
                        }

                        @Override
                        public boolean equals(Object o) {
                            if (!(o instanceof Map.Entry))
                                return false;
                            Map.Entry e = (Map.Entry) o;
                            Object k1 = getKey();
                            Object k2 = e.getKey();
                            if (k1 == k2 || (k1 != null && k1.equals(k2))) {
                                Object v1 = getValue();
                                Object v2 = e.getValue();
                                if (v1 == v2 || (v1 != null && v1.equals(v2)))
                                    return true;
                            }
                            return false;
                        }

                        @Override
                        public int hashCode() {
                            Object value = getValue();
                            return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
                        }
                    };
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }

        @Override
        public int size() {
            try {
                return getModelEx().size();
            } catch (TemplateModelException e) {
                throw new UndeclaredThrowableException(e);
            }
        }
    };
}

2. TSpaceTest#testGetKeySet()

Project: jPOS
Source File: TSpaceTest.java
View license
@Test
public void testGetKeySet() throws Throwable {
    TSpace tSpace = new TSpace();
    AbstractSet result = (AbstractSet) tSpace.getKeySet();
    assertEquals("result.size()", 0, result.size());
    assertEquals("tSpace.entries.size()", 0, tSpace.entries.size());
}