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:com.textocat.textokit.eval.matching.FSFeatureMatcher.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("valueMatcher", getToString(idMap, valueMatcher)).toString();
}

From source file:org.openmrs.module.patientflags.PatientFlagsModuleActivator.java

/**
 * @see org.openmrs.module.Activator#startup()
 *//*from w ww.  ja  v  a  2  s  .  co  m*/
public void startup() {

    // create necessary global properties if they have not been created
    if ((Context.getAdministrationService().getGlobalProperty("patientflags.patientHeaderDisplay")) == null) {
        Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(
                "patientflags.patientHeaderDisplay", "true",
                "DO NOT MODIFY HERE: use \"manage flag global properties\" to modify; true/false whether or not to display flags in the Patient Dashboard overview"));
    }

    if ((Context.getAdministrationService().getGlobalProperty("patientflags.patientOverviewDisplay")) == null) {
        Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(
                "patientflags.patientOverviewDisplay", "true",
                "DO NOT MODIFY HERE: use \"manage flag global properties\" to modify; true/false whether or not to display flags in the Patient Dashboard header"));
    }

    // if no username has been defined, as a default use the username used by the scheduler
    if ((Context.getAdministrationService().getGlobalProperty("patientflags.username")) == null) {
        Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("patientflags.username",
                Context.getAdministrationService().getGlobalProperty("scheduler.username"),
                "DO NOT MODIFY HERE: user \"manage flag global properties\" to modify; Username for the OpenMRS user that will evaluate Groovy flags"));
    }

    // configure extension points based on global properties
    Module thisModule = ModuleFactory.getModuleByPackage("org.openmrs.module.patientflags");

    IdentityHashMap<String, String> extensionPoints = new IdentityHashMap<String, String>();

    extensionPoints.put("org.openmrs.admin.list",
            "org.openmrs.module.patientflags.extension.html.FlagAdminExt");

    if ((Context.getAdministrationService().getGlobalProperty("patientflags.patientHeaderDisplay"))
            .equals("true")) {
        extensionPoints.put("org.openmrs.patientDashboard.afterLastEncounter",
                "org.openmrs.module.patientflags.extension.html.FlagPatientDashboardHeaderExt");
    }

    if ((Context.getAdministrationService().getGlobalProperty("patientflags.patientOverviewDisplay"))
            .equals("true")) {
        extensionPoints.put("org.openmrs.patientDashboard.overviewBox",
                "org.openmrs.module.patientflags.extension.html.FlagPatientOverviewExt");
    }

    // set the new names
    thisModule.setExtensionNames(extensionPoints);

    // this code is copied from  ModuleFactory.startModule();
    // unfortunately it needs to be executed twice since extensions are added to module before activator is executed 
    // (and therefore before the extensions dynamically defined here have been set)
    for (Extension ext : thisModule.getExtensions()) {

        String extId = ext.getExtensionId();
        List<Extension> tmpExtensions = ModuleFactory.getExtensions(extId);
        if (tmpExtensions == null)
            tmpExtensions = new Vector<Extension>();

        log.debug("Adding to mapping ext: " + ext.getExtensionId() + " ext.class: " + ext.getClass());

        tmpExtensions.add(ext);
        ModuleFactory.getExtensionMap().put(extId, tmpExtensions);
    }

    log.info("Starting Patient Flags Module");
}

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

public String generateEventName(Event event) {
    final IdentityHashMap<Event, String> eventNamesMap = this.eventNames.get();
    if (!eventNamesMap.containsKey(event)) {
        eventNamesMap.put(event, generateName(event));
    }//from   w ww . ja  v a2 s.  co  m
    return eventNamesMap.get(event);
}

From source file:com.google.gwt.dev.util.collect.IdentityHashSetTest.java

@SuppressWarnings("unchecked")
@Override/*from   w  w  w .  ja va  2s .  co  m*/
public Collection makeConfirmedCollection() {
    final java.util.IdentityHashMap map = new java.util.IdentityHashMap();
    return new AbstractSet() {
        @Override
        public boolean add(Object e) {
            return map.put(e, e) == null;
        }

        @Override
        public Iterator iterator() {
            return map.keySet().iterator();
        }

        @Override
        public int size() {
            return map.size();
        }
    };
}

From source file:org.apache.kylin.storage.cache.DynamicCacheTest.java

@Test
public void basicTest() {

    final StorageContext context = new StorageContext();
    final List<TblColRef> groups = StorageMockUtils.buildGroups();
    final TblColRef partitionCol = groups.get(0);
    final List<FunctionDesc> aggregations = StorageMockUtils.buildAggregations();
    final TupleInfo tupleInfo = StorageMockUtils.newTupleInfo(groups, aggregations);

    SQLDigest sqlDigest = new SQLDigest("default.test_kylin_fact", null, null, Lists.<TblColRef>newArrayList(),
            groups, Lists.newArrayList(partitionCol), Lists.<TblColRef>newArrayList(), aggregations,
            new ArrayList<MeasureDesc>(), new ArrayList<SQLDigest.OrderEnum>());

    ITuple aTuple = new TsOnlyTuple(partitionCol, "2011-02-01");
    ITuple bTuple = new TsOnlyTuple(partitionCol, "2012-02-01");
    final List<ITuple> allTuples = Lists.newArrayList(aTuple, bTuple);

    //counts for verifying
    final AtomicInteger underlyingSEHitCount = new AtomicInteger(0);
    final List<Integer> returnedRowPerSearch = Lists.newArrayList();

    CacheFledgedDynamicQuery dynamicCache = new CacheFledgedDynamicQuery(new ICachableStorageQuery() {
        @Override//ww w . ja v  a2s .c om
        public ITupleIterator search(StorageContext context, SQLDigest sqlDigest, TupleInfo returnTupleInfo) {
            Range<Long> tsRagneInQuery = TsConditionExtractor.extractTsCondition(partitionCol,
                    sqlDigest.filter);
            List<ITuple> ret = Lists.newArrayList();
            for (ITuple tuple : allTuples) {
                if (tsRagneInQuery.contains(Tuple.getTs(tuple, partitionCol))) {
                    ret.add(tuple);
                }
            }

            underlyingSEHitCount.incrementAndGet();
            returnedRowPerSearch.add(ret.size());

            return new SimpleTupleIterator(ret.iterator());
        }

        @Override
        public boolean isDynamic() {
            return true;
        }

        @Override
        public Range<Long> getVolatilePeriod() {
            return Ranges.greaterThan(DateFormat.stringToMillis("2011-02-01"));
        }

        @Override
        public String getStorageUUID() {
            return "111ca32a-a33e-4b69-12aa-0bb8b1f8c191";
        }
    }, partitionCol);

    sqlDigest.filter = StorageMockUtils.buildTs2010Filter(groups.get(0));
    ITupleIterator firstIterator = dynamicCache.search(context, sqlDigest, tupleInfo);
    IdentityHashMap<ITuple, Void> firstResults = new IdentityHashMap<>();
    while (firstIterator.hasNext()) {
        firstResults.put(firstIterator.next(), null);
    }
    firstIterator.close();

    sqlDigest.filter = StorageMockUtils.buildTs2011Filter(groups.get(0));
    ITupleIterator secondIterator = dynamicCache.search(context, sqlDigest, tupleInfo);
    IdentityHashMap<ITuple, Void> secondResults = new IdentityHashMap<>();
    while (secondIterator.hasNext()) {
        secondResults.put(secondIterator.next(), null);
    }
    secondIterator.close();

    Assert.assertEquals(2, firstResults.size());
    IdentityUtils.collectionReferenceEquals(firstResults.keySet(), secondResults.keySet());
    Assert.assertEquals(2, underlyingSEHitCount.get());
    Assert.assertEquals(new Integer(2), returnedRowPerSearch.get(0));
    Assert.assertEquals(new Integer(1), returnedRowPerSearch.get(1));
}

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

/**
 * Helper method that clones an item/*  w  ww. j  ava 2s  . c o  m*/
 *
 * @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:ca.uhn.fhir.rest.method.TransactionMethodBinding.java

@SuppressWarnings("unchecked")
@Override/*ww w .jav a 2 s .c  o  m*/
public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams)
        throws InvalidRequestException, InternalErrorException {

    /*
     * The design of HAPI's transaction method for DSTU1 support assumed that a transaction was just an update on a
     * bunch of resources (because that's what it was), but in DSTU2 transaction has become much more broad, so we
     * no longer hold the user's hand much here.
     */
    if (myTransactionParamStyle == ParamStyle.RESOURCE_BUNDLE) {
        // This is the DSTU2 style
        Object response = invokeServerMethod(theServer, theRequest, theMethodParams);
        return response;
    }

    // Grab the IDs of all of the resources in the transaction
    List<IResource> resources;
    if (theMethodParams[myTransactionParamIndex] instanceof Bundle) {
        resources = ((Bundle) theMethodParams[myTransactionParamIndex]).toListOfResources();
    } else {
        resources = (List<IResource>) theMethodParams[myTransactionParamIndex];
    }

    IdentityHashMap<IResource, IdDt> oldIds = new IdentityHashMap<IResource, IdDt>();
    for (IResource next : resources) {
        oldIds.put(next, next.getId());
    }

    // Call the server implementation method
    Object response = invokeServerMethod(theServer, theRequest, theMethodParams);
    IBundleProvider retVal = toResourceList(response);

    /*
     * int offset = 0; if (retVal.size() != resources.size()) { if (retVal.size() > 0 && retVal.getResources(0,
     * 1).get(0) instanceof OperationOutcome) { offset = 1; } else { throw new
     * InternalErrorException("Transaction bundle contained " + resources.size() +
     * " entries, but server method response contained " + retVal.size() + " entries (must be the same)"); } }
     */

    List<IBaseResource> retResources = retVal.getResources(0, retVal.size());
    for (int i = 0; i < retResources.size(); i++) {
        IdDt oldId = oldIds.get(retResources.get(i));
        IBaseResource newRes = retResources.get(i);
        if (newRes.getIdElement() == null || newRes.getIdElement().isEmpty()) {
            if (!(newRes instanceof BaseOperationOutcome)) {
                throw new InternalErrorException("Transaction method returned resource at index " + i
                        + " with no id specified - IResource#setId(IdDt)");
            }
        }

        if (oldId != null && !oldId.isEmpty()) {
            if (!oldId.equals(newRes.getIdElement()) && newRes instanceof IResource) {
                ((IResource) newRes).getResourceMetadata().put(ResourceMetadataKeyEnum.PREVIOUS_ID, oldId);
            }
        }
    }

    return retVal;
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Gets the bean size.//  ww  w. ja  v  a 2  s . c om
 *
 * @param bean the bean
 * @param clazz the clazz
 * @param m the m
 * @param classNameMatcher the class name matcher
 * @param fieldNameMatcher the field name matcher
 * @return the bean size
 */
public static int getBeanSize(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m,
        Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) {
    if (m.containsKey(bean) == true) {
        return 0;
    }
    m.put(bean, null);
    return getBeanSizeIntern(bean, clazz, m, classNameMatcher, fieldNameMatcher);
}

From source file:com.parse.ParseTraverser.java

/**
 * Internal implementation of traverse./*  ww w .  ja v a  2 s . c  o m*/
 */
private void traverseInternal(Object root, boolean yieldRoot, IdentityHashMap<Object, Object> seen) {
    if (root == null || seen.containsKey(root)) {
        return;
    }

    if (yieldRoot) {
        if (!visit(root)) {
            return;
        }
    }

    seen.put(root, root);

    if (root instanceof JSONObject) {
        JSONObject json = (JSONObject) root;
        Iterator<String> keys = json.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            try {
                traverseInternal(json.get(key), true, seen);
            } catch (JSONException e) {
                // This should never happen.
                throw new RuntimeException(e);
            }
        }

    } else if (root instanceof JSONArray) {
        JSONArray array = (JSONArray) root;
        for (int i = 0; i < array.length(); ++i) {
            try {
                traverseInternal(array.get(i), true, seen);
            } catch (JSONException e) {
                // This should never happen.
                throw new RuntimeException(e);
            }
        }

    } else if (root instanceof Map) {
        Map<?, ?> map = (Map<?, ?>) root;
        for (Object value : map.values()) {
            traverseInternal(value, true, seen);
        }

    } else if (root instanceof List) {
        List<?> list = (List<?>) root;
        for (Object value : list) {
            traverseInternal(value, true, seen);
        }

    } else if (root instanceof ParseObject) {
        if (traverseParseObjects) {
            ParseObject object = (ParseObject) root;
            for (String key : object.keySet()) {
                traverseInternal(object.get(key), true, seen);
            }
        }

    } else if (root instanceof ParseACL) {
        ParseACL acl = (ParseACL) root;
        ParseUser user = acl.getUnresolvedUser();
        if (user != null && user.isCurrentUser()) {
            traverseInternal(user, true, seen);
        }
    }
}

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  www.  j a va2  s.c  om*/
    }

    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));
    }
}