List of usage examples for java.util SortedSet last
E last();
From source file:edu.cornell.mannlib.vitro.webapp.freemarker.loader.FreemarkerTemplateLoaderTest.java
/** * @param searchTerm/*w ww. j a va 2s . c om*/ * template we are looking for * @param expectedHowMany * How many matches do we expect? * @param expectedBestFit * What should the best match turn out to be? * @throws IOException */ private void assertMatches(String searchTerm, int expectedHowMany, String expectedBestFitString) { Path expectedBestFit = (expectedBestFitString == null) ? null : Paths.get(expectedBestFitString); SortedSet<PathPieces> matches = runTheVisitor(searchTerm); int actualHowMany = matches.size(); Path actualBestFit = matches.isEmpty() ? null : matches.last().path; if (expectedHowMany != actualHowMany) { fail("How many results: expected " + expectedHowMany + ", but was " + actualHowMany + ": " + matches); } assertEquals("Best result", expectedBestFit, actualBestFit); }
From source file:pl.otros.logview.gui.message.SoapFinderTest.java
@Test public void testFindSoap() throws Exception { String stringWithSoaps = IOUtils .toString(this.getClass().getClassLoader().getResourceAsStream("soap/stringWithSoap.txt")); SoapFinder finder = new SoapFinder(); SortedSet<SubText> findSoaps = finder.findSoaps(stringWithSoaps); // 60,300//from w w w.j a v a 2s. c o m AssertJUnit.assertEquals(2, findSoaps.size()); SubText first = findSoaps.first(); stringWithSoaps.substring(first.getStart(), first.getEnd()); AssertJUnit.assertEquals(38, first.getStart()); AssertJUnit.assertEquals(299, first.getEnd()); SubText last = findSoaps.last(); stringWithSoaps.substring(last.getStart(), last.getEnd()); AssertJUnit.assertEquals(369, last.getStart()); AssertJUnit.assertEquals(645, last.getEnd()); }
From source file:org.eclipse.skalli.commons.StatisticsTest.java
private void assertMixedStatistics(Statistics stats) { SortedSet<UsageInfo> usageInfo = stats.getUsageInfo(); assertEquals(3, usageInfo.size());// w w w . j a v a 2s .c o m SortedSet<UserInfo> userInfo = stats.getUserInfo(); assertEquals(2, userInfo.size()); assertEquals(0, userInfo.first().getSequenceNumber()); assertEquals(5, userInfo.last().getSequenceNumber()); SortedSet<BrowserInfo> browserInfo = stats.getBrowserInfo(); assertEquals(1, browserInfo.size()); assertEquals(6, browserInfo.first().getSequenceNumber()); SortedSet<SearchInfo> searchInfo = stats.getSearchInfo(); assertEquals(2, searchInfo.size()); assertEquals(2, searchInfo.first().getSequenceNumber()); assertEquals(8, searchInfo.last().getSequenceNumber()); SortedSet<RefererInfo> referInfo = stats.getRefererInfo(); assertEquals(1, referInfo.size()); assertEquals(3, referInfo.first().getSequenceNumber()); SortedSet<ResponseTimeInfo> responseInfo = stats.getResponseTimeInfo(); assertEquals(1, responseInfo.size()); assertEquals(7, responseInfo.first().getSequenceNumber()); assertEquals(userInfo.first().getTimestamp(), stats.getStartDate()); assertEquals(usageInfo.last().getTimestamp(), stats.getEndDate()); assertEquals(usageInfo.last().getSequenceNumber() + 1, stats.getSequenceNumber()); }
From source file:org.apache.hadoop.mapred.SortedRanges.java
/** * Remove the range indices. If this range is * found in existing ranges, the existing ranges * are shrunk.//from w ww . ja va 2 s .c o m * If range is of 0 length, doesn't do anything. * @param range Range to be removed. */ synchronized void remove(Range range) { if (range.isEmpty()) { return; } long startIndex = range.getStartIndex(); long endIndex = range.getEndIndex(); //make sure that there are no overlapping ranges SortedSet<Range> headSet = ranges.headSet(range); if (headSet.size() > 0) { Range previousRange = headSet.last(); LOG.debug("previousRange " + previousRange); if (startIndex < previousRange.getEndIndex()) { //previousRange overlaps this range //narrow down the previousRange if (ranges.remove(previousRange)) { indicesCount -= previousRange.getLength(); LOG.debug("removed previousRange " + previousRange); } add(previousRange.getStartIndex(), startIndex); if (endIndex <= previousRange.getEndIndex()) { add(endIndex, previousRange.getEndIndex()); } } } Iterator<Range> tailSetIt = ranges.tailSet(range).iterator(); while (tailSetIt.hasNext()) { Range nextRange = tailSetIt.next(); LOG.debug("nextRange " + nextRange + " startIndex:" + startIndex + " endIndex:" + endIndex); if (endIndex > nextRange.getStartIndex()) { //nextRange overlaps this range //narrow down the nextRange tailSetIt.remove(); indicesCount -= nextRange.getLength(); if (endIndex < nextRange.getEndIndex()) { add(endIndex, nextRange.getEndIndex()); break; } } else { break; } } }
From source file:org.apache.hadoop.hbase.regionserver.SegmentScanner.java
/** * Seek the scanner at the first Cell of the row which is the previous row * of specified key/* www.j a va 2s .c o m*/ * * @param cell seek value * @return true if the scanner at the first valid Cell of previous row, * false if not existing such Cell */ @Override public boolean seekToPreviousRow(Cell cell) throws IOException { if (closed) { return false; } boolean keepSeeking; Cell key = cell; do { Cell firstKeyOnRow = PrivateCellUtil.createFirstOnRow(key); SortedSet<Cell> cellHead = segment.headSet(firstKeyOnRow); Cell lastCellBeforeRow = cellHead.isEmpty() ? null : cellHead.last(); if (lastCellBeforeRow == null) { current = null; return false; } Cell firstKeyOnPreviousRow = PrivateCellUtil.createFirstOnRow(lastCellBeforeRow); this.stopSkippingKVsIfNextRow = true; this.stopSkippingKVsRow = firstKeyOnPreviousRow; seek(firstKeyOnPreviousRow); this.stopSkippingKVsIfNextRow = false; if (peek() == null || segment.getComparator().compareRows(peek(), firstKeyOnPreviousRow) > 0) { keepSeeking = true; key = firstKeyOnPreviousRow; continue; } else { keepSeeking = false; } } while (keepSeeking); return true; }
From source file:org.apache.hadoop.mapred.SortedRanges.java
/** * Add the range indices. It is ensured that the added range * doesn't overlap the existing ranges. If it overlaps, the * existing overlapping ranges are removed and a single range * having the superset of all the removed ranges and this range * is added. //from w w w . ja v a2 s .c o m * If the range is of 0 length, doesn't do anything. * @param range Range to be added. */ synchronized void add(Range range) { if (range.isEmpty()) { return; } long startIndex = range.getStartIndex(); long endIndex = range.getEndIndex(); //make sure that there are no overlapping ranges SortedSet<Range> headSet = ranges.headSet(range); if (headSet.size() > 0) { Range previousRange = headSet.last(); LOG.debug("previousRange " + previousRange); if (startIndex < previousRange.getEndIndex()) { //previousRange overlaps this range //remove the previousRange if (ranges.remove(previousRange)) { indicesCount -= previousRange.getLength(); } //expand this range startIndex = previousRange.getStartIndex(); endIndex = endIndex >= previousRange.getEndIndex() ? endIndex : previousRange.getEndIndex(); } } Iterator<Range> tailSetIt = ranges.tailSet(range).iterator(); while (tailSetIt.hasNext()) { Range nextRange = tailSetIt.next(); LOG.debug("nextRange " + nextRange + " startIndex:" + startIndex + " endIndex:" + endIndex); if (endIndex >= nextRange.getStartIndex()) { //nextRange overlaps this range //remove the nextRange tailSetIt.remove(); indicesCount -= nextRange.getLength(); if (endIndex < nextRange.getEndIndex()) { //expand this range endIndex = nextRange.getEndIndex(); break; } } else { break; } } add(startIndex, endIndex); }
From source file:org.kalypso.model.wspm.ui.view.chart.layer.wsp.WspLayer.java
@Override public IDataRange<Double> getTargetRange(final IDataRange<Double> domainIntervall) { final WaterlevelRenderData[] renderData = getRenderData(); if (renderData.length == 0) return null; final SortedSet<Double> values = new TreeSet<>(); for (final WaterlevelRenderData data : renderData) { final double value = data.getValue(); values.add(value);//from w ww . java 2 s . co m } final Double min = values.first(); final Double max = values.last(); return new DataRange<>(min, max); }
From source file:edu.cornell.mannlib.vitro.webapp.freemarker.loader.FreemarkerTemplateLoaderTest.java
/** * Try for exact match, then pare down if needed, just like Freemarker * would.//from ww w.j av a 2 s. c o m */ private void assertFM(String searchTerm, int expectedNumberOfTries, String expectedBestString) { Path expectedBestFit = expectedBestString == null ? null : Paths.get(expectedBestString); PathPieces stPp = new PathPieces(searchTerm); int actualNumberOfTries = 0; Path actualBestFit = null; if (StringUtils.isNotBlank(stPp.region)) { actualNumberOfTries++; SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.language + stPp.region + stPp.extension); if (!matches.isEmpty()) { actualBestFit = matches.last().path; } } if (actualBestFit == null && StringUtils.isNotBlank(stPp.language)) { actualNumberOfTries++; SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.language + stPp.extension); if (!matches.isEmpty()) { actualBestFit = matches.last().path; } } if (actualBestFit == null) { actualNumberOfTries++; SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.extension); if (!matches.isEmpty()) { actualBestFit = matches.last().path; } } assertEquals("How many tries", expectedNumberOfTries, actualNumberOfTries); assertEquals("best fit", expectedBestFit, actualBestFit); }
From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java
private Integer[] findOutermost(final Integer[] intersectionPoints) { Assert.isTrue(intersectionPoints.length > 1); final Integer[] result = new Integer[2]; final SortedSet<Integer> markerIndices = new TreeSet<>(Arrays.asList(intersectionPoints)); result[0] = markerIndices.first();//w w w . j a v a 2 s. c om result[1] = markerIndices.last(); return result; }
From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java
private Integer[] mixExistingWithIntersectionPoint(final IProfile profil, final Integer intersectionIndex) { final Integer[] markerPoints = existingMarkersAsIndices(profil); final SortedSet<Integer> markerIndices = new TreeSet<>(Arrays.asList(markerPoints)); // depends on the side of the profile! final IProfileRecord lowestPoint = ProfileVisitors.findLowestPoint(profil); if (Objects.isNull(lowestPoint)) return new Integer[] { intersectionIndex }; final Collection<Integer> result = new ArrayList<>(2); result.add(intersectionIndex);//from w w w.j av a2 s . c o m if (intersectionIndex > lowestPoint.getIndex()) { // use leftmost of all left markers final SortedSet<Integer> leftSet = markerIndices.headSet(lowestPoint.getIndex()); if (!leftSet.isEmpty()) { result.add(leftSet.first()); } } else { // use leftmost of all left markers final SortedSet<Integer> rightSet = markerIndices.tailSet(lowestPoint.getIndex()); if (!rightSet.isEmpty()) { result.add(rightSet.last()); } } return result.toArray(new Integer[result.size()]); }