List of usage examples for java.util IdentityHashMap IdentityHashMap
public IdentityHashMap()
From source file:org.openmrs.module.patientflags.PatientFlagsModuleActivator.java
/** * @see org.openmrs.module.Activator#startup() *//* w ww . j a va 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:mondrian.util.UtilCompatibleJdk16.java
@Override public <T> Set<T> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<T, Boolean>()); }
From source file:net.big_oh.common.web.WebUtil.java
/** * /* www . j a va 2 s . c om*/ * Calculate an <b>approximation</b> of the memory consumed by the objects * stored under each attribute of a user's {@link HttpSession}. The estimate * will often be greater than the actual value because of "double counting" * objects that appear multiple times in the attribute value's object graph. * * @param session * An HttpSession object from any web application. * @return An <b>approximation</b> of the memory consumed for each attribute * <b>name</b> in the session. */ public static Map<String, Integer> getSessionAttributeNameToApproxSizeInBytesMap(HttpSession session) { // Use an IdentityHashMap because we don't want to miss distinct objects // that are equivalent according to equals(..) method. Map<String, Integer> sessionAttributeNameToApproxSizeInBytesMap = new IdentityHashMap<String, Integer>(); Enumeration<?> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { String attributeName = (String) enumeration.nextElement(); session.getAttribute(attributeName); try { sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(approximateObjectSize(attributeName))); } catch (IOException ioe) { logger.error("Failed to approximate size of session attribute name: " + attributeName.getClass().getName(), ioe); sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(0)); } } return sessionAttributeNameToApproxSizeInBytesMap; }
From source file:com.salas.bb.utils.concurrency.CachingCalculator.java
/** * Create map to use to store keys and values. * By default the map is <code>IdentityHashMap</code>. * * @return map./*from ww w. j a v a 2 s. c o m*/ */ protected Map<Object, Holder> createKeyToValueMap() { return new IdentityHashMap<Object, Holder>(); }
From source file:com.hack23.cia.service.data.impl.util.LoadHelper.java
/** * Recursive initliaze./* w w w . j a va 2 s . c o m*/ * * @param <T> * the generic type * @param obj * the obj * @return the t */ public static <T> T recursiveInitialize(final T obj) { if (obj != null) { final Set<Object> dejaVu = Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>()); try { recursiveInitialize(obj, dejaVu); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { handleReflectionException(e); } } return obj; }
From source file:pcgen.cdom.helper.BridgeListener.java
private ImmutablePair<Set<Object>, Set<Object>> processIdentityDeltas(Object[] oldValue, Object[] newValue) { Set<Object> toAdd = Collections.newSetFromMap(new IdentityHashMap<>()); Collections.addAll(toAdd, newValue); Set<Object> toRemove = Collections.newSetFromMap(new IdentityHashMap<>()); Collections.addAll(toRemove, oldValue); if ((oldValue.length != 0) && (newValue.length != 0)) { //Note order sensitivity toRemove.removeAll(toAdd);//from w ww . jav a 2s.c o m Collections.addAll(toAdd, oldValue); } return new ImmutablePair<>(toRemove, toAdd); }
From source file:eu.eexcess.sourceselection.redde.indexer.topterm.TopTermToWNDomain.java
/** * Aligns terms word net domains.//from www . ja va 2 s . co m * * @param terms * array of terms to align (must be != null) * @throws Exception */ ValueTreeNode<String> assignToDomains(String[] terms) throws Exception { this.topTerms = terms; WordnetDomainsDetector wdt = new WordnetDomainsDetector(wordnetDomainDetectorFile, wordnetDomainsPath, true); inflateDomainTree(); // construct a domain map containing terms IdentityHashMap<String, HashSet<String>> domainToTerms = new IdentityHashMap<String, HashSet<String>>(); for (String term : terms) { Set<Domain> domains = wdt.detect(term); // if domains were detected if (domains.size() > 0) { String domainName = domains.iterator().next().getName(); HashSet<String> domainTerms = domainToTerms.get(domainName); // if domain is not seen so far if (domainTerms == null) { domainTerms = new HashSet<String>(); domainTerms.add(term); domainToTerms.put(domainName, domainTerms); } else { domainTerms.add(term); } } // mount the terms on the domain tree for (Map.Entry<String, HashSet<String>> entry : domainToTerms.entrySet()) { String domainName = entry.getKey(); Set<TreeNode<String>> resultCollector = new HashSet<TreeNode<String>>(); ValueTreeNode.findFirstNode(domainName, wnDomainTree, resultCollector); // find domain in tree if (resultCollector.iterator().hasNext()) { TreeNode<String> nodeInTree = resultCollector.iterator().next(); Set<String> domainTerms = entry.getValue(); ((ValueTreeNode<String>) nodeInTree).addValues(domainTerms); } } } return wnDomainTree; }
From source file:org.apache.hadoop.security.authorize.ServiceAuthorizationManager.java
public static synchronized void refresh(Configuration conf, PolicyProvider provider) { // Get the system property 'hadoop.policy.file' String policyFile = System.getProperty("hadoop.policy.file", HADOOP_POLICY_FILE); // Make a copy of the original config, and load the policy file Configuration policyConf = new Configuration(conf); policyConf.addResource(policyFile);/*from www . j a v a 2s . c o m*/ final Map<Class<?>, AccessControlList> newAcls = new IdentityHashMap<Class<?>, AccessControlList>(); // Parse the config file Service[] services = provider.getServices(); if (services != null) { for (Service service : services) { AccessControlList acl = new AccessControlList( policyConf.get(service.getServiceKey(), AccessControlList.WILDCARD_ACL_VALUE)); newAcls.put(service.getProtocol(), acl); } } // Flip to the newly parsed permissions protocolToAcl = newAcls; }
From source file:org.lilyproject.process.test.DecoratorTest.java
@Test public void test() throws Exception { LilyProxy lilyProxy = createLilyProxy(); LilyClient client = lilyProxy.getLilyServerProxy().getClient(); RepositoryModelImpl repositoryModel = new RepositoryModelImpl( lilyProxy.getLilyServerProxy().getZooKeeper()); repositoryModel.create("repo1"); assertTrue(repositoryModel.waitUntilRepositoryInState("repo1", RepositoryLifecycleState.ACTIVE, 60000L)); repositoryModel.create("repo2"); assertTrue(repositoryModel.waitUntilRepositoryInState("repo2", RepositoryLifecycleState.ACTIVE, 60000L)); repositoryModel.close();/* w w w . j a v a 2 s . c o m*/ // Make a schema TypeManager typeMgr = client.getDefaultRepository().getTypeManager(); QName field1 = new QName("ns", "f1"); FieldType fieldType1 = typeMgr.newFieldType(typeMgr.getValueType("STRING"), field1, Scope.NON_VERSIONED); fieldType1 = typeMgr.createFieldType(fieldType1); QName field2 = new QName("ns", "f2"); FieldType fieldType2 = typeMgr.newFieldType(typeMgr.getValueType("STRING"), field2, Scope.NON_VERSIONED); fieldType2 = typeMgr.createFieldType(fieldType2); QName typeName = new QName("ns", "rt1"); RecordType recordType = typeMgr.newRecordType(typeName); recordType.addFieldTypeEntry(fieldType1.getId(), false); recordType.addFieldTypeEntry(fieldType2.getId(), false); recordType = typeMgr.createRecordType(recordType); DecoratingRepositoryManager repositoryMgr = (DecoratingRepositoryManager) lilyProxy.getLilyServerProxy() .getLilyServerTestingUtility().getRuntime().getModuleById("repository").getApplicationContext() .getBean("repositoryManager"); IdentityHashMap<Object, Object> chains = new IdentityHashMap<Object, Object>(); // Test the decorator is applied for each repository and each table for (String repositoryName : new String[] { "default", "repo1", "repo2" }) { LRepository repository = client.getRepository(repositoryName); repository.getTableManager().createTable("table1"); repository.getTableManager().createTable("table2"); for (String tableName : new String[] { "record", "table1", "table2" }) { LTable table = repository.getTable(tableName); Record record = table.newRecord(); record.setRecordType(typeName); record.setField(field1, "foobar"); record = table.create(record); assertEquals("foo", record.getField(field2)); assertEquals("foo", table.read(record.getId()).getField(field2)); // Test we can get access to our test decorator: this is something that is occasionally useful // in test cases to check certain conditions, e.g. if the decorator would have async side effects. RepositoryDecoratorChain chain = repositoryMgr.getRepositoryDecoratorChain(repositoryName, tableName); assertNotNull(chain); assertNotNull(chain.getDecorator(TestRepositoryDecoratorFactory.NAME)); chains.put(chain.getDecorator(TestRepositoryDecoratorFactory.NAME), null); assertEquals(2, chain.getEntries().size()); } } // There should be one instance of the decorator created for each repository-table combination (that // was accessed) assertEquals(3 * 3, chains.size()); // Check that if we ask the same table twice, we get the same instance (verifies cache works) assertTrue(client.getRepository("repo1").getTable("table1") == client.getRepository("repo1") .getTable("table1")); lilyProxy.stop(); // Check each of the decorators was properly closed assertEquals(9, TestRepositoryDecoratorFactory.CLOSE_COUNT.get()); }
From source file:com.espertech.esper.view.stream.StreamFactorySvcImpl.java
/** * Ctor.//from ww w .ja v a 2 s .c om * @param isReuseViews indicator on whether stream and view resources are to be reused between statements */ public StreamFactorySvcImpl(String engineURI, boolean isReuseViews) { this.engineURI = engineURI; this.eventStreamsRefCounted = new RefCountedMap<FilterSpecCompiled, Pair<EventStream, EPStatementHandleCallback>>(); this.eventStreamsIdentity = new IdentityHashMap<Object, Pair<EventStream, EPStatementHandleCallback>>(); this.isReuseViews = isReuseViews; }