Search in sources :

Example 11 with IdentityHashMap

use of java.util.IdentityHashMap in project rest.li by linkedin.

the class TemplateSpecGenerator method generateRecord.

private RecordTemplateSpec generateRecord(RecordDataSchema schema) {
    final RecordTemplateSpec recordClass = new RecordTemplateSpec(schema);
    recordClass.setNamespace(schema.getNamespace());
    recordClass.setPackage(schema.getPackage());
    recordClass.setClassName(schema.getName());
    recordClass.setModifiers(ModifierSpec.PUBLIC);
    registerClassTemplateSpec(schema, recordClass);
    // processSchema included schemas first, so that unnamed classes will belong to the defining class
    // instead of the current class
    final List<NamedDataSchema> includes = schema.getInclude();
    for (NamedDataSchema includedSchema : includes) {
        processSchema(includedSchema, null, null);
    }
    final Map<CustomInfoSpec, Object> customInfoMap = new IdentityHashMap<CustomInfoSpec, Object>(schema.getFields().size() * 2);
    for (RecordDataSchema.Field field : schema.getFields()) {
        final ClassTemplateSpec fieldClass = processSchema(field.getType(), recordClass, field.getName());
        final RecordTemplateSpec.Field newField = new RecordTemplateSpec.Field();
        newField.setSchemaField(field);
        newField.setType(fieldClass);
        newField.setDataClass(determineDataClass(field.getType(), recordClass, field.getName()));
        final CustomInfoSpec customInfo = getImmediateCustomInfo(field.getType());
        if (customInfo != null) {
            if (!customInfoMap.containsKey(customInfo)) {
                customInfoMap.put(customInfo, null);
            }
            newField.setCustomInfo(customInfo);
        }
        recordClass.addField(newField);
    }
    return recordClass;
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) CustomInfoSpec(com.linkedin.pegasus.generator.spec.CustomInfoSpec) IdentityHashMap(java.util.IdentityHashMap) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) RecordTemplateSpec(com.linkedin.pegasus.generator.spec.RecordTemplateSpec)

Example 12 with IdentityHashMap

use of java.util.IdentityHashMap in project neo4j by neo4j.

the class CompilationFailureException method source.

private static String source(List<? extends Diagnostic<?>> diagnostics) {
    Set<JavaFileObject> sources = null;
    for (Diagnostic<?> diagnostic : diagnostics) {
        Object source = diagnostic.getSource();
        if (source instanceof JavaFileObject) {
            JavaFileObject file = (JavaFileObject) source;
            if (file.getKind() == JavaFileObject.Kind.SOURCE) {
                if (sources == null) {
                    sources = Collections.newSetFromMap(new IdentityHashMap<JavaFileObject, Boolean>());
                }
                sources.add(file);
            }
        }
    }
    if (sources == null) {
        return "";
    }
    StringBuilder result = new StringBuilder();
    for (JavaFileObject source : sources) {
        int pos = result.length();
        result.append("\nSource file ").append(source.getName()).append(":\n");
        try {
            CharSequence content = source.getCharContent(true);
            result.append(String.format("%4d: ", 1));
            for (int line = 1, i = 0; i < content.length(); i++) {
                char c = content.charAt(i);
                result.append(c);
                if (c == '\n') {
                    result.append(String.format("%4d: ", ++line));
                }
            }
        } catch (IOException e) {
            result.setLength(pos);
        }
    }
    return result.toString();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) IdentityHashMap(java.util.IdentityHashMap) JavaFileObject(javax.tools.JavaFileObject) IOException(java.io.IOException)

Example 13 with IdentityHashMap

use of java.util.IdentityHashMap in project netty by netty.

the class DefaultChannelPipeline method childExecutor.

private EventExecutor childExecutor(EventExecutorGroup group) {
    if (group == null) {
        return null;
    }
    Boolean pinEventExecutor = channel.config().getOption(ChannelOption.SINGLE_EVENTEXECUTOR_PER_GROUP);
    if (pinEventExecutor != null && !pinEventExecutor) {
        return group.next();
    }
    Map<EventExecutorGroup, EventExecutor> childExecutors = this.childExecutors;
    if (childExecutors == null) {
        // Use size of 4 as most people only use one extra EventExecutor.
        childExecutors = this.childExecutors = new IdentityHashMap<EventExecutorGroup, EventExecutor>(4);
    }
    // Pin one of the child executors once and remember it so that the same child executor
    // is used to fire events for the same channel.
    EventExecutor childExecutor = childExecutors.get(group);
    if (childExecutor == null) {
        childExecutor = group.next();
        childExecutors.put(group, childExecutor);
    }
    return childExecutor;
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) EventExecutor(io.netty.util.concurrent.EventExecutor) IdentityHashMap(java.util.IdentityHashMap)

Example 14 with IdentityHashMap

use of java.util.IdentityHashMap in project robovm by robovm.

the class AbstractMapTest method test_values.

/**
     * java.util.AbstractMap#values()
     */
public void test_values() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.values(), map1.values());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.values(), map2.values());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.values(), map3.values());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.values(), map4.values());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("IdentityHashMap", map5.values(), map5.values());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.values(), map6.values());
    AbstractMap map7 = new WeakHashMap();
    assertSame("WeakHashMap", map7.values(), map7.values());
}
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) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) LinkedHashMap(java.util.LinkedHashMap) WeakHashMap(java.util.WeakHashMap)

Example 15 with IdentityHashMap

use of java.util.IdentityHashMap in project robovm by robovm.

the class IdentityHashMapTest method test_Constructor.

/**
     * java.util.IdentityHashMap#IdentityHashMap()
     */
public void test_Constructor() {
    // Test for method java.util.IdentityHashMap()
    new Support_MapTest2(new IdentityHashMap()).runTest();
    IdentityHashMap hm2 = new IdentityHashMap();
    assertEquals("Created incorrect IdentityHashMap", 0, hm2.size());
}
Also used : IdentityHashMap(java.util.IdentityHashMap) Support_MapTest2(tests.support.Support_MapTest2)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)131 Map (java.util.Map)43 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)19 LinkedHashMap (java.util.LinkedHashMap)17 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 Entry (java.util.Map.Entry)5