List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:org.unitime.timetable.test.StudentSectioningTest.java
private static String getInstructorNames(Class_ clazz) { if (!clazz.isDisplayInstructor().booleanValue()) return null; String ret = null;/*from ww w . j a v a2s. c o m*/ TreeSet ts = new TreeSet(clazz.getClassInstructors()); for (Iterator i = ts.iterator(); i.hasNext();) { ClassInstructor ci = (ClassInstructor) i.next(); if (!ci.isLead().booleanValue()) continue; if (ret == null) ret = ci.getInstructor().nameShort(); else ret += ":" + ci.getInstructor().nameShort(); } return ret; }
From source file:md.MangaDownloader.java
public static String automaticVolumeName(List<MangaChaptersInfo> selectedChapters) { TreeSet<Integer> chapterNumbers = new TreeSet<Integer>(); String alternative = ""; for (MangaChaptersInfo m : selectedChapters) { try {/*from ww w . j av a 2 s .c o m*/ if (!m.chapterNumber.equals("")) { int test = Integer.parseInt(m.chapterNumber); chapterNumbers.add(test); } } catch (NumberFormatException e) { //If more than one alternative chapter name then all renamed to "Extras" if (alternative.equals("")) { alternative = m.chapterNumber; } else { alternative = STRINGS.getString("NAME_EXTRAS"); } } } String result = ""; if (!chapterNumbers.isEmpty()) { int firstInSequence = Integer.MIN_VALUE; int lastInSequence; for (Iterator<Integer> i = chapterNumbers.iterator(); i.hasNext();) { int actualNumber = i.next(); if (firstInSequence == Integer.MIN_VALUE) firstInSequence = actualNumber; lastInSequence = actualNumber; int next; if (i.hasNext()) { next = chapterNumbers.higher(actualNumber); } else { next = Integer.MIN_VALUE; } if ((actualNumber + 1 != next) || (next == Integer.MIN_VALUE)) { //FIN DE SECUENCIA if (!result.equals("")) { result += ", "; } if (firstInSequence == lastInSequence) { result += String.format("%04d", firstInSequence); } else { result += String.format("%04d - %04d", firstInSequence, lastInSequence); } firstInSequence = Integer.MIN_VALUE; } } } if (!alternative.equals("")) { if (!result.equals("")) result += " & "; result += alternative; } return result; }
From source file:org.mapfish.print.output.OutputFactory.java
private boolean permitted(String supportedFormat, Config config) { TreeSet<String> configuredFormats = config.getFormats(); if (configuredFormats.size() == 1 && configuredFormats.iterator().next().trim().equals("*")) { return true; }/*w w w. j av a2 s . co m*/ if (configuredFormats.isEmpty()) { return "pdf".equalsIgnoreCase(supportedFormat); } for (String configuredFormat : configuredFormats) { if (configuredFormat.equalsIgnoreCase(supportedFormat)) return true; } return false; }
From source file:org.springframework.integration.x.rollover.file.RolloverFileMessageHandlerTest.java
@Test public void testRolloverFileSink() throws IOException, InterruptedException { applicationContext.start();/* w ww . ja v a 2 s .c o m*/ input.send(new GenericMessage<String>("foo")); Thread.sleep(1100); // > 1 sec to make sure it crosses the rollover time trigger set to 1 second. input.send(new GenericMessage<String>("bar")); // Second message should land in a new file. TreeSet<File> files = new TreeSet<File>(FileUtils.listFiles(tmpDir, null, false)); assertEquals(2, files.size()); Iterator<File> iterator = files.iterator(); File firstFile = iterator.next(); assertTrue(firstFile.toString().startsWith("test_results/archive.test666_")); // no gzip at the moment as the compression now happens asynchronous assertEquals("foo\n", IOUtils.toString(firstFile.toURI())); File secondFile = iterator.next(); assertTrue(secondFile.toString().startsWith("test_results/test666_")); assertEquals("bar\n", IOUtils.toString(secondFile.toURI())); }
From source file:org.jboss.dashboard.ui.config.treeNodes.WorkspacesNode.java
protected List listChildren() { try {//from ww w.j a v a 2s . c o m Set workspaceIds = UIServices.lookup().getWorkspacesManager().getAllWorkspacesIdentifiers(); TreeSet sortedWorkspaceIds = new TreeSet(workspaceIds); ArrayList list = new ArrayList(); for (Iterator iterator = sortedWorkspaceIds.iterator(); iterator.hasNext();) { String workspaceId = (String) iterator.next(); Workspace workspace = UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceId); WorkspacePermission viewPerm = WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_LOGIN); boolean canLogin = UserStatus.lookup().hasPermission(viewPerm); if (canLogin) list.add(getNewWorkspaceNode(workspace)); } return list; } catch (Exception e) { log.error("Error: ", e); } return null; }
From source file:org.openmicroscopy.shoola.env.data.util.OriginalMetadataParser.java
/** * Writes the content of the map to a String. * /*from w w w. j a va 2 s. c om*/ * @param map The map to convert. * @param separator Value used to separate key and value. * @return See above. */ private String writeMap(Map<String, RType> map, String separator) { if (map == null || map.size() == 0) return null; if (StringUtils.isBlank(separator)) separator = " "; TreeSet<String> sortedSet = new TreeSet<String>(map.keySet()); Iterator<String> j = sortedSet.iterator(); String key; Object v; StringBuffer buffer = new StringBuffer(); while (j.hasNext()) { key = j.next(); buffer.append(key); buffer.append(separator); v = ModelMapper.convertRTypeToJava(map.get(key)); if (v instanceof List) { List<Object> l = (List<Object>) v; Iterator<Object> k = l.iterator(); while (k.hasNext()) { buffer.append(k.next()); buffer.append(" "); } } else if (v instanceof Map) { Map<String, Object> l = (Map<String, Object>) v; Entry<String, Object> e; Iterator<Entry<String, Object>> k = l.entrySet().iterator(); while (k.hasNext()) { e = k.next(); buffer.append(e.getKey()); buffer.append(separator); buffer.append(e.getValue()); } } else buffer.append(v.toString()); buffer.append(System.getProperty("line.separator")); } return buffer.toString(); }
From source file:org.jamocha.dn.ConflictSet.java
/** * Deletes all revoked asserts and all retracts. *//*from w w w . j ava 2 s.co m*/ public synchronized void deleteRevokedEntries() { for (final Iterator<Entry<Integer, TreeSet<RuleAndToken>>> entryIterator = this.rulesAndTokensBySalience .entrySet().iterator(); entryIterator.hasNext();) { final Entry<Integer, TreeSet<RuleAndToken>> entry = entryIterator.next(); final TreeSet<RuleAndToken> rulesAndTokens = entry.getValue(); final Iterator<RuleAndToken> iterator = rulesAndTokens.iterator(); while (iterator.hasNext()) { final RuleAndToken nodeAndToken = iterator.next(); final AssertOrRetract<?> token = nodeAndToken.getToken(); if (token.isRevokedOrMinus() || 0 == token.getMem().size()) { iterator.remove(); } } if (rulesAndTokens.isEmpty()) { entryIterator.remove(); } } }
From source file:net.certiv.authmgr.task.section.model.AnalyzeModel.java
private void analyzePartitions(PersistantWordsDataSource pds, String category, HashMap<String, HashMap<String, WordProbabilityPT>> partsMap) { PartitionKeyComparator keyComp = new PartitionKeyComparator(partsMap); TreeSet<String> partKeys = new TreeSet<String>(keyComp); partKeys.addAll(partsMap.keySet());//ww w . java 2s . co m String partitions = ""; for (Iterator<String> it = partKeys.iterator(); it.hasNext();) { partitions = partitions + it.next() + " "; } Log.info(this, "Partition collection: " + partKeys.size() + " = " + partitions); // for each partition for (Iterator<String> it = partKeys.iterator(); it.hasNext();) { String partition = it.next(); HashMap<String, WordProbabilityPT> wordsMap = partsMap.get(partition); analyzeWords(category, partition, wordsMap); } }
From source file:org.unitime.timetable.test.StudentSectioningTest.java
private static Course loadCourse(CourseOffering co, long studentId) { sLog.debug(" -- loading " + co.getCourseName()); Offering offering = new Offering(co.getInstructionalOffering().getUniqueId().longValue(), co.getInstructionalOffering().getCourseName()); int projected = (co.getProjectedDemand() == null ? 0 : co.getProjectedDemand().intValue()); int courseLimit = co.getInstructionalOffering().getLimit().intValue(); if (co.getReservation() != null) courseLimit = co.getReservation(); Course course = new Course(co.getUniqueId().longValue(), co.getSubjectAreaAbbv(), co.getCourseNbr(), offering, courseLimit, projected); Hashtable class2section = new Hashtable(); Hashtable ss2subpart = new Hashtable(); for (Iterator i = co.getInstructionalOffering().getInstrOfferingConfigs().iterator(); i.hasNext();) { InstrOfferingConfig ioc = (InstrOfferingConfig) i.next(); Config config = new Config(ioc.getUniqueId().longValue(), (ioc.isUnlimitedEnrollment() ? -1 : ioc.getLimit()), ioc.getCourseName() + " [" + ioc.getName() + "]", offering); TreeSet subparts = new TreeSet(new SchedulingSubpartComparator()); subparts.addAll(ioc.getSchedulingSubparts()); for (Iterator j = subparts.iterator(); j.hasNext();) { SchedulingSubpart ss = (SchedulingSubpart) j.next(); String sufix = ss.getSchedulingSubpartSuffix(); Subpart parentSubpart = (ss.getParentSubpart() == null ? null : (Subpart) ss2subpart.get(ss.getParentSubpart())); Subpart subpart = new Subpart(ss.getUniqueId().longValue(), ss.getItype().getItype().toString() + sufix, ss.getItypeDesc().trim() + (sufix == null || sufix.length() == 0 ? "" : " (" + sufix + ")"), config, parentSubpart); subpart.setAllowOverlap(ss.isStudentAllowOverlap()); ss2subpart.put(ss, subpart); for (Iterator k = ss.getClasses().iterator(); k.hasNext();) { Class_ c = (Class_) k.next(); Assignment a = c.getCommittedAssignment(); int usedSpace = 0; if (studentId >= 0) for (Iterator l = c.getStudentEnrollments().iterator(); l.hasNext();) { StudentClassEnrollment sce = (StudentClassEnrollment) l.next(); if (Long.parseLong(sce.getStudent().getExternalUniqueId()) != studentId) usedSpace++; }/*from w w w.j ava 2 s . c om*/ /* Number usedSpace = (Number)new Class_DAO().getSession().createQuery( "select count(sce) from StudentClassEnrollment sce where " + "sce.clazz.uniqueId=:classId and sce.student.externalUniqueId!=:studentId"). setLong("classId", c.getUniqueId()). setLong("studentId", studentId).uniqueResult(); if (studentId<0) usedSpace = new Integer(0); */ int limit = c.getClassLimit() - usedSpace; if (ioc.isUnlimitedEnrollment().booleanValue()) limit = -1; Section parentSection = (c.getParentClass() == null ? null : (Section) class2section.get(c.getParentClass())); Section section = new Section(c.getUniqueId().longValue(), limit, c.getClassLabel(), subpart, (a == null ? null : a.getPlacement()), getInstructorIds(c), getInstructorNames(c), parentSection); if (c.getSectioningInfo() != null) { section.setSpaceExpected(c.getSectioningInfo().getNbrExpectedStudents().doubleValue()); section.setSpaceHeld(c.getSectioningInfo().getNbrHoldingStudents().doubleValue()); section.setPenalty(getPenalty(section, c, studentId)); } class2section.put(c, section); sLog.debug(" -- section " + section); } } } return course; }
From source file:com.linkedin.pinot.operator.filter.OrOperatorTest.java
@Test public void testUnionForTwoLists() { int[] docIds1 = new int[] { 2, 3, 10, 15, 16, 28 }; int[] docIds2 = new int[] { 3, 6, 8, 20, 28 }; TreeSet<Integer> treeSet = new TreeSet<>(); treeSet.addAll(Arrays.asList(ArrayUtils.toObject(docIds1))); treeSet.addAll(Arrays.asList(ArrayUtils.toObject(docIds2))); Iterator<Integer> expectedIterator = treeSet.iterator(); List<BaseFilterOperator> operators = new ArrayList<>(); operators.add(FilterOperatorTestUtils.makeFilterOperator(docIds1)); operators.add(FilterOperatorTestUtils.makeFilterOperator(docIds2)); OrOperator orOperator = new OrOperator(operators); BlockDocIdIterator iterator = orOperator.nextBlock().getBlockDocIdSet().iterator(); int docId;/*from ww w .j a v a2 s. c om*/ while ((docId = iterator.next()) != Constants.EOF) { Assert.assertEquals(docId, expectedIterator.next().intValue()); } }