Search in sources :

Example 51 with LinkedHashMap

use of java.util.LinkedHashMap in project j2objc by google.

the class LinkedHashMapTest method test_putAllLjava_util_Map.

/**
     * java.util.LinkedHashMap#putAll(java.util.Map)
     */
public void test_putAllLjava_util_Map() {
    // Test for method void java.util.LinkedHashMap.putAll(java.util.Map)
    LinkedHashMap hm2 = new LinkedHashMap();
    hm2.putAll(hm);
    for (int i = 0; i < 1000; i++) assertTrue("Failed to clear all elements", hm2.get(new Integer(i).toString()).equals((new Integer(i))));
}
Also used : LinkedHashMap(java.util.LinkedHashMap)

Example 52 with LinkedHashMap

use of java.util.LinkedHashMap in project j2objc by google.

the class LinkedHashMapTest method test_containsKeyLjava_lang_Object.

/**
     * java.util.LinkedHashMap#containsKey(java.lang.Object)
     */
public void test_containsKeyLjava_lang_Object() {
    // Test for method boolean
    // java.util.LinkedHashMap.containsKey(java.lang.Object)
    assertTrue("Returned false for valid key", hm.containsKey(new Integer(876).toString()));
    assertTrue("Returned true for invalid key", !hm.containsKey("KKDKDKD"));
    LinkedHashMap m = new LinkedHashMap();
    m.put(null, "test");
    assertTrue("Failed with null key", m.containsKey(null));
    assertTrue("Failed with missing key matching null hash", !m.containsKey(new Integer(0)));
}
Also used : LinkedHashMap(java.util.LinkedHashMap)

Example 53 with LinkedHashMap

use of java.util.LinkedHashMap in project j2objc by google.

the class LinkedHashMapTest method test_ordered_keySet.

/**
     * java.util.LinkedHashMap#keySet()
     */
public void test_ordered_keySet() {
    int i;
    int sz = 100;
    LinkedHashMap lhm = new LinkedHashMap();
    for (i = 0; i < sz; i++) {
        Integer ii = new Integer(i);
        lhm.put(ii, ii.toString());
    }
    Set s1 = lhm.keySet();
    Iterator it1 = s1.iterator();
    assertTrue("Returned set of incorrect size", lhm.size() == s1.size());
    for (i = 0; it1.hasNext(); i++) {
        Integer jj = (Integer) it1.next();
        assertTrue("Returned incorrect entry set", jj.intValue() == i);
    }
    LinkedHashMap lruhm = new LinkedHashMap(200, .75f, true);
    for (i = 0; i < sz; i++) {
        Integer ii = new Integer(i);
        lruhm.put(ii, ii.toString());
    }
    Set s3 = lruhm.keySet();
    Iterator it3 = s3.iterator();
    assertTrue("Returned set of incorrect size", lruhm.size() == s3.size());
    for (i = 0; i < sz && it3.hasNext(); i++) {
        Integer jj = (Integer) it3.next();
        assertTrue("Returned incorrect entry set", jj.intValue() == i);
    }
    /* fetch the even numbered entries to affect traversal order */
    int p = 0;
    for (i = 0; i < sz; i += 2) {
        String ii = (String) lruhm.get(new Integer(i));
        p = p + Integer.parseInt(ii);
    }
    assertEquals("invalid sum of even numbers", 2450, p);
    Set s2 = lruhm.keySet();
    Iterator it2 = s2.iterator();
    assertTrue("Returned set of incorrect size", lruhm.size() == s2.size());
    for (i = 1; i < sz && it2.hasNext(); i += 2) {
        Integer jj = (Integer) it2.next();
        assertTrue("Returned incorrect entry set", jj.intValue() == i);
    }
    for (i = 0; i < sz && it2.hasNext(); i += 2) {
        Integer jj = (Integer) it2.next();
        assertTrue("Returned incorrect entry set", jj.intValue() == i);
    }
    assertTrue("Entries left to iterate on", !it2.hasNext());
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with LinkedHashMap

use of java.util.LinkedHashMap in project binnavi by google.

the class ReilTranslator method translate.

/**
   * Translates a disassembled function to REIL code.
   * 
   * @param environment The translation environment for the translation process
   * @param function The disassembled function
   * 
   * @return The function translated to REIL code
   * 
   * @throws InternalTranslationException Thrown if an internal error occurs
   */
public ReilFunction translate(final ITranslationEnvironment environment, final IBlockContainer<InstructionType> function, final List<ITranslationExtension<InstructionType>> extensions) throws InternalTranslationException {
    final LinkedHashMap<ICodeContainer<InstructionType>, List<ReilInstruction>> instructionMap = new LinkedHashMap<ICodeContainer<InstructionType>, List<ReilInstruction>>();
    final Map<IInstruction, ReilInstruction> firstMap = new HashMap<IInstruction, ReilInstruction>();
    final Map<IInstruction, ReilInstruction> lastMap = new HashMap<IInstruction, ReilInstruction>();
    final List<List<ReilInstruction>> delayedTrueBranches = new ArrayList<List<ReilInstruction>>();
    for (final ICodeContainer<InstructionType> block : function.getBasicBlocks()) {
        final Iterable<InstructionType> blockInstructions = block.getInstructions();
        final IInstruction lastBlockInstruction = Iterables.getLast(blockInstructions);
        final boolean endsWithInlining = isInlineSource(block);
        final ArrayList<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
        instructionMap.put(block, instructions);
        for (final InstructionType instruction : blockInstructions) {
            environment.nextInstruction();
            final ITranslator<InstructionType> translator = m_translators.get(instruction.getArchitecture().toUpperCase());
            if (translator == null) {
                throw new InternalTranslationException("Could not translate instruction from unknown architecture " + instruction.getArchitecture());
            }
            try {
                final List<ReilInstruction> result = translator.translate(environment, instruction, extensions);
                instructions.addAll(result);
                if (endsWithInlining && (instruction == lastBlockInstruction)) {
                    // We skip the last JCC instruction of blocks that were split by inlining. In 99%
                    // of all cases this should be the inlined call; unless the user removed the
                    // call from the block.
                    final ReilInstruction lastInstruction = instructions.get(instructions.size() - 1);
                    if (lastInstruction.getMnemonic().equals(ReilHelpers.OPCODE_JCC) && lastInstruction.getMetaData().containsKey("isCall")) {
                        instructions.remove(instructions.size() - 1);
                        result.remove(result.size() - 1);
                    }
                }
                firstMap.put(instruction, getFirstInstruction(result));
                lastMap.put(instruction, getLastInstruction(result));
            } catch (final InternalTranslationException exception) {
                exception.setInstruction(instruction);
                throw exception;
            }
        }
        // In this step we have to consider delayed branches of the form
        //
        // BRANCH CONDITION, SOMEWHERE
        // EXECUTE ALWAYS
        //
        // We basically re-order the instructions to
        //
        // EVALUATE CONDITION -> TEMP
        // EXECUTE ALWAYS
        // BRANCH TEMP, SOMEWHERE
        final IInstruction secondLastInstruction = Iterables.size(block.getInstructions()) > 2 ? Iterables.get(block.getInstructions(), Iterables.size(block.getInstructions()) - 2, null) : null;
        if (secondLastInstruction != null) {
            final List<ReilInstruction> secondLastReil = getReilInstructions(secondLastInstruction, instructions);
            if (ReilHelpers.isDelayedBranch(secondLastReil.get(secondLastReil.size() - 1))) {
                final IInstruction lastInstruction = getLastInstruction(block);
                final List<ReilInstruction> lastReil = getReilInstructions(lastInstruction, instructions);
                if (secondLastReil.get(secondLastReil.size() - 1).getMnemonic().equals(ReilHelpers.OPCODE_JCC)) {
                    instructions.removeAll(lastReil);
                    instructions.addAll(instructions.size() - 1, lastReil);
                }
            } else if (ReilHelpers.isDelayedTrueBranch(secondLastReil.get(secondLastReil.size() - 1))) {
                final IInstruction lastInstruction = getLastInstruction(block);
                final List<ReilInstruction> lastReil = getReilInstructions(lastInstruction, instructions);
                delayedTrueBranches.add(lastReil);
            }
        }
    }
    // In this step we determine all jump targets of the input graph.
    // We need them later because not all original jump targets can be
    // found in the translated REIL graph. The reason for this is that
    // source instructions of edges in the input graph do not necessarily
    // have a reference to the address of the edge target. This happens
    // for example when removing the first instruction from a code node.
    // The edge still goes to the code node, but the jump instruction now
    // refers to the removed instruction.
    final Collection<IAddress> nativeJumpTargets = getBlockAddresses(function);
    final Pair<List<ReilBlock>, List<ReilEdge>> pair = ReilGraphGenerator.createGraphElements(instructionMap.values(), nativeJumpTargets);
    final List<ReilBlock> nodes = pair.first();
    final List<ReilEdge> edges = pair.second();
    // In a post-processing step all edges which could not be determined
    // from the REIL instructions alone are inserted into the graph.
    insertNativeEdges(function.getBasicBlockEdges(), nodes, edges, firstMap, lastMap);
    handleDelayedTrueBranches(nodes, edges, delayedTrueBranches);
    return new ReilFunction("REIL - " + function.getName(), new ReilGraph(nodes, edges));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IInstruction(com.google.security.zynamics.zylib.disassembly.IInstruction) ICodeContainer(com.google.security.zynamics.zylib.disassembly.ICodeContainer) ArrayList(java.util.ArrayList) List(java.util.List) ReilGraph(com.google.security.zynamics.reil.ReilGraph) ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) ReilEdge(com.google.security.zynamics.reil.ReilEdge) ReilBlock(com.google.security.zynamics.reil.ReilBlock) ReilFunction(com.google.security.zynamics.reil.ReilFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 55 with LinkedHashMap

use of java.util.LinkedHashMap in project j2objc by google.

the class AbstractMapTest method test_removeLjava_lang_Object.

/**
     * java.util.AbstractMap#remove(java.lang.Object)
     */
public void test_removeLjava_lang_Object() {
    Object key = new Object();
    Object value = new Object();
    AbstractMap map1 = new HashMap(0);
    map1.put("key", value);
    assertSame("HashMap(0)", map1.remove("key"), value);
    AbstractMap map4 = new IdentityHashMap(1);
    map4.put(key, value);
    assertSame("IdentityHashMap", map4.remove(key), value);
    AbstractMap map5 = new LinkedHashMap(122);
    map5.put(key, value);
    assertSame("LinkedHashMap", map5.remove(key), value);
    AbstractMap map6 = new TreeMap(new Comparator() {

        // Bogus comparator
        public int compare(Object object1, Object object2) {
            return 0;
        }
    });
    map6.put(key, value);
    assertSame("TreeMap", map6.remove(key), value);
    AbstractMap map7 = new WeakHashMap();
    map7.put(key, value);
    assertSame("WeakHashMap", map7.remove(key), value);
    AbstractMap aSpecialMap = new MyMap();
    aSpecialMap.put(specialKey, specialValue);
    Object valueOut = aSpecialMap.remove(specialKey);
    assertSame("MyMap", valueOut, specialValue);
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator) WeakHashMap(java.util.WeakHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2398 Map (java.util.Map)691 ArrayList (java.util.ArrayList)675 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)298 IOException (java.io.IOException)152 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64