Example usage for java.util IdentityHashMap get

List of usage examples for java.util IdentityHashMap get

Introduction

In this page you can find the example usage for java.util IdentityHashMap get.

Prototype

@SuppressWarnings("unchecked")
public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java

/**
 * Helper method that clones an item/*from  www.j  av  a2 s  .com*/
 *
 * @param item the item to clone
 * @return a clone of item.
 */
public static Map<String, AttributeValue> cloneItem(Map<String, AttributeValue> item) {
    if (item == null) {
        return null;
    }
    Map<String, AttributeValue> clonedItem = Maps.newHashMap();
    IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap = new IdentityHashMap<>();

    for (Entry<String, AttributeValue> entry : item.entrySet()) {
        if (!sourceDestinationMap.containsKey(entry.getValue())) {
            sourceDestinationMap.put(entry.getValue(), clone(entry.getValue(), sourceDestinationMap));
        }
        clonedItem.put(entry.getKey(), sourceDestinationMap.get(entry.getValue()));
    }
    return clonedItem;
}

From source file:eu.eexcess.sourceselection.redde.indexer.topterm.TopTermToWNDomain.java

/**
 * Aligns terms word net domains.//from w w w  .j a  va 2s  .  co  m
 * 
 * @param terms
 *            array of terms to align (must be != null)
 * @throws Exception
 */

ValueTreeNode<String> assignToDomains(String[] terms) throws Exception {
    this.topTerms = terms;
    WordnetDomainsDetector wdt = new WordnetDomainsDetector(wordnetDomainDetectorFile, wordnetDomainsPath,
            true);
    inflateDomainTree();

    // construct a domain map containing terms
    IdentityHashMap<String, HashSet<String>> domainToTerms = new IdentityHashMap<String, HashSet<String>>();
    for (String term : terms) {
        Set<Domain> domains = wdt.detect(term);
        // if domains were detected
        if (domains.size() > 0) {
            String domainName = domains.iterator().next().getName();
            HashSet<String> domainTerms = domainToTerms.get(domainName);
            // if domain is not seen so far
            if (domainTerms == null) {
                domainTerms = new HashSet<String>();
                domainTerms.add(term);
                domainToTerms.put(domainName, domainTerms);
            } else {
                domainTerms.add(term);
            }
        }

        // mount the terms on the domain tree
        for (Map.Entry<String, HashSet<String>> entry : domainToTerms.entrySet()) {
            String domainName = entry.getKey();
            Set<TreeNode<String>> resultCollector = new HashSet<TreeNode<String>>();
            ValueTreeNode.findFirstNode(domainName, wnDomainTree, resultCollector);

            // find domain in tree
            if (resultCollector.iterator().hasNext()) {
                TreeNode<String> nodeInTree = resultCollector.iterator().next();
                Set<String> domainTerms = entry.getValue();

                ((ValueTreeNode<String>) nodeInTree).addValues(domainTerms);
            }
        }
    }
    return wnDomainTree;
}

From source file:net.datenwerke.sandbox.SandboxLoader.java

private SandboxLoader initSubLoader(IdentityHashMap<SandboxContext, SandboxLoader> loaderMap,
        SandboxContext context) {/* www  .java2 s. c  o  m*/
    if (loaderMap.containsKey(context))
        return loaderMap.get(context);

    SandboxLoader subLoader = new SandboxLoader(this, securityManager);
    subLoader.init(context);

    loaderMap.put(context, subLoader);

    return subLoader;
}

From source file:ome.services.util.ServiceHandler.java

/**
 * public for testing purposes./*  w w w.  j ava  2 s  .  c o m*/
 */
public String getResultsString(Object o, IdentityHashMap<Object, String> cache) {

    if (o == null) {
        return "null";
    }

    if (cache == null) {
        cache = new IdentityHashMap<Object, String>();
    } else {
        if (cache.containsKey(o)) {
            return (String) cache.get(o);
        }
    }

    if (o instanceof Collection) {
        int count = 0;
        StringBuilder sb = new StringBuilder(128);
        sb.append("(");
        Collection c = (Collection) o;
        for (Object obj : (c)) {
            if (count > 0) {
                sb.append(", ");
            }
            if (count > 2) {
                sb.append("... ");
                sb.append(c.size() - 3);
                sb.append(" more");
                break;
            }
            sb.append(obj);
            count++;
        }
        sb.append(")");
        return sb.toString();
    } else if (o instanceof Map) {
        Map map = (Map) o;
        int count = 0;
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        for (Object k : map.keySet()) {
            if (count > 0) {
                sb.append(", ");
            }
            if (count > 2) {
                sb.append("... ");
                sb.append(map.size() - 3);
                sb.append(" more");
                break;
            }
            sb.append(k);
            sb.append("=");
            cache.put(o, o.getClass().getName() + ":" + System.identityHashCode(o));
            sb.append(getResultsString(map.get(k), cache));
            count++;
        }
        sb.append("}");
        return sb.toString();
    } else if (o.getClass().isArray()) {
        int length = Array.getLength(o);
        if (length == 0) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder(128);
        sb.append("[");
        for (int i = 0; i < length; i++) {

            if (i != 0) {
                sb.append(", ");
            }

            if (i > 2) {
                sb.append("... ");
                sb.append(i - 2);
                sb.append(" more");
                break;
            }
            sb.append(Array.get(o, i));
        }
        sb.append("]");
        return sb.toString();
    } else {
        return o.toString();
    }
}

From source file:com.google.gerrit.server.project.SectionSortCache.java

void sort(String ref, List<AccessSection> sections) {
    final int cnt = sections.size();
    if (cnt <= 1) {
        return;// ww  w . jav a  2 s  . c o  m
    }

    EntryKey key = new EntryKey(ref, sections);
    EntryVal val = cache.get(key);
    if (val != null) {
        int[] srcIdx = val.order;
        if (srcIdx != null) {
            AccessSection[] srcList = copy(sections);
            for (int i = 0; i < cnt; i++) {
                sections.set(i, srcList[srcIdx[i]]);
            }
        } else {
            // Identity transform. No sorting is required.
        }

    } else {
        IdentityHashMap<AccessSection, Integer> srcMap = new IdentityHashMap<AccessSection, Integer>();
        for (int i = 0; i < cnt; i++) {
            srcMap.put(sections.get(i), i);
        }

        Collections.sort(sections, new MostSpecificComparator(ref));

        int srcIdx[];
        if (isIdentityTransform(sections, srcMap)) {
            srcIdx = null;
        } else {
            srcIdx = new int[cnt];
            for (int i = 0; i < cnt; i++) {
                srcIdx[i] = srcMap.get(sections.get(i));
            }
        }

        cache.put(key, new EntryVal(srcIdx));
    }
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testAddWatch() {
    IdentityHashMap m = new IdentityHashMap();
    m.put("watch", "watch");
    assertEquals(m.get("watch"), "watch");
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testGet() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    assertNull(hashMap.get(KEY_TEST_GET));
    hashMap.put(KEY_TEST_GET, VALUE_TEST_GET);
    assertNotNull(hashMap.get(KEY_TEST_GET));

    assertNull(hashMap.get(null));/*from ww w. ja  v  a2s. c  o m*/
    hashMap.put(null, VALUE_TEST_GET);
    assertNotNull(hashMap.get(null));

    hashMap.put(null, null);
    assertNull(hashMap.get(null));
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

/**
 * Test that the implementation differs from a standard map in demanding
 * identity.//from  ww  w .j a v a  2  s.  co  m
 */
public void testIdentity() {
    IdentityHashMap hashMap = new IdentityHashMap();
    checkEmptyHashMapAssumptions(hashMap);

    Foo foo1 = new Foo();
    assertNull(hashMap.get(foo1));
    hashMap.put(foo1, VALUE_1);
    assertNotNull(hashMap.get(foo1));
    assertSame(VALUE_1, hashMap.get(foo1));

    Foo foo2 = new Foo();
    assertNull(hashMap.get(foo2));
}

From source file:sf.net.experimaestro.manager.plans.Operator.java

/**
 * Recursion through the structure//  w  w w  .j  a  v a  2 s.  co  m
 *
 * @see #getTaskOperatorMap(sf.net.experimaestro.manager.experiments.Experiment)
 * @param experiment
 * @param map The current map
 * @param descendant The current descendant
 */
private void getTaskOperatorMap(Experiment experiment, IdentityHashMap<TaskOperator, TaskReference> map,
        TaskReference descendant) {
    if (this instanceof TaskOperator) {
        TaskOperator task = (TaskOperator) this;
        TaskReference reference = map.get(task);

        if (descendant != null) {
            descendant.addParent(reference);
        }

        if (reference != null) {
            // If we already were in the map, no need to go higher
            return;
        }

        reference = new TaskReference(experiment, task.getPlan().getFactory().getId());
        map.put(task, reference);
        descendant = reference;
    }

    for (Operator parent : getParents()) {
        parent.getTaskOperatorMap(experiment, map, descendant);
    }
}

From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java

public void testKeysConflict() {
    IdentityHashMap hashMap = new IdentityHashMap();

    hashMap.put(STRING_ZERO_KEY, STRING_ZERO_VALUE);
    hashMap.put(INTEGER_ZERO_KEY, INTEGER_ZERO_VALUE);
    hashMap.put(ODD_ZERO_KEY, ODD_ZERO_VALUE);
    assertEquals(hashMap.get(INTEGER_ZERO_KEY), INTEGER_ZERO_VALUE);
    assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE);
    assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE);
    hashMap.remove(INTEGER_ZERO_KEY);//from  w  ww. jav a2 s.c o  m
    assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE);
    assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE);
    assertEquals(hashMap.get(INTEGER_ZERO_KEY), null);
    hashMap.remove(ODD_ZERO_KEY);
    assertEquals(hashMap.get(INTEGER_ZERO_KEY), null);
    assertEquals(hashMap.get(ODD_ZERO_KEY), null);
    assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE);
    hashMap.remove(STRING_ZERO_KEY);
    assertEquals(hashMap.get(INTEGER_ZERO_KEY), null);
    assertEquals(hashMap.get(ODD_ZERO_KEY), null);
    assertEquals(hashMap.get(STRING_ZERO_KEY), null);
    assertEquals(hashMap.size(), 0);
}