List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:edu.wustl.mir.erl.ihe.xdsi.util.DICOMUtility.java
public KOSBean manufactureKOSFromUIDs(List<String> uidList, String retrieveAETitle, String retrieveLocationUID, String classUID) throws Exception { KOSBean bean = new KOSBean(null); Iterator<String> it = uidList.iterator(); HashMap<String, TreeSet<String>> studySeriesMap = new HashMap<String, TreeSet<String>>(); HashMap<String, TreeSet<String>> seriesInstanceMap = new HashMap<String, TreeSet<String>>(); while (it.hasNext()) { String composite = it.next(); String[] tokens = composite.split(":"); String studyUID = tokens[0]; String seriesUID = tokens[1]; String instanceUID = tokens[2]; if (studySeriesMap.containsKey(studyUID)) { TreeSet<String> x = studySeriesMap.get(studyUID); x.add(seriesUID);//from ww w . jav a 2 s . c om } else { TreeSet<String> x = new TreeSet<String>(); x.add(seriesUID); studySeriesMap.put(studyUID, x); } if (seriesInstanceMap.containsKey(seriesUID)) { TreeSet<String> y = seriesInstanceMap.get(seriesUID); y.add(instanceUID); } else { TreeSet<String> y = new TreeSet<String>(); y.add(instanceUID); seriesInstanceMap.put(seriesUID, y); } } Iterator<String> itStudy = studySeriesMap.keySet().iterator(); while (itStudy.hasNext()) { String studyUID = itStudy.next(); KOSStudyBean studyBean = new KOSStudyBean(studyUID, null); TreeSet<String> seriesSet = studySeriesMap.get(studyUID); Iterator<String> itSeries = seriesSet.iterator(); while (itSeries.hasNext()) { String seriesUID = itSeries.next(); KOSSeriesBean seriesBean = new KOSSeriesBean(seriesUID, retrieveAETitle, retrieveLocationUID, null); TreeSet<String> instanceSet = seriesInstanceMap.get(seriesUID); Iterator<String> itInstance = instanceSet.iterator(); while (itInstance.hasNext()) { String instanceUID = itInstance.next(); KOSInstanceBean instanceBean = new KOSInstanceBean(instanceUID, classUID); seriesBean.addInstanceBean(instanceBean); } studyBean.addSeriesBean(seriesBean); } bean.addStudyBean(studyBean); } return bean; }
From source file:edu.wustl.mir.erl.ihe.xdsi.util.DICOMUtility.java
public KOSBean manufactureKOSFromUIDs(KOSBean bean, List<String> uidList, String retrieveAETitle, String retrieveLocationUID, String classUID) throws Exception { HashMap<String, TreeSet<String>> studySeriesMap = new HashMap<String, TreeSet<String>>(); HashMap<String, TreeSet<String>> seriesInstanceMap = new HashMap<String, TreeSet<String>>(); if (bean == null) { bean = new KOSBean(null); }//from w ww. j a va2 s. c o m Iterator<String> it = uidList.iterator(); while (it.hasNext()) { String composite = it.next(); String[] tokens = composite.split(":"); String studyUID = tokens[0]; String seriesUID = tokens[1]; String instanceUID = tokens[2]; if (studySeriesMap.containsKey(studyUID)) { TreeSet<String> x = studySeriesMap.get(studyUID); x.add(seriesUID); } else { TreeSet<String> x = new TreeSet<String>(); x.add(seriesUID); studySeriesMap.put(studyUID, x); } if (seriesInstanceMap.containsKey(seriesUID)) { TreeSet<String> y = seriesInstanceMap.get(seriesUID); y.add(instanceUID); } else { TreeSet<String> y = new TreeSet<String>(); y.add(instanceUID); seriesInstanceMap.put(seriesUID, y); } } Iterator<String> itStudy = studySeriesMap.keySet().iterator(); while (itStudy.hasNext()) { String studyUID = itStudy.next(); KOSStudyBean studyBean = new KOSStudyBean(studyUID, null); TreeSet<String> seriesSet = studySeriesMap.get(studyUID); Iterator<String> itSeries = seriesSet.iterator(); while (itSeries.hasNext()) { String seriesUID = itSeries.next(); KOSSeriesBean seriesBean = new KOSSeriesBean(seriesUID, retrieveAETitle, retrieveLocationUID, null); TreeSet<String> instanceSet = seriesInstanceMap.get(seriesUID); Iterator<String> itInstance = instanceSet.iterator(); while (itInstance.hasNext()) { String instanceUID = itInstance.next(); KOSInstanceBean instanceBean = new KOSInstanceBean(instanceUID, classUID); seriesBean.addInstanceBean(instanceBean); } studyBean.addSeriesBean(seriesBean); } bean.addStudyBean(studyBean); } return bean; }
From source file:gemlite.shell.admin.dao.AdminDao.java
/** * region/*from ww w . j a va 2s . com*/ * * @return * @throws IOException */ private String showRegions() throws IOException { do { System.out.println("------------------------"); Map param = new HashMap(); param.put("beanName", "ListRegionsService"); Execution execution = FunctionService.onServer(clientPool).withArgs(param); ResultCollector rc = execution.execute("REMOTE_ADMIN_FUNCTION"); Object obj = rc.getResult(); if (obj == null) { System.out.println("can't get regions list"); return null; } ArrayList list = (ArrayList) obj; if (!(list.get(0) instanceof Set)) { System.out.println(list.get(0)); return null; } TreeSet regionSet = (TreeSet) list.get(0); Iterator regionIters = regionSet.iterator(); StringBuilder sb = new StringBuilder(); TreeMap<String, String> regionMap = new TreeMap<String, String>(); int no = 1; sb.append("NO.").append("\t").append("RegionName").append("\n"); while (regionIters.hasNext()) { String fullPath = (String) regionIters.next(); sb.append(no).append("\t").append(fullPath).append("\n"); regionMap.put(String.valueOf(no), fullPath); no++; } System.out.println(sb.toString()); System.out.println( "------------------------\nRegionNames,Your choice?No.or regionName,ALL(all) means export all regions,X to exit"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String line = bufferedReader.readLine(); if (line == null) { System.out.println("no input regionName!"); } else if (!"x".equalsIgnoreCase(line.trim()) && !regionMap.entrySet().contains(line.trim()) && !"ALL".equalsIgnoreCase(line.trim()) && !regionMap.keySet().contains(line.trim())) { System.out.println("error input:" + line); } else { if (regionMap.keySet().contains(line.trim())) return regionMap.get(String.valueOf(line.trim())); return line.trim(); } } while (true); }
From source file:org.starnub.starnubserver.pluggable.PluggableManager.java
public NavigableSet<UnloadedPluggable> pluggableScan(String directory, ConcurrentHashMap<String, Pluggable> loadedPluggables, boolean updating) { TreeSet<UnloadedPluggable> unloadedPluggables = getFiles(directory, "jar", "py"); /* Remove unloaded pluggables that are older then currently loaded*/ Iterator<UnloadedPluggable> iterator = unloadedPluggables.iterator(); while (iterator.hasNext()) { UnloadedPluggable up = iterator.next(); String upName = up.getDetails().getNAME().toLowerCase(); Pluggable p = loadedPluggables.get(upName); if (p != null) { boolean canUpdate = canUpdate(up, p, updating); if (!canUpdate) { iterator.remove();/*from w w w . j a v a 2s . c om*/ } } } return unloadedPluggables.descendingSet(); }
From source file:org.pentaho.reporting.libraries.resourceloader.factory.AbstractResourceFactory.java
/** * @param data//from w w w.j a va2s .com * @param context * @return * @throws ResourceCreationException * @throws ResourceLoadingException */ public synchronized Resource create(final ResourceManager manager, final ResourceData data, final ResourceKey context) throws ResourceCreationException, ResourceLoadingException { final TreeSet<ResourceFactoryEntry> sortedEntries = new TreeSet<ResourceFactoryEntry>(); final Iterator<FactoryModule> factoryModulesIt = factoryModules.iterator(); while (factoryModulesIt.hasNext()) { final FactoryModule mod = factoryModulesIt.next(); final int weight = mod.canHandleResource(manager, data); if (weight >= 0) { sortedEntries.add(new ResourceFactoryEntry(mod, weight)); } } final Iterator<ResourceFactoryEntry> it = sortedEntries.iterator(); while (it.hasNext()) { final ResourceFactoryEntry entry = it.next(); try { return entry.getModule().create(manager, data, context); } catch (ResourceCreationException ex) { if (ex instanceof ContentNotRecognizedException) { throw ex; } } catch (Exception ex) { // ok, that one failed, try the next one ... if (logger.isDebugEnabled()) { logger.debug("Failed to load content with module " + entry.getModule() + ":", ex); } } } throw new ContentNotRecognizedException("No valid handler for the given content."); }
From source file:com.miz.mizuu.AddNetworkFilesourceDialog.java
@SuppressLint("UseSparseArrays") public void search(View v) { final ArrayList<FileSource> sources = new ArrayList<FileSource>(); DbAdapterSources dbHelper = MizuuApplication.getSourcesAdapter(); // Fetch all movie sources and add them to the array Cursor cursor = dbHelper.fetchAllSources(); while (cursor.moveToNext()) { if (cursor.getInt(cursor.getColumnIndex(DbAdapterSources.KEY_FILESOURCE_TYPE)) == FileSource.SMB) sources.add(new FileSource(cursor.getLong(cursor.getColumnIndex(DbAdapterSources.KEY_ROWID)), cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_FILEPATH)), cursor.getInt(cursor.getColumnIndex(DbAdapterSources.KEY_FILESOURCE_TYPE)), cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_USER)), cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_PASSWORD)), cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_DOMAIN)), cursor.getString(cursor.getColumnIndex(DbAdapterSources.KEY_TYPE)))); }/* w w w. j a v a2 s . c o m*/ cursor.close(); TreeSet<String> uniqueSources = new TreeSet<String>(); int count = sources.size(); for (int i = 0; i < count; i++) { String temp = sources.get(i).getFilepath().replace("smb://", ""); temp = temp.substring(0, temp.indexOf("/")); uniqueSources.add(temp); } final CharSequence[] items = new CharSequence[uniqueSources.size() + 1]; count = 0; Iterator<String> it = uniqueSources.iterator(); while (it.hasNext()) { items[count] = it.next(); count++; } items[items.length - 1] = getString(R.string.scanForSources); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.browseSources)); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (which == (items.length - 1)) { Intent intent = new Intent(); intent.setClass(getApplicationContext(), SearchForNetworkShares.class); startActivity(intent); } else { showUserDialog(items, which); } } }); builder.show(); }
From source file:org.wso2.carbon.identity.entitlement.policy.collection.DefaultPolicyCollection.java
/** * Attempts to retrieve a policy based on the given identifier and other constraints. If there * are multiple versions of the identified policy that meet the version constraints, then the * most recent version is returned./* ww w .j ava 2s .c o m*/ * * @param identifier * @param type * @param constraints * @return */ public AbstractPolicy getPolicy(URI identifier, int type, VersionConstraints constraints) { TreeSet<AbstractPolicy> set = policies.get(identifier.toString()); // if we don't know about this identifier then there's nothing to do if (set == null) return null; // walk through the set starting with the most recent version, looking // for a match until we exhaust all known versions Iterator<AbstractPolicy> it = set.iterator(); while (it.hasNext()) { AbstractPolicy policy = (AbstractPolicy) (it.next()); if (constraints.meetsConstraint(policy.getVersion())) { // we found a valid version, so see if it's the right kind, // and if it is then we return it if (type == PolicyReference.POLICY_REFERENCE) { if (policy instanceof Policy) return policy; } else { if (policy instanceof PolicySet) return policy; } } } // we didn't find a match return null; }
From source file:org.apache.axis2.jaxws.message.databinding.JAXBUtils.java
/** * Create a JAXBContext using the contextpath approach * * @param packages/*w w w .j a v a 2 s .c o m*/ * @param cl ClassLoader * @param List<String> classRefs * @return JAXBContext or null if unsuccessful */ private static JAXBContext createJAXBContextUsingContextPath(TreeSet<String> packages, ClassLoader cl, List<String> classRefs) { JAXBContext context = null; String contextpath = ""; // Iterate through the classes and build the contextpath Iterator<String> it = packages.iterator(); while (it.hasNext()) { String p = it.next(); if (contextpath.length() != 0) { contextpath += ":"; } contextpath += p; } try { if (log.isDebugEnabled()) { log.debug("Attempting to create JAXBContext with contextPath=" + contextpath); } context = JAXBContext_newInstance(contextpath, cl); if (!containsClasses(context, classRefs)) { if (log.isDebugEnabled()) { log.debug(" Unsuccessful: Will now use an alterative JAXBConstruct construction"); } return null; } if (log.isDebugEnabled()) { log.debug(" Successfully created JAXBContext:" + context); } } catch (Throwable e) { if (log.isDebugEnabled()) { log.debug(" Unsuccessful: We will now use an alterative JAXBConstruct construction"); log.debug(" Reason " + e.toString()); } } return context; }
From source file:info.magnolia.test.mock.MockContentTest.java
/** * This is the mock-equivalent test of {@link info.magnolia.cms.core.DefaultContentTest#testNameFilteringWorksForBothBinaryAndNonBinaryProperties()}. *///w w w .j ava 2 s. com @Test public void testNameFilteringWorksForBothBinaryAndNonBinaryProperties() throws Exception { String contentProperties = StringUtils.join(Arrays.asList("/somepage/mypage@type=mgnl:content", "/somepage/mypage/paragraphs@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", // 2 regular props "/somepage/mypage/paragraphs/0/attention=booyah", "/somepage/mypage/paragraphs/0/imaginary=date:2009-10-14T08:59:01.227-04:00", // 3 binaries "/somepage/mypage/paragraphs/0/attachment1@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment1.fileName=hello", "/somepage/mypage/paragraphs/0/attachment1.extension=gif", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:data=X", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:mimeType=image/gif", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:lastModified=", "/somepage/mypage/paragraphs/0/attachment2@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment2.fileName=test", "/somepage/mypage/paragraphs/0/attachment2.extension=jpeg", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:data=X", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:mimeType=image/jpeg", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:lastModified=", "/somepage/mypage/paragraphs/0/image3@type=mgnl:resource", "/somepage/mypage/paragraphs/0/image3.fileName=third", "/somepage/mypage/paragraphs/0/image3.extension=png", "/somepage/mypage/paragraphs/0/image3.jcr\\:data=X", "/somepage/mypage/paragraphs/0/image3.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/image3.jcr\\:lastModified=", // and more which should not match "/somepage/mypage/paragraphs/0/foo=bar", "/somepage/mypage/paragraphs/0/mybool=boolean:true", "/somepage/mypage/paragraphs/0/rand@type=mgnl:resource", "/somepage/mypage/paragraphs/0/rand.fileName=randdddd", "/somepage/mypage/paragraphs/0/rand.extension=png", "/somepage/mypage/paragraphs/0/rand.jcr\\:data=X", "/somepage/mypage/paragraphs/0/rand.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/rand.jcr\\:lastModified="), "\n"); // --- only this line differs from the DefaultContentTest equivalent final MockHierarchyManager hm = MockUtil.createHierarchyManager(contentProperties); // --- final Content content = hm.getContent("/somepage/mypage/paragraphs/0"); final Collection<NodeData> props = content.getNodeDataCollection("att*|ima*"); assertEquals(5, props.size()); // sort by name final TreeSet<NodeData> sorted = new TreeSet<NodeData>(new Comparator<NodeData>() { @Override public int compare(NodeData o1, NodeData o2) { return o1.getName().compareTo(o2.getName()); } }); sorted.addAll(props); // sanity check - just recheck we still have 5 elements assertEquals(5, sorted.size()); final Iterator<NodeData> it = sorted.iterator(); final NodeData a = it.next(); final NodeData b = it.next(); final NodeData c = it.next(); final NodeData d = it.next(); final NodeData e = it.next(); assertEquals("attachment1", a.getName()); assertEquals(PropertyType.BINARY, a.getType()); assertEquals("attachment2", b.getName()); assertEquals(PropertyType.BINARY, b.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("attention", c.getName()); assertEquals(PropertyType.STRING, c.getType()); assertEquals("booyah", c.getString()); assertEquals("imaginary", e.getName()); assertEquals(PropertyType.DATE, e.getType()); assertEquals(true, e.getDate().before(Calendar.getInstance())); }
From source file:com.thoughtworks.go.domain.DirectoryScannerTest.java
private void compareFiles(DirectoryScanner ds, String[] expectedFiles, String[] expectedDirectories) { String includedFiles[] = ds.getIncludedFiles(); String includedDirectories[] = ds.getIncludedDirectories(); assertThat("expected " + Arrays.asList(expectedFiles) + " but " + Arrays.asList(includedFiles), includedFiles.length, is(expectedFiles.length)); assertThat("directories present: ", includedDirectories.length, is(expectedDirectories.length)); TreeSet files = new TreeSet(); for (int counter = 0; counter < includedFiles.length; counter++) { files.add(includedFiles[counter].replace(File.separatorChar, '/')); }//from www . ja va2 s. c o m TreeSet directories = new TreeSet(); for (int counter = 0; counter < includedDirectories.length; counter++) { directories.add(includedDirectories[counter].replace(File.separatorChar, '/')); } String currentfile; Iterator i = files.iterator(); int counter = 0; while (i.hasNext()) { currentfile = (String) i.next(); assertThat(currentfile, is(expectedFiles[counter])); counter++; } String currentdirectory; Iterator dirit = directories.iterator(); counter = 0; while (dirit.hasNext()) { currentdirectory = (String) dirit.next(); assertThat(currentdirectory, is(expectedDirectories[counter])); counter++; } }