use of java.util.AbstractSet in project bnd by bndtools.
the class PersistentMap method entrySet.
public Set<java.util.Map.Entry<String, V>> entrySet() {
return new AbstractSet<Map.Entry<String, V>>() {
public int size() {
init();
return cache.size();
}
public Iterator<java.util.Map.Entry<String, V>> iterator() {
init();
return new Iterator<Map.Entry<String, V>>() {
Iterator<java.util.Map.Entry<String, SoftReference<V>>> it = cache.entrySet().iterator();
java.util.Map.Entry<String, SoftReference<V>> entry;
public boolean hasNext() {
return it.hasNext();
}
@SuppressWarnings("unchecked")
public java.util.Map.Entry<String, V> next() {
try {
entry = it.next();
SoftReference<V> ref = entry.getValue();
V value = null;
if (ref != null)
value = ref.get();
if (value == null) {
File file = new File(data, entry.getKey());
value = (V) codec.dec().from(file).get(type);
entry.setValue(new SoftReference<V>(value));
}
final V v = value;
return new Map.Entry<String, V>() {
public String getKey() {
return entry.getKey();
}
public V getValue() {
return v;
}
public V setValue(V value) {
return put(entry.getKey(), value);
}
};
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public void remove() {
PersistentMap.this.remove(entry.getKey());
}
};
}
};
}
use of java.util.AbstractSet in project freemarker by apache.
the class IdentityHashMap method entrySet.
/**
* Returns a collection view of the mappings contained in this map. Each
* element in the returned collection is a <tt>Map.Entry</tt>. The
* collection is backed by the map, so changes to the map are reflected in
* the collection, and vice versa. The collection supports element
* removal, which removes the corresponding mapping from the map, via the
* <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
* <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> operations.
* It does not support the <tt>add</tt> or <tt>addAll</tt> operations.
*
* @return a collection view of the mappings contained in this map.
* @see java.util.Map.Entry
*/
@Override
public Set entrySet() {
if (entrySet == null) {
entrySet = new AbstractSet() {
@Override
public Iterator iterator() {
return getHashIterator(ENTRIES);
}
@Override
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry) o;
Object key = entry.getKey();
Entry[] tab = table;
int hash = (key == null ? 0 : System.identityHashCode(key));
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index]; e != null; e = e.next) if (e.hash == hash && e.equals(entry))
return true;
return false;
}
@Override
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry entry = (Map.Entry) o;
Object key = entry.getKey();
Entry[] tab = table;
int hash = (key == null ? 0 : System.identityHashCode(key));
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
if (e.hash == hash && e.equals(entry)) {
modCount++;
if (prev != null)
prev.next = e.next;
else
tab[index] = e.next;
count--;
e.value = null;
return true;
}
}
return false;
}
@Override
public int size() {
return count;
}
@Override
public void clear() {
IdentityHashMap.this.clear();
}
};
}
return entrySet;
}
use of java.util.AbstractSet in project Purus-Pasta by puruscor.
the class CacheMap method entrySet.
public Set<Entry<K, V>> entrySet() {
if (entries == null)
entries = new AbstractSet<Entry<K, V>>() {
public int size() {
clean();
return (back.size());
}
public Iterator<Entry<K, V>> iterator() {
clean();
final Iterator<Entry<K, Reference<V>>> iter = back.entrySet().iterator();
return (new Iterator<Entry<K, V>>() {
private K nk;
private V nv;
public boolean hasNext() {
while (true) {
if (nv != null)
return (true);
if (!iter.hasNext())
return (false);
Entry<K, Reference<V>> e = iter.next();
K k = e.getKey();
V v = e.getValue().get();
if (v != null) {
nk = k;
nv = v;
return (true);
}
}
}
public Entry<K, V> next() {
if (!hasNext())
throw (new NoSuchElementException());
Entry<K, V> ret = new IteredEntry(nk, nv);
nk = null;
nv = null;
return (ret);
}
public void remove() {
iter.remove();
}
});
}
public void clear() {
back.clear();
}
};
return (entries);
}
use of java.util.AbstractSet in project atlas by alibaba.
the class PatchMethodTool method modifyMethod.
public static void modifyMethod(String srcDexFile, String outDexFile, boolean isAndFix) throws IOException {
DexFile dexFile = DexFileFactory.loadDexFile(srcDexFile, Opcodes.getDefault());
final Set<ClassDef> classes = Sets.newConcurrentHashSet();
for (ClassDef classDef : dexFile.getClasses()) {
Set<Method> methods = Sets.newConcurrentHashSet();
boolean modifiedMethod = false;
for (Method method : classDef.getMethods()) {
MethodImplementation implementation = method.getImplementation();
if (implementation != null && (methodNeedsModification(classDef, method, isAndFix))) {
modifiedMethod = true;
methods.add(new ImmutableMethod(method.getDefiningClass(), method.getName(), method.getParameters(), method.getReturnType(), method.getAccessFlags(), method.getAnnotations(), isAndFix ? modifyMethodAndFix(implementation, method) : modifyMethodTpatch(implementation, method)));
} else {
methods.add(method);
}
}
if (!modifiedMethod) {
classes.add(classDef);
} else {
classes.add(new ImmutableClassDef(classDef.getType(), classDef.getAccessFlags(), classDef.getSuperclass(), classDef.getInterfaces(), classDef.getSourceFile(), classDef.getAnnotations(), classDef.getFields(), methods));
}
}
DexFileFactory.writeDexFile(outDexFile, new DexFile() {
@Nonnull
@Override
public Set<? extends ClassDef> getClasses() {
return new AbstractSet<ClassDef>() {
@Nonnull
@Override
public Iterator<ClassDef> iterator() {
return classes.iterator();
}
@Override
public int size() {
return classes.size();
}
};
}
@Nonnull
@Override
public Opcodes getOpcodes() {
return Opcodes.getDefault();
}
});
}
Aggregations