Java Code Examples for java.util.IdentityHashMap#get()

The following examples show how to use java.util.IdentityHashMap#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmaliClassDetailLoader.java    From PATDroid with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an apk file and extract all classes, methods, fields and optionally instructions
 */
public void loadAll(Scope scope) {
    IdentityHashMap<MethodInfo, MethodImplementation> collector = new IdentityHashMap<MethodInfo, MethodImplementation>();
    for (DexFile dexFile: dexFiles) {
        for (final ClassDef classDef : dexFile.getClasses()) {
            ClassInfo ci = Dalvik.findOrCreateClass(scope, classDef.getType());
            ClassDetail detail = translateClassDef(ci, classDef, collector);
            setDetail(ci, detail);
        }
    }
    if (translateInstructions) {
        for (MethodInfo mi: collector.keySet()) {
            final MethodImplementation impl = collector.get(mi);
            // Decode instructions
            if (impl != null) {
                new MethodImplementationTranslator(scope).translate(mi, impl);
            }
        }
    }
}
 
Example 2
Source File: WindupConfiguration.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns all of the {@link ConfigurationOption} in the specified {@link Addon}.
 */
public static Iterable<ConfigurationOption> getWindupConfigurationOptions(Addon addon)
{
    IdentityHashMap<ClassLoader, Addon> classLoaderToAddon = new IdentityHashMap<>();
    for (Addon loadedAddon : FurnaceHolder.getAddonRegistry().getAddons())
    {
        classLoaderToAddon.put(loadedAddon.getClassLoader(), loadedAddon);
    }

    List<ConfigurationOption> results = new ArrayList<>();
    Imported<ConfigurationOption> options = FurnaceHolder.getAddonRegistry()
                .getServices(ConfigurationOption.class);
    for (ConfigurationOption option : options)
    {
        ClassLoader optionClassLoader = option.getClass().getClassLoader();
        Addon optionAddon = classLoaderToAddon.get(optionClassLoader);
        if (optionAddon.equals(addon))
        {
            results.add(option);
        }
    }
    return results;
}
 
Example 3
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> void addAfterInstanceEdges(DirectedGraph graph,
                                              List<ComponentVertex<T>> vertices,
                                              IdentityHashMap<T, Dependencies<T>> dependencies) {
    IdentityHashMap<T, Vertex> componentToVertex = getComponentToVertex(vertices);
    for (ComponentVertex<T> vertex : vertices) {
        for (T after : dependencies.get(vertex.component).after.instances) {
            Vertex afterVertex = componentToVertex.get(after);
            if (afterVertex != null) {
                graph.addEdge(afterVertex, vertex);
            }
        }
    }
}
 
Example 4
Source File: GridToStringBuilder.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that object is already saved.
 * In positive case this method inserts hash to the saved object entry (if needed) and name@hash for current entry.
 * Further toString operations are not needed for current object.
 *
 * @param buf String builder buffer.
 * @param obj Object.
 * @param cls Class.
 * @param svdObjs Map with saved objects to handle recursion.
 * @return {@code True} if object is already saved and name@hash was added to buffer.
 * {@code False} if it wasn't saved previously and it should be saved.
 */
private static boolean handleRecursion(
    SBLimitedLength buf,
    Object obj,
    @NotNull Class cls,
    IdentityHashMap<Object, EntryReference> svdObjs
) {
    EntryReference ref = svdObjs.get(obj);

    if (ref == null)
        return false;

    int pos = ref.pos;

    String name = cls.getSimpleName();
    String hash = identity(obj);
    String savedName = name + hash;
    String charsAtPos = buf.impl().substring(pos, pos + savedName.length());

    if (!buf.isOverflowed() && !savedName.equals(charsAtPos)) {
        if (charsAtPos.startsWith(cls.getSimpleName())) {
            buf.i(pos + name.length(), hash);

            incValues(svdObjs, obj, hash.length());
        }
        else
            ref.hashNeeded = true;
    }

    buf.a(savedName);

    return true;
}
 
Example 5
Source File: BinaryObjectExImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ctx Reader context.
 * @param handles Handles for already traversed objects.
 * @return {@code true} if has circular reference.
 */
private boolean hasCircularReferences(BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
    BinaryType meta;

    try {
        meta = rawType();
    }
    catch (BinaryObjectException ignore) {
        meta = null;
    }

    if (meta == null)
        return false;

    int idHash = System.identityHashCode(this);

    handles.put(this, idHash);

    if (meta.fieldNames() != null) {
        ctx.put(start(), this);

        for (String name : meta.fieldNames()) {
            Object val = field(ctx, name);

            if (val instanceof BinaryObjectExImpl) {
                BinaryObjectExImpl po = (BinaryObjectExImpl)val;

                Integer idHash0 = handles.get(val);

                // Check for circular reference.
                if (idHash0 != null || po.hasCircularReferences(ctx, handles))
                    return true;
            }
        }
    }

    return false;
}
 
Example 6
Source File: SpanTree.java    From vespa with Apache License 2.0 5 votes vote down vote up
private void setCorrectAnnotationReference(FieldValue value, IdentityHashMap<Annotation, Integer> originalAnnotations, List<Annotation> newAnnotations) {
    if (value == null) {
        return;
    }

    if (value.getDataType() instanceof AnnotationReferenceDataType) {
        AnnotationReference ref = (AnnotationReference) value;
        if (ref.getReference() == null) {
            return;
        }
        Integer referenceIndex = originalAnnotations.get(ref.getReference());
        if (referenceIndex == null) {
            throw new IllegalStateException("Cannot find Annotation pointed to by " + ref);
        }
        try {
            Annotation newReference = newAnnotations.get(referenceIndex);
            ref.setReference(newReference);
        } catch (IndexOutOfBoundsException ioobe) {
            throw new IllegalStateException("Cannot find Annotation pointed to by " + ref, ioobe);
        }
    } else if (value.getDataType() instanceof StructuredDataType) {
        setCorrectAnnotationReference((StructuredFieldValue) value, originalAnnotations, newAnnotations);
    } else if (value.getDataType() instanceof CollectionDataType) {
        setCorrectAnnotationReference((CollectionFieldValue) value, originalAnnotations, newAnnotations);
    } else if (value.getDataType() instanceof MapDataType) {
        setCorrectAnnotationReference((MapFieldValue) value, originalAnnotations, newAnnotations);
    }
}
 
Example 7
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> Map<String, Set<Vertex>> getProvidedNames(List<ComponentVertex<T>> vertices,
                                                             IdentityHashMap<T, Dependencies<T>> dependencies) {
    Map<String, Set<Vertex>> result = new HashMap<>();
    for (ComponentVertex<T> vertex : vertices) {
        for (String providedName : dependencies.get(vertex.component).provided) {
            getIdentitySet(result, providedName).add(vertex);
        }
        addClassName(result, vertex);
    }
    return result;
}
 
Example 8
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> void addAfterProvidedEdges(DirectedGraph graph,
                                              List<ComponentVertex<T>> vertices,
                                              IdentityHashMap<T, Dependencies<T>> dependencies) {
    Map<String, Set<Vertex>> providedNames = getProvidedNames(vertices, dependencies);
    for (ComponentVertex<T> vertex : vertices) {
        for (String name : dependencies.get(vertex.component).after.providedNames) {
            for (Vertex afterVertex : emptyIfNull(providedNames.get(name))) {
                graph.addEdge(afterVertex, vertex);
            }
        }
    }
}
 
Example 9
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> void addBeforeProvidedEdges(DirectedGraph graph,
                                               List<ComponentVertex<T>> vertices,
                                               IdentityHashMap<T, Dependencies<T>> dependencies) {
    Map<String, Set<Vertex>> providedNames = getProvidedNames(vertices, dependencies);
    for (ComponentVertex<T> vertex : vertices) {
        for (String name : dependencies.get(vertex.component).before.providedNames) {
            for (Vertex beforeVertex : emptyIfNull(providedNames.get(name))) {
                graph.addEdge(vertex, beforeVertex);
            }
        }
    }
}
 
Example 10
Source File: JavaBeanSerializeUtil.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
    if (cache.containsKey(obj)) {
        return cache.get(obj);
    } else if (obj instanceof JavaBeanDescriptor) {
        return (JavaBeanDescriptor) obj;
    } else {
        JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
        cache.put(obj, result);
        serializeInternal(result, obj, accessor, cache);
        return result;
    }
}
 
Example 11
Source File: CityGMLImportManager.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
protected void delegateToADEImporter(AbstractGML object, long objectId, AbstractObjectType<?> objectType) throws CityGMLImportException, SQLException {
	// delegate import of ADE object to an ADE importer
	if (object instanceof ADEModelObject) {
		ADEModelObject adeObject = (ADEModelObject)object;

		ForeignKeys foreignKeys = (ForeignKeys)object.getLocalProperty(CoreConstants.FOREIGN_KEYS_SET);
		if (foreignKeys == null)
			foreignKeys = ForeignKeys.EMPTY_SET;

		getADEImportManager(adeObject).importObject(adeObject, objectId, objectType, foreignKeys);
	}

	// if the object is a CityGML feature or an ADE feature derived from a CityGML feature
	// then check for generic ADE properties and delegate their import to an ADE importer
	if (object instanceof AbstractFeature && object instanceof CityGMLModuleComponent) {
		AbstractFeature feature = (AbstractFeature)object;

		List<ADEModelObject> properties = propertyCollector.getADEProperties(feature);
		if (properties != null && !properties.isEmpty()) {
			IdentityHashMap<ADEImportManager, ADEPropertyCollection> groupedBy = new IdentityHashMap<>();
			for (ADEModelObject property : properties) {
				ADEImportManager adeImporter = getADEImportManager(property);
				ADEPropertyCollection collection = groupedBy.get(adeImporter);
				if (collection == null) {
					collection = new ADEPropertyCollection();
					groupedBy.put(adeImporter, collection);
				}

				collection.register(property);
			}

			for (Entry<ADEImportManager, ADEPropertyCollection> entry : groupedBy.entrySet())
				entry.getKey().importGenericApplicationProperties(entry.getValue(), feature, objectId, (FeatureType)objectType);
		}
	}
}
 
Example 12
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> void addAfterClassEdges(DirectedGraph graph,
                                           List<ComponentVertex<T>> vertices,
                                           IdentityHashMap<T, Dependencies<T>> dependencies) {
    for (ComponentVertex<T> vertex : vertices) {
        for (Class<? extends T> afterClass : dependencies.get(vertex.component).after.classes) {
            for (Vertex afterVertex : componentsWithClass(vertices, afterClass)) {
                graph.addEdge(afterVertex, vertex);
            }
        }
    }
}
 
Example 13
Source File: ChainBuilder.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static <T> void addBeforeClassEdges(DirectedGraph graph,
                                            List<ComponentVertex<T>> vertices,
                                            IdentityHashMap<T, Dependencies<T>> dependencies) {
    for (ComponentVertex<T> vertex : vertices) {
        for (Class<? extends T> beforeClass : dependencies.get(vertex.component).before.classes) {
            for (Vertex beforeVertex : componentsWithClass(vertices, beforeClass)) {
                graph.addEdge(vertex, beforeVertex);
            }
        }
    }
}
 
Example 14
Source File: JavaBeanSerializeUtil.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
    if (cache.containsKey(obj)) {
        return cache.get(obj);
    } else if (obj instanceof JavaBeanDescriptor) {
        return (JavaBeanDescriptor)obj;
    } else {
        JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
        cache.put(obj, result);
        serializeInternal(result, obj, accessor, cache);
        return result;
    }
}
 
Example 15
Source File: JavaBeanSerializeUtil.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
    if (cache.containsKey(obj)) {
        return cache.get(obj);
    } else if (obj instanceof JavaBeanDescriptor) {
        return (JavaBeanDescriptor) obj;
    } else {
        JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
        cache.put(obj, result);
        serializeInternal(result, obj, accessor, cache);
        return result;
    }
}
 
Example 16
Source File: JavaBeanSerializeUtil.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
    if (cache.containsKey(obj)) {
        return cache.get(obj);
    } else if (obj instanceof JavaBeanDescriptor) {
        return (JavaBeanDescriptor)obj;
    } else {
        JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
        cache.put(obj, result);
        serializeInternal(result, obj, accessor, cache);
        return result;
    }
}
 
Example 17
Source File: JavaBeanSerializeUtil.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
    if (cache.containsKey(obj)) {
        return cache.get(obj);
    } else if (obj instanceof JavaBeanDescriptor) {
        return (JavaBeanDescriptor)obj;
    } else {
        JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
        cache.put(obj, result);
        serializeInternal(result, obj, accessor, cache);
        return result;
    }
}
 
Example 18
Source File: Models.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e) {
    //System.err.println("Models.ActionSupport.actionPerformed("+e+")");
    Node[] ns = getActiveNodes(e);
    int i, k = ns.length;
    IdentityHashMap<Action, ArrayList<Object>> h = new IdentityHashMap<Action, ArrayList<Object>>();
    for (i = 0; i < k; i++) {
        Object node = ns[i].getLookup().lookup(Object.class);
        Action[] as = ns [i].getActions (false);
        int j, jj = as.length;
        for (j = 0; j < jj; j++) {
            if (equals (as [j])) {
                ArrayList<Object> l = h.get (as [j]);
                if (l == null) {
                    l = new ArrayList<Object>();
                    h.put (as [j], l);
                }
                l.add (node);
            }
        }
    }
    //System.err.println("  k = "+k);
    if (k == 0) {
        if (multiselectionType != MULTISELECTION_TYPE_EXACTLY_ONE) {
            performer.perform(new Object[]{});
        }
    } else {
        //System.err.println("  h = "+h);
        Iterator<Action> it = h.keySet ().iterator ();
        while (it.hasNext ()) {
            ActionSupport a = (ActionSupport) it.next ();
            //System.err.println("  "+a.performer+".perform("+((ArrayList) h.get (a)));
            a.performer.perform (
                ((ArrayList) h.get (a)).toArray ()
            );
        }
    }
}
 
Example 19
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that can clone an Attribute Value
 *
 * @param val the AttributeValue to copy
 * @param sourceDestinationMap used to avoid loops by keeping track of references
 * @return a copy of val
 */
public static AttributeValue clone(final AttributeValue val, final IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) {
    if (val == null) {
        return null;
    }

    if (sourceDestinationMap.containsKey(val)) {
        return sourceDestinationMap.get(val);
    }

    final AttributeValue clonedVal = new AttributeValue();
    sourceDestinationMap.put(val, clonedVal);
    if (val.getN() != null) {
        clonedVal.setN(val.getN());
    } else if (val.getS() != null) {
        clonedVal.setS(val.getS());
    } else if (val.getB() != null) {
        clonedVal.setB(val.getB());
    } else if (val.getNS() != null) {
        clonedVal.setNS(val.getNS());
    } else if (val.getSS() != null) {
        clonedVal.setSS(val.getSS());
    } else if (val.getBS() != null) {
        clonedVal.setBS(val.getBS());
    } else if (val.getBOOL() != null) {
        clonedVal.setBOOL(val.getBOOL());
    } else if (val.getNULL() != null) {
        clonedVal.setNULL(val.getNULL());
    } else if (val.getL() != null) {
        final List<AttributeValue> list = new ArrayList<>(val.getL().size());
        for (AttributeValue listItemValue : val.getL()) {
            if (!sourceDestinationMap.containsKey(listItemValue)) {
                sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap));
            }
            list.add(sourceDestinationMap.get(listItemValue));
        }
        clonedVal.setL(list);
    } else if (val.getM() != null) {
        final Map<String, AttributeValue> map = new HashMap<>(val.getM().size());
        for (Entry<String, AttributeValue> pair : val.getM().entrySet()) {
            if (!sourceDestinationMap.containsKey(pair.getValue())) {
                sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap));
            }
            map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue()));
        }
        clonedVal.setM(map);
    }
    return clonedVal;
}
 
Example 20
Source File: UnsafeOperations.java    From jadira with Apache License 2.0 4 votes vote down vote up
/**
 * Performs a deep copy of the array. With a deep copy all references from the array are also copied.
 * The identity of referenced objects is preserved, so, for example, if the object graph contains two 
 * references to the same object, the cloned object will preserve this structure.
 * @param arrayOriginal The array to perform a deep copy for.
 * @param visited An identity map of references to reuse - this is further populated as the copy progresses.
 * The key is the original object reference - the value is the copied instance for that original.
 * @return A deep copy of the original array.
 */
public final Object deepCopyArray(Object arrayOriginal, IdentityHashMap<Object, Object> visited) {

	if (visited.containsKey(arrayOriginal)) {
		return visited.get(arrayOriginal);
	}

	final Class<?> componentType = arrayOriginal.getClass().getComponentType();

	Object result = null;

	if (componentType.isPrimitive()) {

		if (java.lang.Boolean.TYPE == componentType) {
			result = Arrays.copyOf((boolean[]) arrayOriginal, ((boolean[]) arrayOriginal).length);
		} else if (java.lang.Byte.TYPE == componentType) {
			result = Arrays.copyOf((byte[]) arrayOriginal, ((byte[]) arrayOriginal).length);
		} else if (java.lang.Character.TYPE == componentType) {
			result = Arrays.copyOf((char[]) arrayOriginal, ((char[]) arrayOriginal).length);
		} else if (java.lang.Short.TYPE == componentType) {
			result = Arrays.copyOf((short[]) arrayOriginal, ((short[]) arrayOriginal).length);
		} else if (java.lang.Integer.TYPE == componentType) {
			result = Arrays.copyOf((int[]) arrayOriginal, ((int[]) arrayOriginal).length);
		} else if (java.lang.Long.TYPE == componentType) {
			result = Arrays.copyOf((long[]) arrayOriginal, ((long[]) arrayOriginal).length);
		} else if (java.lang.Float.TYPE == componentType) {
			result = Arrays.copyOf((float[]) arrayOriginal, ((float[]) arrayOriginal).length);
		} else if (java.lang.Double.TYPE == componentType) {
			result = Arrays.copyOf((double[]) arrayOriginal, ((double[]) arrayOriginal).length);
		}
	}

	if (result == null) {
		Object[] arrayCopy = Arrays.copyOf((Object[]) arrayOriginal, ((Object[]) arrayOriginal).length);
		if (arrayCopy.length > 0) {

			if (componentType.isArray()) {
				for (int i = 0; i < arrayCopy.length; i++) {
					arrayCopy[i] = deepCopyArray(arrayCopy[i], visited);
				}
			} else {
				for (int i = 0; i < arrayCopy.length; i++) {
					Object component = deepCopy(arrayCopy[i], visited);
					arrayCopy[i] = component;
				}
			}
		}
		result = arrayCopy;
	}

	visited.put(arrayOriginal, result);
	return result;
}