Example usage for java.util IdentityHashMap IdentityHashMap

List of usage examples for java.util IdentityHashMap IdentityHashMap

Introduction

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

Prototype

public IdentityHashMap() 

Source Link

Document

Constructs a new, empty identity hash map with a default expected maximum size (21).

Usage

From source file:org.apache.maven.graph.FilteredProjectDependencyGraph.java

/**
 * Creates a new project dependency graph from the specified graph.
 *
 * @param projectDependencyGraph The project dependency graph to create a sub view from, must not be {@code null}.
 * @param whiteList The projects on which the dependency view should focus, must not be {@code null}.
 *//*w w w  .j  a  v  a2s  .com*/
public FilteredProjectDependencyGraph(ProjectDependencyGraph projectDependencyGraph,
        Collection<? extends MavenProject> whiteList) {
    this.projectDependencyGraph = Validate.notNull(projectDependencyGraph,
            "projectDependencyGraph cannot be null");

    this.whiteList = new IdentityHashMap<MavenProject, Object>();

    for (MavenProject project : whiteList) {
        this.whiteList.put(project, null);
    }
}

From source file:org.drools.core.xml.jaxb.util.JaxbUnknownAdapter.java

@Override
public Object marshal(Object o) throws Exception {
    try {//from ww w  .  j av a  2  s.  co m
        return recursiveMarshal(o, new IdentityHashMap<Object, Object>());
    } catch (Exception e) {
        // because exceptions are always swallowed by JAXB
        logger.error("Unable to marshal " + o.getClass().getName() + " instance: " + e.getMessage(), e);
        throw e;
    }
}

From source file:nz.co.senanque.validationengine.Binder.java

public Map<ValidationObject, ProxyObject> bind(final ValidationObject object, final ValidationSession session,
        final ProxyField parent, final Integer index, ValidationObject owner) {
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(
            m_validationEngine.getMessageSource());
    final Map<ValidationObject, ProxyObject> ret = new IdentityHashMap<ValidationObject, ProxyObject>();
    if (object == null) {
        return ret;
    }//from  w w w.  j ava  2  s.  c om
    Class<?> clazz = object.getClass();
    final ClassMetadata classMetadata = m_validationEngine.getClassMetadata(clazz);
    if (classMetadata == null) {
        throw m_validationEngine.getLocaleAwareExceptionFactory().getRuntimeException(
                "nz.co.senanque.validationengine.class.not.recognised", new Object[] { clazz.getName() });
    }
    object.setValidationSession(session);
    final ProxyObject proxyObject = new ProxyObject(object, parent, index, session);
    ret.put(object, proxyObject);
    final ObjectMetadata objectMetadata = (ObjectMetadata) object.getMetadata();
    objectMetadata.setClassMetadata(proxyObject, classMetadata);
    Map<String, Property> propertyMap = ValidationUtils.getProperties(object.getClass());
    for (Property property : propertyMap.values()) {
        String fieldName = property.getFieldName();
        final PropertyMetadataImpl propertyMetadata = (PropertyMetadataImpl) classMetadata.getField(fieldName);
        if (propertyMetadata == null) {
            continue;
        }
        final ProxyFieldImpl proxyField = new ProxyFieldImpl(fieldName, proxyObject, parent, propertyMetadata,
                messageSourceAccessor);
        proxyObject.put(fieldName, proxyField);
        Method method = property.getGetter();
        if (property.getGetter().getReturnType().isAssignableFrom(List.class)) {
            try {
                @SuppressWarnings("unchecked")
                final List<ValidationObject> validationObjects = (List<ValidationObject>) method.invoke(object,
                        new Object[] {});
                final ListeningArray<Object> array = new ListeningArray<Object>();
                array.addAll(validationObjects);
                array.setValidationSession(session);
                array.setProxyField(proxyField);
                final Method setterMethod = property.getSetter();
                setterMethod.invoke(object, array);
                int index1 = 0;
                for (ValidationObject child : validationObjects) {
                    ret.putAll(bind(child, session, proxyField, index1++, owner));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            continue;
        }
        if (m_validationEngine.getClassMetadata(method.getReturnType()) != null) {
            try {
                final ValidationObject child = (ValidationObject) method.invoke(object, new Object[] {});
                ret.putAll(bind(child, session, proxyField, null, owner));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            continue;
        }
        try {
            Method getter = ValidationUtils.figureGetter(fieldName, clazz);
            if (getter.isAnnotationPresent(Ignore.class)) {
                continue;
            }
            java.lang.reflect.Field propertyField = getField(clazz, fieldName);
            Object value = ConvertUtils.convertToObject(propertyField.getType());
            proxyField.setInitialValue(value);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return ret;
}

From source file:org.micromanager.plugins.magellan.propsandcovariants.CovariantPairing.java

public CovariantPairing(Covariant independent, Covariant dependent) {
    independent_ = independent;//w w w .j  a  va2 s  . co m
    dependent_ = dependent;
    excludedAcqs_ = new IdentityHashMap<Acquisition, Object>();
}

From source file:org.kalypso.ui.editor.styleeditor.graphic.GraphicElementsTabList.java

@Override
public void refresh() {
    final Map<Object, IGraphicElementItem> oldItems = new IdentityHashMap<>();
    final ITabItem[] items = getItems();
    for (final ITabItem item : items)
        oldItems.put(((IGraphicElementItem) item).getElement(), (IGraphicElementItem) item);

    internalClear();/* w ww . ja  v a  2  s. co  m*/

    final Graphic graphic = getData();
    final Object[] elements = graphic == null ? ArrayUtils.EMPTY_OBJECT_ARRAY
            : graphic.getMarksAndExtGraphics();
    for (final Object element : elements) {
        if (oldItems.containsKey(element))
            internalAddItem(oldItems.get(element));
        else {
            final IGraphicElementItem newItem = createItem(element);
            internalAddItem(newItem);
        }
    }

    fireChanged();
}

From source file:org.logicblaze.lingo.cache.impl.ThreadCache.java

public String toString() {
    Map map = (clear) ? new IdentityHashMap() : new IdentityHashMap(backingCache);
    for (Iterator iter = localRemoves.keySet().iterator(); iter.hasNext();) {
        map.remove(iter.next());/* w  w w. j av  a2s  .c om*/
    }
    for (Iterator iter = localChanges.entrySet().iterator(); iter.hasNext();) {
        Entry entry = (Entry) iter.next();
        Object key = entry.getKey();
        VersionedValue change = (VersionedValue) entry.getValue();
        map.put(key, change.getValue());
    }
    return map.toString();
}

From source file:com.flipkart.flux.client.runtime.LocalContext.java

/**
 * Creates a new, local StateMachineDefinition instance
 * @return/*from w ww . j  av a  2 s  . c  om*/
 * @param workflowIdentifier
 * @param version
 * @param description
 */
public void registerNew(String workflowIdentifier, long version, String description, String correlationId) {
    if (this.stateMachineDefinition.get() != null) {
        /* This ensures we don't compose workflows within workflows */
        throw new IllegalStateException("A single thread cannot execute more than one workflow");
    }
    stateMachineDefinition.set(new StateMachineDefinition(description, workflowIdentifier, version,
            new HashSet<>(), new HashSet<>(), correlationId));
    tlUniqueEventCount.set(new MutableInt(0));
    this.eventNames.set(new IdentityHashMap<>());
}

From source file:org.unitils.mock.report.impl.ObservedInvocationsReport.java

/**
 * Creates a string representation of the given invocations as described in the class javadoc.
 *
 * @param observedInvocations The invocations for which to create a report, not null
 * @param testObject          The test instance
 * @return The string representation, not null
 *//*w ww.  j ava2s.  c  om*/
public String createReport(List<ObservedInvocation> observedInvocations, Object testObject) {
    Map<Object, String> largeObjectNames = new IdentityHashMap<Object, String>();
    Map<Class<?>, Integer> largeObjectNameIndexes = new HashMap<Class<?>, Integer>();
    Map<Object, String> fieldValuesAndNames = getFieldValuesAndNames(testObject);

    return formatObservedInvocations(observedInvocations, largeObjectNames, largeObjectNameIndexes,
            fieldValuesAndNames);
}

From source file:org.blockartistry.DynSurround.registry.BlockRegistry.java

@Override
public void init() {
    this.registry = new HashMap<BlockInfo, BlockProfile>();
    this.cache = new IdentityHashMap<IBlockState, BlockProfile>();
}

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;/*from  w  w  w  .j av a2s. 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));
    }
}