List of usage examples for java.util TreeSet last
public E last()
From source file:org.jasig.schedassist.model.VisibleScheduleBuilderTest.java
/** * // ww w . ja va 2 s .c om * @throws Exception */ @Test public void testOddAppointmentMultipleAttendees() throws Exception { Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "12:00 PM", "MTRF", makeDateTime("20090202-0830"), makeDateTime("20090206-1600"), 1, null); TreeSet<AvailableBlock> expanded = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 45)); LOG.info("expanded set first: " + expanded.first() + ", last: " + expanded.last()); AvailableSchedule schedule = new AvailableSchedule(expanded); DateTime eventStart = new net.fortuna.ical4j.model.DateTime(makeDateTime("20090203-1000")); eventStart.setTimeZone(americaChicago); DateTime eventEnd = new net.fortuna.ical4j.model.DateTime(makeDateTime("20090203-1030")); eventEnd.setTimeZone(americaChicago); VEvent someEvent = new VEvent(eventStart, eventEnd, "some conflicting appointment"); Attendee attendee = new Attendee(); attendee.setValue("mailto:person@domain.edu"); attendee.getParameters().add(new XParameter("X-ORACLE-SHOWASFREE", "FREE")); attendee.getParameters().add(new Cn("GIVEN SURNAME")); Attendee attendee2 = new Attendee(); attendee2.setValue("mailto:person2@domain.edu"); attendee2.getParameters().add(new Cn("GIVEN2 SURNAME2")); someEvent.getProperties().add(attendee); someEvent.getProperties().add(attendee2); ComponentList components = new ComponentList(); components.add(someEvent); MockCalendarAccount person1 = new MockCalendarAccount(); person1.setEmailAddress("someowner@wisc.edu"); person1.setDisplayName("Some Owner"); MockScheduleOwner owner = new MockScheduleOwner(person1, 1); owner.setPreference(Preferences.DURATIONS, MeetingDurations.FORTYFIVE.getKey()); VisibleSchedule visible = this.builder.calculateVisibleSchedule(makeDateTime("20090202-0830"), makeDateTime("20090206-1600"), new Calendar(components), schedule, owner); Assert.assertEquals(16, visible.getSize()); List<AvailableBlock> free = visible.getFreeList(); Assert.assertEquals(16, free.size()); List<AvailableBlock> busy = visible.getBusyList(); Assert.assertEquals(0, busy.size()); }
From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDao.java
private void removeCompletedIfNotLatest(Stage stage, Map<CaseInsensitiveString, TreeSet<Long>> activePipelinesToIds, CaseInsensitiveString pipelineName) { if (stage.getState().completed()) { if (activePipelinesToIds.containsKey(pipelineName)) { TreeSet<Long> ids = activePipelinesToIds.get(pipelineName); if (!ids.last().equals(stage.getPipelineId())) { ids.remove(stage.getPipelineId()); }/*from w ww. j a v a 2 s . c o m*/ } } }
From source file:net.sourceforge.fenixedu.domain.degree.DegreeType.java
public CycleType getLastOrderedCycleType() { final TreeSet<CycleType> ordered = getOrderedCycleTypes(); return ordered.isEmpty() ? null : ordered.last(); }
From source file:org.jasig.schedassist.model.VisibleScheduleBuilderTest.java
/** * //from w ww . j a v a 2 s . c o m * @throws Exception */ @Test public void testAlternateMeetingDurations() throws Exception { MockCalendarAccount person = new MockCalendarAccount(); person.setEmailAddress("someowner@wisc.edu"); person.setDisplayName("Some Owner"); MockScheduleOwner owner = new MockScheduleOwner(person, 1); // 4 week available schedule Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "12:00 PM", "MRF", makeDateTime("20091102-0000"), makeDateTime("20091127-0000"), 1, null); TreeSet<AvailableBlock> expanded = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 30)); //Assert.assertEquals(72, expanded.size()); LOG.info("expanded set first: " + expanded.first() + ", last: " + expanded.last()); AvailableSchedule schedule = new AvailableSchedule(expanded); // event conflict is thursday of 2nd week DateTime eventStart = new net.fortuna.ical4j.model.DateTime(makeDateTime("20091112-0930")); eventStart.setTimeZone(americaChicago); DateTime eventEnd = new net.fortuna.ical4j.model.DateTime(makeDateTime("20091112-1030")); eventEnd.setTimeZone(americaChicago); VEvent someEvent = new VEvent(eventStart, eventEnd, "some event"); ParameterList parameterList = new ParameterList(); parameterList.add(PartStat.ACCEPTED); parameterList.add(CuType.INDIVIDUAL); parameterList.add(Rsvp.FALSE); parameterList.add(new Cn(person.getDisplayName())); Attendee attendee = new Attendee(parameterList, "mailto:" + person.getEmailAddress()); someEvent.getProperties().add(attendee); ComponentList components = new ComponentList(); components.add(someEvent); VisibleSchedule visible = this.builder.calculateVisibleSchedule(makeDateTime("20091102-0000"), makeDateTime("20091130-0000"), new Calendar(components), schedule, owner); Assert.assertEquals(2, visible.getBusyCount()); Assert.assertEquals(70, visible.getFreeCount()); Assert.assertEquals(72, visible.getSize()); owner.setPreference(Preferences.DURATIONS, MeetingDurations.FIFTEEN.getKey()); TreeSet<AvailableBlock> expanded2 = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 15)); VisibleSchedule visible2 = this.builder.calculateVisibleSchedule(makeDateTime("20091102-0000"), makeDateTime("20091130-0000"), new Calendar(components), new AvailableSchedule(expanded2), owner); Assert.assertEquals(4, visible2.getBusyCount()); Assert.assertEquals(140, visible2.getFreeCount()); Assert.assertEquals(144, visible2.getSize()); owner.setPreference(Preferences.DURATIONS, MeetingDurations.FORTYFIVE.getKey()); TreeSet<AvailableBlock> expanded3 = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 45)); VisibleSchedule visible3 = this.builder.calculateVisibleSchedule(makeDateTime("20091102-0000"), makeDateTime("20091130-0000"), new Calendar(components), new AvailableSchedule(expanded3), owner); Assert.assertEquals(2, visible3.getBusyCount()); Assert.assertEquals(46, visible3.getFreeCount()); Assert.assertEquals(48, visible3.getSize()); }
From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDao.java
private void removeCurrentLatestIfNoLongerActive(Stage stage, TreeSet<Long> ids) { if (!ids.isEmpty()) { if (isNewerThanCurrentLatest(stage, ids) && isCurrentLatestInactive(ids)) { ids.remove(ids.last()); }//w w w . j ava 2 s. c om } }
From source file:org.jasig.schedassist.model.VisibleScheduleBuilderTest.java
/** * Same as {@link #testOffsetStart()}, only use 40 minute blocks. *///from w w w. ja v a2 s . c o m @Test public void testOffsetStart40() throws Exception { MeetingDurations fortyMinuteDurations = new MeetingDurations("40", 40, 40); Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "1:00 PM", "MWF", makeDateTime("20090720-0000"), makeDateTime("20090725-0000"), 1, null); TreeSet<AvailableBlock> expanded = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 40)); Assert.assertEquals(makeDateTime("20090720-0900"), expanded.first().getStartTime()); Assert.assertEquals(makeDateTime("20090720-0940"), expanded.first().getEndTime()); Assert.assertEquals(makeDateTime("20090724-1220"), expanded.last().getStartTime()); Assert.assertEquals(makeDateTime("20090724-1300"), expanded.last().getEndTime()); AvailableSchedule schedule = new AvailableSchedule(expanded); Calendar emptyCalendar = new Calendar(); MockScheduleOwner owner = new MockScheduleOwner(new MockCalendarAccount(), 1); owner.setPreference(Preferences.DURATIONS, fortyMinuteDurations.getKey()); VisibleSchedule control = this.builder.calculateVisibleSchedule(makeDateTime("20090719-0000"), makeDateTime("20090726-0000"), emptyCalendar, schedule, owner); Assert.assertEquals(18, control.getFreeCount()); // verify that all the free blocks start on the twenty minute marks for (AvailableBlock freeBlock : control.getFreeList()) { java.util.Calendar startTimeCal = java.util.Calendar.getInstance(); startTimeCal.setTime(freeBlock.getStartTime()); Assert.assertTrue(startTimeCal.get(java.util.Calendar.MINUTE) % 20 == 0); java.util.Calendar endTimeCal = java.util.Calendar.getInstance(); endTimeCal.setTime(freeBlock.getEndTime()); Assert.assertTrue(endTimeCal.get(java.util.Calendar.MINUTE) % 20 == 0); } // now start the offset in between a block VisibleSchedule startsInBlock = this.builder.calculateVisibleSchedule(makeDateTime("20090720-1005"), makeDateTime("20090727-1005"), emptyCalendar, schedule, owner); Assert.assertEquals(16, startsInBlock.getFreeList().size()); // verify that all the free blocks start on the twenty minute marks for (AvailableBlock freeBlock : startsInBlock.getFreeList()) { java.util.Calendar startTimeCal = java.util.Calendar.getInstance(); startTimeCal.setTime(freeBlock.getStartTime()); Assert.assertTrue(startTimeCal.get(java.util.Calendar.MINUTE) % 20 == 0); java.util.Calendar endTimeCal = java.util.Calendar.getInstance(); endTimeCal.setTime(freeBlock.getEndTime()); Assert.assertTrue(endTimeCal.get(java.util.Calendar.MINUTE) % 20 == 0); } }
From source file:org.jasig.schedassist.model.VisibleScheduleBuilderTest.java
/** * Verify that start and end times of blocks stay consistent for calculateVisibleSchedule. * //from w w w . j av a2s.c o m * @throws Exception */ @Test public void testOffsetStart() throws Exception { Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "1:00 PM", "MWF", makeDateTime("20090720-0000"), makeDateTime("20090725-0000"), 1, null); TreeSet<AvailableBlock> expanded = new TreeSet<AvailableBlock>(AvailableBlockBuilder.expand(blocks, 30)); Assert.assertEquals(makeDateTime("20090720-0900"), expanded.first().getStartTime()); Assert.assertEquals(makeDateTime("20090720-0930"), expanded.first().getEndTime()); Assert.assertEquals(makeDateTime("20090724-1230"), expanded.last().getStartTime()); Assert.assertEquals(makeDateTime("20090724-1300"), expanded.last().getEndTime()); AvailableSchedule schedule = new AvailableSchedule(expanded); Calendar emptyCalendar = new Calendar(); MockScheduleOwner owner = new MockScheduleOwner(new MockCalendarAccount(), 1); owner.setPreference(Preferences.DURATIONS, MeetingDurations.THIRTY.getKey()); VisibleSchedule control = this.builder.calculateVisibleSchedule(makeDateTime("20090719-0000"), makeDateTime("20090726-0000"), emptyCalendar, schedule, owner); Assert.assertEquals(24, control.getFreeCount()); // verify that all the free blocks start on the half hour SortedMap<AvailableBlock, AvailableStatus> blockMap = control.getBlockMap(); for (Entry<AvailableBlock, AvailableStatus> entry : blockMap.entrySet()) { if (AvailableStatus.FREE.equals(entry.getValue())) { AvailableBlock freeBlock = entry.getKey(); java.util.Calendar startTimeCal = java.util.Calendar.getInstance(); startTimeCal.setTime(freeBlock.getStartTime()); Assert.assertTrue(startTimeCal.get(java.util.Calendar.MINUTE) % 30 == 0); java.util.Calendar endTimeCal = java.util.Calendar.getInstance(); endTimeCal.setTime(freeBlock.getEndTime()); Assert.assertTrue(endTimeCal.get(java.util.Calendar.MINUTE) % 30 == 0); } } // now start the offset in between a block VisibleSchedule startsInBlock = this.builder.calculateVisibleSchedule(makeDateTime("20090720-1005"), makeDateTime("20090727-1005"), emptyCalendar, schedule, owner); Assert.assertEquals(21, startsInBlock.getFreeCount()); // verify that all the free blocks start on the half hour SortedMap<AvailableBlock, AvailableStatus> blockMap2 = startsInBlock.getBlockMap(); for (Entry<AvailableBlock, AvailableStatus> entry : blockMap2.entrySet()) { if (AvailableStatus.FREE.equals(entry.getValue())) { AvailableBlock freeBlock = entry.getKey(); java.util.Calendar startTimeCal = java.util.Calendar.getInstance(); startTimeCal.setTime(freeBlock.getStartTime()); Assert.assertTrue(startTimeCal.get(java.util.Calendar.MINUTE) % 30 == 0); java.util.Calendar endTimeCal = java.util.Calendar.getInstance(); endTimeCal.setTime(freeBlock.getEndTime()); Assert.assertTrue(endTimeCal.get(java.util.Calendar.MINUTE) % 30 == 0); } } }
From source file:com.inmobi.conduit.local.LocalStreamService.java
protected String getCurrentFile(FileSystem fs, FileStatus[] files, TreeSet<FileStatus> sortedFiles) { // Proposed Algo :-> Sort files based on timestamp // if there are no files) // then null (implying process this file as non-current file) // else/*from ww w. j a v a 2s. c om*/ // return last file as the current file if (files == null || files.length == 0) return null; for (FileStatus file : files) { sortedFiles.add(file); } // get last file from set FileStatus lastFile = sortedFiles.last(); long diff = (System.currentTimeMillis() - lastFile.getModificationTime()) / MILLISECONDS_IN_MINUTE; if (diff > timeoutToProcessLastCollectorFile) { processLastFile = true; } else { processLastFile = false; } return lastFile.getPath().getName(); }
From source file:biz.netcentric.cq.tools.actool.dumpservice.impl.DumpserviceImpl.java
private void createTransientDumpNode(String dump, Node rootNode) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException, ValueFormatException { NodeIterator nodeIt = rootNode.getNodes(); // TreeSet used here since only this type offers the methods first() and // last()/* w w w . ja v a 2s .c o m*/ TreeSet<Node> dumpNodes = new TreeSet<Node>(new JcrCreatedComparator()); Node previousDumpNode = null; // get all dump nodes while (nodeIt.hasNext()) { Node currNode = nodeIt.nextNode(); if (currNode.getName().startsWith(DUMP_NODE_PREFIX)) { dumpNodes.add(currNode); } } // try to get previous dump node if (!dumpNodes.isEmpty()) { previousDumpNode = dumpNodes.first(); } // is limit of dump nodes to save reached? if (dumpNodes.size() > (nrOfSavedDumps - 1)) { Node oldestDumpNode = dumpNodes.last(); oldestDumpNode.remove(); } Node dumpNode = getNewDumpNode(dump, rootNode); // order the newest dump node as first child node of ac root node if (previousDumpNode != null) { rootNode.orderBefore(dumpNode.getName(), previousDumpNode.getName()); } }
From source file:ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3.java
@Override public Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {/*www .ja va 2 s .com*/ HashSet<ResourceIndexedSearchParamDate> retVal = new HashSet<ResourceIndexedSearchParamDate>(); RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); for (RuntimeSearchParam nextSpDef : def.getSearchParams()) { if (nextSpDef.getParamType() != RestSearchParameterTypeEnum.DATE) { continue; } String nextPath = nextSpDef.getPath(); if (isBlank(nextPath)) { continue; } boolean multiType = false; if (nextPath.endsWith("[x]")) { multiType = true; } for (Object nextObject : extractValues(nextPath, theResource)) { if (nextObject == null) { continue; } ResourceIndexedSearchParamDate nextEntity; if (nextObject instanceof BaseDateTimeType) { BaseDateTimeType nextValue = (BaseDateTimeType) nextObject; if (nextValue.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue()); } else if (nextObject instanceof Period) { Period nextValue = (Period) nextObject; if (nextValue.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getStart(), nextValue.getEnd()); } else if (nextObject instanceof Timing) { Timing nextValue = (Timing) nextObject; if (nextValue.isEmpty()) { continue; } TreeSet<Date> dates = new TreeSet<Date>(); for (DateTimeType nextEvent : nextValue.getEvent()) { if (nextEvent.getValue() != null) { dates.add(nextEvent.getValue()); } } if (dates.isEmpty()) { continue; } nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), dates.first(), dates.last()); } else if (nextObject instanceof StringType) { // CarePlan.activitydate can be a string continue; } else { if (!multiType) { throw new ConfigurationException("Search param " + nextSpDef.getName() + " is of unexpected datatype: " + nextObject.getClass()); } else { continue; } } if (nextEntity != null) { nextEntity.setResource(theEntity); retVal.add(nextEntity); } } } return retVal; }