Example usage for java.util IdentityHashMap put

List of usage examples for java.util IdentityHashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this identity hash map.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//  w w  w .  j a  va 2 s. co m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    Map<Object, Object> objMap1 = new IdentityHashMap<Object, Object>();

    System.out.println(objMap1.equals(objMap));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//w  ww .java  2  s .  c om
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // check if key 3 exists
    boolean isavailable = objMap.containsKey(o1);

    System.out.println(isavailable);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//  w  w w.j  a v  a  2 s . c o  m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    objMap.clear();

    System.out.println("Map content after clear: " + objMap);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);// ww w .  jav a 2 s  .  com
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // create a set view
    Set<Object> nset = objMap.keySet();

    System.out.println("Set view is: " + nset);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);/*from  www  .j  ava 2s .c  o  m*/
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // create entry set from the map
    Set<Entry<Object, Object>> enset = objMap.entrySet();

    System.out.println("Set view of the map: " + enset);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//from ww  w  .j a v  a  2  s .c o  m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // clone the map
    IdentityHashMap ihmapclone = (IdentityHashMap) objMap.clone();

    System.out.println("Cloned map content: " + ihmapclone);

}

From source file:Main.java

public static void main(String args[]) {

    IdentityHashMap<Integer, String> ihmap1 = new IdentityHashMap<Integer, String>();
    IdentityHashMap<Integer, String> ihmap2 = new IdentityHashMap<Integer, String>();

    // populate the ihmap1
    ihmap1.put(1, "from");
    ihmap1.put(2, "java2s.com");
    ihmap1.put(3, "tutorial");

    System.out.println("Value of ihmap1 before: " + ihmap1);
    System.out.println("Value of ihmap2 before: " + ihmap2);

    // put all values from ihmap1 to ihmap2
    ihmap2.putAll(ihmap1);//from w  w w .  ja  v a  2  s. co m

    System.out.println("Value of ihmap2 after: " + ihmap2);
}

From source file:com.netflix.config.util.ConfigurationUtils.java

/**
 * Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance
 * and thread safety. //from   w  w  w.  j a  va 2  s  .  com
 * 
 * @param config Configuration to be converted
 */
public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(
        CombinedConfiguration config) {
    ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration();
    IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>();
    for (String name : (Set<String>) config.getConfigurationNames()) {
        Configuration child = config.getConfiguration(name);
        reverseMap.put(child, name);
    }
    for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
        Configuration child = config.getConfiguration(i);
        String name = reverseMap.get(child);
        if (child instanceof CombinedConfiguration) {
            CombinedConfiguration combinedConf = (CombinedConfiguration) child;
            ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf);
            root.addConfiguration(newConf, name);
        } else {
            Configuration conf = new ConcurrentMapConfiguration(child);
            root.addConfiguration((AbstractConfiguration) conf, name);
        }
    }
    return root;
}

From source file:org.openspotlight.bundle.language.java.bundle.JavaBinaryProcessor.java

private static Map<TypeDefinition, JavaType> createTypes(final List<TypeDefinition> types,
        final JavaGraphNodeSupport helper) throws Exception {
    final IdentityHashMap<TypeDefinition, JavaType> map = new IdentityHashMap<TypeDefinition, JavaType>();
    for (final TypeDefinition definition : types) {
        if (!definition.isPrivate()) {
            final Class<? extends JavaType> nodeType = getNodeType(definition.getType());
            final JavaType newType = helper.addTypeOnCurrentContext(nodeType, definition.getPackageName(),
                    definition.getTypeName(), definition.getAccess());
            map.put(definition, newType);
        }//from ww w  . j a  v  a2  s  . c  om
    }
    return map;
}

From source file:com.textocat.textokit.eval.matching.CollectionFeatureMatcherBase.java

@Override
protected String toString(IdentityHashMap<Matcher<?>, Integer> idMap) {
    idMap.put(this, getNextId(idMap));
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("feature", feature)
            .append("elemMatcher", getToString(idMap, elemMatcher)).append("ignoreOrder", ignoreOrder)
            .toString();// w w  w .j a  va 2s  .  c o m
}