Search in sources :

Example 6 with AbstractSet

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();
                }
            };
        }
    });
}
Also used : MutableMethodImplementation(org.jf.dexlib2.builder.MutableMethodImplementation) MethodImplementation(org.jf.dexlib2.iface.MethodImplementation) ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod) AbstractSet(java.util.AbstractSet) Set(java.util.Set) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) Nonnull(javax.annotation.Nonnull) ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod) Method(org.jf.dexlib2.iface.Method) DexFile(org.jf.dexlib2.iface.DexFile) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) ImmutableClassDef(org.jf.dexlib2.immutable.ImmutableClassDef) ClassDef(org.jf.dexlib2.iface.ClassDef) Iterator(java.util.Iterator)

Example 7 with AbstractSet

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));
}
Also used : AbstractSet(java.util.AbstractSet)

Example 8 with AbstractSet

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);
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) AbstractSet(java.util.AbstractSet) Vector(java.util.Vector)

Example 9 with AbstractSet

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());
                }
            };
        }
    };
}
Also used : AbstractSet(java.util.AbstractSet) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) IOException(java.io.IOException) SoftReference(java.lang.ref.SoftReference) Iterator(java.util.Iterator) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

AbstractSet (java.util.AbstractSet)9 Iterator (java.util.Iterator)5 NoSuchElementException (java.util.NoSuchElementException)2 Entry (hudson.scm.ChangeLogSet.Entry)1 AdaptedIterator (hudson.util.AdaptedIterator)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 SoftReference (java.lang.ref.SoftReference)1 OverlappingFileLockException (java.nio.channels.OverlappingFileLockException)1 AbstractMap (java.util.AbstractMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Vector (java.util.Vector)1 Nonnull (javax.annotation.Nonnull)1 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)1 MutableMethodImplementation (org.jf.dexlib2.builder.MutableMethodImplementation)1