List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:com.antelink.sourcesquare.client.scan.SourceSquareFSWalker.java
public synchronized void queryFiles(TreeSet<File> fileSet) throws InterruptedException { HashMap<String, String> toAnalyze = new HashMap<String, String>(); Iterator<File> iterator = fileSet.iterator(); logger.debug(fileSet.size() + " files to analyze"); long count = 0; long timer = System.currentTimeMillis(); while (iterator.hasNext()) { File file = iterator.next(); logger.trace("adding analyze file to the pool: " + file.getAbsolutePath()); try {// ww w .jav a 2 s . com String sha1 = FileAnalyzer.calculateHash("SHA-1", file); toAnalyze.put(file.getAbsolutePath(), sha1); count++; } catch (Exception e) { logger.error("skipping files " + file, e); } if (toAnalyze.size() == this.filePerQuery || System.currentTimeMillis() - timer > COMPUTE_WAIT_TIME) { // dispatch analysis timer = System.currentTimeMillis(); analyzeMap(toAnalyze); this.filePerQuery = Math.min(MAX_FILE_PER_QUERY, this.filePerQuery * 2); logger.trace("new counter: " + count); } } analyzeMap(toAnalyze); while (!allProcessDone()) { synchronized (this.lock) { this.lock.wait(); } } this.eventBus.fireEvent(new ScanCompleteEvent(this.levels)); logger.info("Analysis done " + count); }
From source file:org.deeplearning4j.util.FingerPrintKeyer.java
public String key(String s, Object... o) { if (s == null || o != null && o.length > 0) { throw new IllegalArgumentException("Fingerprint keyer accepts a single string parameter"); }//from w ww .j av a 2 s . com s = s.trim(); // first off, remove whitespace around the string s = s.toLowerCase(); // then lowercase it s = punctctrl.matcher(s).replaceAll(""); // then remove all punctuation and control chars String[] frags = StringUtils.split(s); // split by whitespace TreeSet<String> set = new TreeSet<>(); Collections.addAll(set, frags); StringBuilder b = new StringBuilder(); Iterator<String> i = set.iterator(); while (i.hasNext()) { // join ordered fragments back together b.append(i.next()); if (i.hasNext()) { b.append(' '); } } return asciify(b.toString()); // find ASCII equivalent to characters }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * get all views (viewId's) with Statistic * @return//from w w w. j a v a 2 s . c o m */ public static String[] getViews(Model model) { TreeSet<String> views = new TreeSet<String>(); String[] ids = model.getStatistics().getAllIds(); for (int i = 0; i < ids.length; i++) { Statistic statistic = model.getStatistics().get(ids[i]); StatisticGrafic statisticGrafic = (StatisticGrafic) statistic.getGrafic(); if (statisticGrafic != null) { String viewId = statisticGrafic.getViewId(); if (!views.contains(viewId)) views.add(viewId); } } String[] out = new String[views.size()]; int i = 0; for (Iterator<String> it = views.iterator(); it.hasNext();) { out[i] = it.next(); i++; } return out; }
From source file:net.certiv.authmgr.task.section.model.AnalyzeModel.java
private void analyzeWords(String category, String partition, HashMap<String, WordProbabilityPT> wordsMap) { // convert to sorted set WordProbPTComparator sorter = new WordProbPTComparator(); TreeSet<WordProbabilityPT> wordProbs = new TreeSet<WordProbabilityPT>(sorter); wordProbs.addAll(wordsMap.values()); // now accumulate and print statistics StringBuffer wordlist = new StringBuffer(); int k = 0;//w ww.j a v a2 s . c o m for (Iterator<WordProbabilityPT> it = wordProbs.iterator(); it.hasNext() && k < 20; k++) { WordProbabilityPT wp = it.next(); String word = wp.getWord(); double prob = wp.getProbability(); double count = wp.getMatchingCount(); BigDecimal probBD = new BigDecimal(prob).setScale(8, BigDecimal.ROUND_HALF_UP); String countStr = Util.rightAlign("" + count, 6); String wordAbbr = StringUtils.abbreviate(word, 13); wordlist.append(Util.leftAlign(wordAbbr, 14) + probBD + "/" + countStr + "| "); } Log.info(this, Util.leftAlign(partition + ":", 14) + Util.rightAlign("" + wordProbs.size(), 5) + " = " + wordlist.toString()); }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
private static void printJSONObject(JSONObject jsonObject, String indentation, BufferedWriter buff) { try {/*from ww w. j a va 2s. c o m*/ @SuppressWarnings("unchecked") Iterator<String> keys = (Iterator<String>) jsonObject.keys(); TreeSet<String> orderedKeysSet = new TreeSet<String>(); while (keys.hasNext()) { orderedKeysSet.add(keys.next()); } Iterator<String> orderedKeys = orderedKeysSet.iterator(); while (orderedKeys.hasNext()) { String key = orderedKeys.next(); try { Object value = jsonObject.get(key); if (value instanceof JSONObject) { if (buff != null) { buff.write(indentation + " " + key + " : "); buff.newLine(); } // Log.i(AnkiDroidApp.TAG, " " + indentation + key + " : "); printJSONObject((JSONObject) value, indentation + "-", buff); } else { if (buff != null) { buff.write(indentation + " " + key + " = " + jsonObject.get(key).toString()); buff.newLine(); } // Log.i(AnkiDroidApp.TAG, " " + indentation + key + " = " + jsonObject.get(key).toString()); } } catch (JSONException e) { Log.e(AnkiDroidApp.TAG, "JSONException = " + e.getMessage()); } } } catch (IOException e1) { Log.e(AnkiDroidApp.TAG, "IOException = " + e1.getMessage()); } }
From source file:com.linkedin.pinot.operator.OrOperatorTest.java
@Test public void testIntersectionForThreeLists() { int[] list1 = new int[] { 2, 3, 6, 10, 15, 16, 28 }; int[] list2 = new int[] { 3, 6, 8, 20, 28 }; int[] list3 = new int[] { 1, 2, 3, 6, 30 }; List<Operator> operators = new ArrayList<Operator>(); operators.add(makeFilterOperator(list1)); operators.add(makeFilterOperator(list2)); operators.add(makeFilterOperator(list3)); final OrOperator orOperator = new OrOperator(operators); orOperator.open();/* ww w .j a va 2 s .c om*/ Block block; TreeSet<Integer> set = new TreeSet<Integer>(); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list1))); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list2))); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list3))); Iterator<Integer> expectedIterator = set.iterator(); while ((block = orOperator.nextBlock()) != null) { final BlockDocIdSet blockDocIdSet = block.getBlockDocIdSet(); final BlockDocIdIterator iterator = blockDocIdSet.iterator(); int docId; while ((docId = iterator.next()) != Constants.EOF) { Assert.assertEquals(expectedIterator.next().intValue(), docId); } } orOperator.close(); }
From source file:org.jasig.portlet.calendar.processor.ICalendarContentProcessorTest.java
@Test public void test() throws IOException { Resource calendarFile = applicationContext.getResource("classpath:/sampleEvents.ics"); DateMidnight start = new DateMidnight(2010, 1, 1, DateTimeZone.UTC); Interval interval = new Interval(start, start.plusYears(3)); InputStream in = calendarFile.getInputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); IOUtils.copyLarge(in, buffer);// ww w . ja v a2 s. c o m TreeSet<VEvent> events = new TreeSet<VEvent>(new VEventStartComparator()); net.fortuna.ical4j.model.Calendar c = processor.getIntermediateCalendar(interval, new ByteArrayInputStream(buffer.toByteArray())); events.addAll(processor.getEvents(interval, c)); assertEquals(5, events.size()); Iterator<VEvent> iterator = events.iterator(); VEvent event = iterator.next(); assertEquals("Independence Day", event.getSummary().getValue()); assertNull(event.getStartDate().getTimeZone()); event = iterator.next(); assertEquals("Vikings @ Saints [NBC]", event.getSummary().getValue()); DateTime eventStart = new DateTime(event.getStartDate().getDate(), DateTimeZone.UTC); assertEquals(0, eventStart.getHourOfDay()); assertEquals(30, eventStart.getMinuteOfHour()); event = iterator.next(); assertEquals("Independence Day", event.getSummary().getValue()); assertNull(event.getStartDate().getTimeZone()); }
From source file:com.linkedin.pinot.operator.OrOperatorTest.java
@Test public void testComplex() { int[] list1 = new int[] { 2, 3, 6, 10, 15, 16, 28 }; int[] list2 = new int[] { 3, 6, 8, 20, 28 }; int[] list3 = new int[] { 1, 2, 3, 6, 30 }; TreeSet<Integer> set = new TreeSet<Integer>(); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list1))); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list2))); set.addAll(Lists.newArrayList(ArrayUtils.toObject(list3))); Iterator<Integer> expectedIterator = set.iterator(); List<Operator> operators = new ArrayList<Operator>(); operators.add(makeFilterOperator(list1)); operators.add(makeFilterOperator(list2)); final OrOperator orOperator1 = new OrOperator(operators); List<Operator> operators1 = new ArrayList<Operator>(); operators1.add(orOperator1);/*from www. ja v a 2s. c o m*/ operators1.add(makeFilterOperator(list3)); final OrOperator orOperator = new OrOperator(operators1); orOperator.open(); BaseFilterBlock block; while ((block = orOperator.getNextBlock()) != null) { final BlockDocIdSet blockDocIdSet = block.getBlockDocIdSet(); final BlockDocIdIterator iterator = blockDocIdSet.iterator(); int docId; while ((docId = iterator.next()) != Constants.EOF) { System.out.println(docId); Assert.assertEquals(expectedIterator.next().intValue(), docId); } } orOperator.close(); }
From source file:org.wso2.andes.kernel.slot.SlotManagerStandalone.java
/** * Delete slot details when slot is empty. (All the messages are delivered and acknowledgments are * returned )/* w ww . ja v a 2 s. c o m*/ * * @param queueName Name of the queue * @param slotToBeDeleted Slot to be deleted * @return Whether deleted or not */ public boolean deleteSlot(String queueName, Slot slotToBeDeleted) { String lockKey = queueName + SlotManagerStandalone.class; synchronized (lockKey.intern()) { TreeSet<Slot> assignedSlotSet = slotAssignmentMap.get(queueName); if (null != assignedSlotSet) { Iterator assignedSlotIterator = assignedSlotSet.iterator(); while (assignedSlotIterator.hasNext()) { Slot assignedSlot = (Slot) assignedSlotIterator.next(); if (assignedSlot.getEndMessageId() == slotToBeDeleted.getEndMessageId()) { assignedSlotIterator.remove(); break; } } } } return true; }
From source file:org.apache.hadoop.hbase.backup.impl.RestoreClientImpl.java
/** * Restore operation. Stage 2: resolved Backup Image dependency * @param backupManifestMap : tableName, Manifest * @param sTableArray The array of tables to be restored * @param tTableArray The array of mapping tables to restore to * @return set of BackupImages restored//from w w w .j av a 2 s. c o m * @throws IOException exception */ private void restoreStage(HashMap<TableName, BackupManifest> backupManifestMap, TableName[] sTableArray, TableName[] tTableArray, boolean isOverwrite) throws IOException { TreeSet<BackupImage> restoreImageSet = new TreeSet<BackupImage>(); boolean truncateIfExists = isOverwrite; try { for (int i = 0; i < sTableArray.length; i++) { TableName table = sTableArray[i]; BackupManifest manifest = backupManifestMap.get(table); // Get the image list of this backup for restore in time order from old // to new. List<BackupImage> list = new ArrayList<BackupImage>(); list.add(manifest.getBackupImage()); List<BackupImage> depList = manifest.getDependentListByTable(table); list.addAll(depList); TreeSet<BackupImage> restoreList = new TreeSet<BackupImage>(list); LOG.debug("need to clear merged Image. to be implemented in future jira"); restoreImages(restoreList.iterator(), table, tTableArray[i], truncateIfExists); restoreImageSet.addAll(restoreList); if (restoreImageSet != null && !restoreImageSet.isEmpty()) { LOG.info("Restore includes the following image(s):"); for (BackupImage image : restoreImageSet) { LOG.info("Backup: " + image.getBackupId() + " " + HBackupFileSystem .getTableBackupDir(image.getRootDir(), image.getBackupId(), table)); } } } } catch (Exception e) { LOG.error("Failed", e); throw new IOException(e); } LOG.debug("restoreStage finished"); }