List of usage examples for java.util IdentityHashMap IdentityHashMap
public IdentityHashMap()
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testAddEqualKeys() { final IdentityHashMap expected = new IdentityHashMap(); assertEquals(expected.size(), 0);/*from www . ja v a 2 s.co m*/ iterateThrough(expected); expected.put(new Long(45), new Object()); assertEquals(expected.size(), 1); iterateThrough(expected); expected.put(new Integer(45), new Object()); assertNotSame(new Integer(45), new Long(45)); assertEquals(expected.size(), 2); iterateThrough(expected); }
From source file:ca.uhn.fhir.rest.method.TransactionMethodBinding.java
@SuppressWarnings("unchecked") @Override//from ww w .ja va 2s. co 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:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testAddWatch() { IdentityHashMap m = new IdentityHashMap(); m.put("watch", "watch"); assertEquals(m.get("watch"), "watch"); }
From source file:org.kuali.rice.krad.service.impl.DictionaryValidationServiceImpl.java
/** * creates a new IdentitySet.//from w w w .j a va 2 s. co m * * @return a new Set */ protected final Set<Object> newIdentitySet() { return java.util.Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>()); }
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/* w w w . ja v a 2 s . c o m*/ 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.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testClear() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); hashMap.put("Hello", "Bye"); assertFalse(hashMap.isEmpty());// w w w .j ava 2 s . c o m assertTrue(hashMap.size() == SIZE_ONE); hashMap.clear(); assertTrue(hashMap.isEmpty()); assertTrue(hashMap.size() == 0); }
From source file:net.sf.jasperreports.extensions.DefaultExtensionsRegistry.java
protected List<ExtensionsRegistry> loadRegistries() { //there is no identity linked hash map/set, using separate map and list IdentityHashMap<ExtensionsRegistry, Object> registrySet = new IdentityHashMap<>(); List<ExtensionsRegistry> allRegistries = new ArrayList<ExtensionsRegistry>(); List<ClassLoaderResource> extensionResources = loadExtensionPropertyResources(); for (ClassLoaderResource extensionResource : extensionResources) { ClassLoader classLoader = extensionResource.getClassLoader(); Map<URL, URLRegistries> classLoaderRegistries = getClassLoaderRegistries(classLoader); URL url = extensionResource.getUrl(); List<ExtensionsRegistry> registries; Map<String, Exception> registryExceptions = new LinkedHashMap<String, Exception>(); synchronized (classLoaderRegistries) { URLRegistries urlRegistries = classLoaderRegistries.get(url); if (urlRegistries == null) { if (log.isDebugEnabled()) { log.debug("Loading JasperReports extension properties resource " + url); }/*from w ww . ja v a2 s. c o m*/ JRPropertiesMap properties = JRPropertiesMap.loadProperties(url); URL duplicateURL = detectDuplicate(properties, classLoaderRegistries);//search across classloaders? if (duplicateURL == null) { registries = loadRegistries(properties, registryExceptions); } else { log.warn("Extension resource " + url + " was found to be a duplicate of " + duplicateURL + " in classloader " + classLoader); registries = Collections.emptyList(); } classLoaderRegistries.put(url, new URLRegistries(properties, registries)); } else { registries = urlRegistries.registries; } } for (Map.Entry<String, Exception> entry : registryExceptions.entrySet()) { log.error("Error instantiating extensions registry for " + entry.getKey() + " from " + url, entry.getValue()); } for (ExtensionsRegistry extensionsRegistry : registries) { //detecting identity duplicates boolean added = registrySet.put(extensionsRegistry, Boolean.FALSE) == null; if (added) { allRegistries.add(extensionsRegistry); } else if (log.isDebugEnabled()) { log.debug("Found duplicate extension registry " + extensionsRegistry); } } } return allRegistries; }
From source file:ca.uhn.fhir.util.FhirTerser.java
/** * Returns a list containing all child elements (including the resource itself) which are <b>non-empty</b> and are either of the exact type specified, or are a subclass of that type. * <p>//w w w .j a va 2s .c o m * For example, specifying a type of {@link StringDt} would return all non-empty string instances within the message. Specifying a type of {@link IResource} would return the resource itself, as * well as any contained resources. * </p> * <p> * Note on scope: This method will descend into any contained resources ({@link IResource#getContained()}) as well, but will not descend into linked resources (e.g. * {@link BaseResourceReferenceDt#getResource()}) or embedded resources (e.g. Bundle.entry.resource) * </p> * * @param theResource * The resource instance to search. Must not be null. * @param theType * The type to search for. Must not be null. * @return Returns a list of all matching elements */ public <T extends IBase> List<T> getAllPopulatedChildElementsOfType(IBaseResource theResource, final Class<T> theType) { final ArrayList<T> retVal = new ArrayList<T>(); BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource); visit(new IdentityHashMap<Object, Object>(), theResource, theResource, null, null, def, new IModelVisitor() { @SuppressWarnings("unchecked") @Override public void acceptElement(IBaseResource theOuterResource, IBase theElement, List<String> thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition<?> theDefinition) { if (theElement == null || theElement.isEmpty()) { return; } if (theType.isAssignableFrom(theElement.getClass())) { retVal.add((T) theElement); } } }); return retVal; }
From source file:org.datacleaner.windows.ResultWindow.java
/** * * @param configuration//w ww . ja va 2 s. c o m * @param job * either this or result must be available * @param result * either this or job must be available * @param jobFilename * @param windowContext * @param userPreferences * @param rendererFactory */ @Inject protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job, @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext, UserPreferences userPreferences, RendererFactory rendererFactory) { super(windowContext); final boolean running = (result == null); _resultPanels = new IdentityHashMap<>(); _configuration = configuration; _job = job; _jobFilename = jobFilename; _userPreferences = userPreferences; _rendererFactory = rendererFactory; final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() { @Override public AnalysisResult get() { return getResult(); } }; Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE, new EmptyBorder(10, 4, 10, 4)); _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP); _cancelButton.setHorizontalAlignment(SwingConstants.LEFT); _cancelButton.setBorder(buttonBorder); _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results", IconUtils.ACTION_SAVE_DARK); _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT); _saveResultsPopupButton.setBorder(buttonBorder); _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP); _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM)); JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK); saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences)); saveAsFileItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(saveAsFileItem); JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE); exportToHtmlItem.addActionListener( new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences)); exportToHtmlItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(exportToHtmlItem); JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server", IconUtils.MENU_DQ_MONITOR); publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(), _userPreferences, resultRef, _jobFilename)); publishToServerItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(publishToServerItem); _tabbedPane = new VerticalTabbedPane() { private static final long serialVersionUID = 1L; @Override protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) { DCPanel buttonPanel = new DCPanel(); buttonPanel.setLayout(new VerticalLayout()); buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM)); buttonPanel.add(_saveResultsPopupButton); buttonPanel.add(_cancelButton); DCPanel wrappedPanel = new DCPanel(); wrappedPanel.setLayout(new BorderLayout()); wrappedPanel.add(originalPanel, BorderLayout.CENTER); wrappedPanel.add(buttonPanel, BorderLayout.SOUTH); return super.wrapInCollapsiblePane(wrappedPanel); } }; final Dimension size = getDefaultWindowSize(); _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height); _progressInformationPanel = new ProgressInformationPanel(running); _tabbedPane.addTab("Progress information", imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB), _progressInformationPanel); for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) { JComponent component = pluggableComponent.eval(this); if (component != null) { if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon()); for (ActionListener listener : button.getActionListeners()) { menuItem.addActionListener(listener); } menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove? JMenuItem menuItem = (JMenuItem) component; menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } } } if (running) { // run the job in a swing worker _result = null; _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this); _cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { _worker.cancelIfRunning(); } }); } else { // don't add the progress information, simply render the job asap _result = result; _worker = null; final Map<ComponentJob, AnalyzerResult> map = result.getResultMap(); for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) { final ComponentJob componentJob = entry.getKey(); final AnalyzerResult analyzerResult = entry.getValue(); addResult(componentJob, analyzerResult); } _progressInformationPanel.onSuccess(); WidgetUtils.invokeSwingAction(new Runnable() { @Override public void run() { if (_tabbedPane.getTabCount() > 1) { // switch to the first available result panel _tabbedPane.setSelectedIndex(1); } } }); } updateButtonVisibility(running); }
From source file:uk.org.taverna.platform.execution.impl.local.WorkflowToDataflowMapper.java
public WorkflowToDataflowMapper(WorkflowBundle workflowBundle, Profile profile, Edits edits, ActivityService activityService, DispatchLayerService dispatchLayerService) { this.workflowBundle = workflowBundle; this.profile = profile; this.edits = edits; this.activityService = activityService; this.dispatchLayerService = dispatchLayerService; inputPorts = new IdentityHashMap<>(); outputPorts = new IdentityHashMap<>(); merges = new IdentityHashMap<>(); workflowToDataflow = new IdentityHashMap<>(); dataflowToWorkflow = new HashMap<>(); workflowToDataflowProcessors = new IdentityHashMap<>(); dataflowToWorkflowProcessors = new HashMap<>(); workflowToDataflowActivities = new IdentityHashMap<>(); dataflowToWorkflowActivities = new HashMap<>(); }