List of usage examples for java.util SortedSet last
E last();
From source file:org.geoserver.taskmanager.external.impl.S3FileServiceImpl.java
@Override public FileReference getVersioned(String filePath) { int index = filePath.indexOf(PLACEHOLDER_VERSION); if (index < 0) { return new FileReferenceImpl(this, filePath, filePath); }// ww w.j a v a 2 s . c om SortedSet<Integer> set = new TreeSet<Integer>(); Pattern pattern = Pattern .compile(Pattern.quote(filePath).replace(FileService.PLACEHOLDER_VERSION, "\\E(.*)\\Q")); ObjectListing listing = getS3Client().listObjects(rootFolder, filePath.substring(0, index)); for (S3ObjectSummary summary : listing.getObjectSummaries()) { Matcher matcher = pattern.matcher(summary.getKey()); if (matcher.matches()) { try { set.add(Integer.parseInt(matcher.group(1))); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING, "could not parse version in versioned file " + summary.getKey(), e); } } } int last = set.isEmpty() ? 0 : set.last(); return new FileReferenceImpl(this, filePath.replace(FileService.PLACEHOLDER_VERSION, last + ""), filePath.replace(FileService.PLACEHOLDER_VERSION, (last + 1) + "")); }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Create adjacent available blocks but set different meeting locations. * Confirm blocks not combined by combine method. * @throws InputFormatException /*ww w . ja v a2 s. co m*/ * */ @Test public void testDifferentMeetingLocationNotCombined() throws InputFormatException { AvailableBlock blockNoLocation = AvailableBlockBuilder.createBlock("20110810-0900", "20110810-0930", 1, "some location"); AvailableBlock blockWithLocation = AvailableBlockBuilder.createBlock("20110810-0930", "20110810-1000", 1, "different location"); SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>(); smallBlocks.add(blockNoLocation); smallBlocks.add(blockWithLocation); SortedSet<AvailableBlock> combined = AvailableBlockBuilder.combine(smallBlocks); Assert.assertEquals(2, combined.size()); Assert.assertEquals(blockNoLocation, combined.first()); Assert.assertEquals(blockWithLocation, combined.last()); }
From source file:net.sourceforge.fenixedu.domain.alumni.AlumniReportFile.java
private void addCurriculumDataRow(Spreadsheet sheet, String alumniName, Integer studentNumber, Student student) {//w w w . ja va2 s.co m Alumni alumni = student.getAlumni(); // "NOME", "NUMERO_ALUNO", "CURSO", "INICIO", "CONCLUSAO", "DESCRICAO", // "EMPREGADO ACTUALMENTE" for (Registration registration : student.getRegistrationsSet()) { if (registration.isBolonha()) { if (registration.hasConcluded()) { final SortedSet<CycleCurriculumGroup> concludeCycles = new TreeSet<CycleCurriculumGroup>( CycleCurriculumGroup.COMPARATOR_BY_CYCLE_TYPE_AND_ID); concludeCycles .addAll(registration.getLastStudentCurricularPlan().getInternalCycleCurriculumGrops()); Row row = sheet.addRow(); row.setCell(alumniName); row.setCell(studentNumber); row.setCell(registration.getDegreeName()); row.setCell(registration.getStartDate().toString(DATE_FORMAT)); final CycleCurriculumGroup lastConcludedCycle = concludeCycles.last(); try { row.setCell(lastConcludedCycle.isConclusionProcessed() ? lastConcludedCycle.getConclusionDate().toString(DATE_FORMAT) : lastConcludedCycle.calculateConclusionDate().toString(DATE_FORMAT)); } catch (Exception ex) { row.setCell(NOT_AVAILABLE); } row.setCell("Bolonha"); row.setCell(alumni != null && alumni.getIsEmployed() != null ? getApp("label." + alumni.getIsEmployed()) : NOT_AVAILABLE); } } else { if (registration.isRegistrationConclusionProcessed()) { Row row = sheet.addRow(); row.setCell(alumniName); row.setCell(studentNumber); row.setCell(registration.getDegreeName()); row.setCell(registration.getStartDate().toString(DATE_FORMAT)); row.setCell(registration.getConclusionDate() != null ? registration.getConclusionDate().toString(DATE_FORMAT) : NOT_AVAILABLE); row.setCell("Pre-Bolonha"); row.setCell(alumni != null && alumni.getIsEmployed() != null ? getApp("label." + alumni.getIsEmployed()) : NOT_AVAILABLE); } } } }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java
/** * @throws ParseException // w ww . j a va 2 s. c o m * @throws InputFormatException * */ @Test public void testAvailable104() throws InputFormatException, ParseException { // get owner with meeting durations preference of 20 minutes IScheduleOwner owner = sampleOwners[3]; SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:40 AM", "MW", dateFormat.parse("20100830"), dateFormat.parse("20100903"), 1); availableScheduleDao.addToSchedule(owner, blocks); AvailableSchedule stored = availableScheduleDao.retrieve(owner); SortedSet<AvailableBlock> storedBlocks = stored.getAvailableBlocks(); Assert.assertEquals(2, storedBlocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0900"), storedBlocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1140"), storedBlocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-0900"), storedBlocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-1140"), storedBlocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(storedBlocks, 20); Assert.assertEquals(16, expanded.size()); Date originalStart = CommonDateOperations.getDateTimeFormat().parse("20100830-0900"); Date currentStart = originalStart; for (AvailableBlock e : expanded) { if (!DateUtils.isSameDay(e.getStartTime(), currentStart)) { currentStart = DateUtils.addDays(originalStart, 2); } Assert.assertEquals(currentStart, e.getStartTime()); currentStart = DateUtils.addMinutes(currentStart, 20); Assert.assertEquals(currentStart, e.getEndTime()); } }
From source file:org.sakaiproject.dash.entity.ScheduleSupport.java
public Integer findLargest(Set<Integer> numbers) { SortedSet<Integer> set = new TreeSet<Integer>(numbers); return set.last(); }
From source file:org.jahia.services.render.RenderService.java
private Template addTemplate(Resource resource, RenderContext renderContext, String templateName, Set<String> installedModules, String type) throws RepositoryException { SortedSet<Template> templates = new TreeSet<Template>(TEMPLATE_PRIORITY_COMPARATOR); for (String s : installedModules) { JahiaTemplatesPackage pack = templateManagerService.getTemplatePackageById(s); if (pack != null) { JCRNodeWrapper templateNode = resource.getNode().getSession() .getNode("/modules/" + s + "/" + pack.getVersion()); templates.addAll(addTemplates(resource, renderContext, templateName, templateNode, type)); }/*from www. ja va2 s .com*/ } return templates.isEmpty() ? null : templates.last(); }
From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java
private TokenBackedBasicResultsPage<RowResult<Value>, byte[]> getPage(final String tableName, final RangeRequest rangeRequest, final long timestamp) { final int maxRows = getBatchSize(rangeRequest); return getDbi().withHandle(new HandleCallback<TokenBackedBasicResultsPage<RowResult<Value>, byte[]>>() { @Override//from w w w .jav a2s. c o m public TokenBackedBasicResultsPage<RowResult<Value>, byte[]> withHandle(Handle handle) throws Exception { Collection<byte[]> rows = getRowsInRange(tableName, rangeRequest, timestamp, maxRows, handle); if (rows.isEmpty()) { return SimpleTokenBackedResultsPage.create(rangeRequest.getStartInclusive(), Collections.<RowResult<Value>>emptyList(), false); } ColumnSelection columns = RangeRequests.extractColumnSelection(rangeRequest); Map<Cell, Value> cells = getRows(tableName, rows, columns, timestamp); final Ordering<RowResult<Value>> ordering = RowResult .<Value>getOrderingByRowName(rangeRequest.isReverse()); final SortedSet<RowResult<Value>> result = ImmutableSortedSet.orderedBy(ordering) .addAll(AtlasSqlUtils.cellsToRows(cells)).build(); return SimpleTokenBackedResultsPage.create( AtlasSqlUtils.generateToken(rangeRequest, result.last().getRowName()), assertThatRowResultsAreOrdered(result, rangeRequest), rows.size() == maxRows); } }); }
From source file:controllers.Statistics.java
private static void getElapsedTimeStatistics(long secondInMillis, String target, ObjectNode objectNode) { TitanGraph g = Global.getGraph();/* w w w . j a v a 2s. c o m*/ long second = (secondInMillis / 1000) * 1000; Iterator<Vertex> it = g.getVertices("second", second).iterator(); Vertex v = null; SortedSet<Integer> numSet = new TreeSet<Integer>(); int value = 0; int sum = 0; int count = 0; //if(it.hasNext()) { while (it.hasNext()) { v = it.next(); for (Vertex vertex : v.query().labels("include").has("event", target).vertices()) { if (vertex == null) { continue; } value = (Integer) vertex.getProperty("elapsedTime"); count++; sum += value; numSet.add(value); } } objectNode.put("cnt", count); if (count > 0) { objectNode.put("avg", sum / count); objectNode.put("min", numSet.first()); objectNode.put("max", numSet.last()); } else { objectNode.put("avg", 0); objectNode.put("min", 0); objectNode.put("max", 0); } }
From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java
private TokenBackedBasicResultsPage<RowResult<Set<Value>>, byte[]> getPageWithHistory(final String tableName, final RangeRequest rangeRequest, final long timestamp) { final int maxRows = getBatchSize(rangeRequest); return getDbi() .withHandle(new HandleCallback<TokenBackedBasicResultsPage<RowResult<Set<Value>>, byte[]>>() { @Override//from ww w .ja v a 2 s . co m public TokenBackedBasicResultsPage<RowResult<Set<Value>>, byte[]> withHandle(Handle handle) throws Exception { Collection<byte[]> rows = getRowsInRange(tableName, rangeRequest, timestamp, maxRows, handle); if (rows.isEmpty()) { return SimpleTokenBackedResultsPage.create(rangeRequest.getStartInclusive(), Collections.<RowResult<Set<Value>>>emptyList(), false); } ListMultimap<Cell, Value> timestamps = getAllVersionsInternal(tableName, rows, RangeRequests.extractColumnSelection(rangeRequest), timestamp); final Ordering<RowResult<Set<Value>>> ordering = RowResult .getOrderingByRowName(rangeRequest.isReverse()); final SortedSet<RowResult<Set<Value>>> result = ImmutableSortedSet.orderedBy(ordering) .addAll(AtlasSqlUtils.cellsToRows(timestamps)).build(); return SimpleTokenBackedResultsPage.create( AtlasSqlUtils.generateToken(rangeRequest, result.last().getRowName()), assertThatRowResultsAreOrdered(result, rangeRequest), rows.size() == maxRows); } }); }
From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java
private TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> getPageOfTimestamps(final String tableName, final RangeRequest rangeRequest, final long timestamp) { final int maxRows = getBatchSize(rangeRequest); return getDbi().withHandle(new HandleCallback<TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]>>() { @Override// w w w . ja v a2 s .com public TokenBackedBasicResultsPage<RowResult<Set<Long>>, byte[]> withHandle(Handle handle) throws Exception { Collection<byte[]> rows = getRowsInRange(tableName, rangeRequest, timestamp, maxRows, handle); if (rows.isEmpty()) { return SimpleTokenBackedResultsPage.create(rangeRequest.getStartInclusive(), Collections.<RowResult<Set<Long>>>emptyList(), false); } ColumnSelection columns = RangeRequests.extractColumnSelection(rangeRequest); ListMultimap<Cell, Long> timestamps = getAllTimestampsInternal(tableName, rows, columns, timestamp); final Ordering<RowResult<Set<Long>>> ordering = RowResult .<Set<Long>>getOrderingByRowName(rangeRequest.isReverse()); final SortedSet<RowResult<Set<Long>>> result = ImmutableSortedSet.orderedBy(ordering) .addAll(AtlasSqlUtils.cellsToRows(timestamps)).build(); return new SimpleTokenBackedResultsPage<RowResult<Set<Long>>, byte[]>( AtlasSqlUtils.generateToken(rangeRequest, result.last().getRowName()), assertThatRowResultsAreOrdered(result, rangeRequest), rows.size() == maxRows); } }); }