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, 15, true);
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();
}
};
}
});
}
use of java.util.AbstractSet in project robovm by robovm.
the class OldAbstractSetTest method testEquals.
public void testEquals() {
AbstractSet as1 = new Mock_AbstractSet();
AbstractSet as2 = new Mock_AbstractSet();
assertTrue(as1.equals(as2));
}
use of java.util.AbstractSet in project robovm by robovm.
the class OldAbstractSetTest method testRemoveAll.
public void testRemoveAll() {
AbstractSet as = new AbstractSet() {
@Override
public Iterator iterator() {
return new Iterator() {
public boolean hasNext() {
return true;
}
public Object next() {
return null;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
@Override
public int size() {
return 10;
}
};
try {
as.removeAll(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
//expected
}
Collection c = new Vector();
c.add(null);
try {
as.removeAll(c);
fail("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) {
//expected
}
as = new Mock_AbstractSet();
as.removeAll(c);
}
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());
}
};
}
};
}
Aggregations