List of usage examples for java.util SortedSet subSet
SortedSet<E> subSet(E fromElement, E toElement);
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.subSet(Object, Object)'. * * @see java.util.SortedSet#subSet(Object, Object) *///from w w w .j a va 2 s. c o m @SuppressWarnings("unchecked") public void testSubMap_throwsClassCastException() { SortedSet SortedSet = createNavigableSet(); SortedSet.add(getKeys()[0]); try { SortedSet.subSet(getConflictingKey(), getKeys()[0]); assertTrue("CCE expected in Development Mode", !TestUtils.isJvm()); } catch (IllegalArgumentException e) { // since we can't ensure CCEs in Production Mode, we may get IAE assertTrue("IllegalArgumentException in Development Mode", !TestUtils.isJvm()); } catch (ClassCastException e) { // expected outcome } try { SortedSet.subSet(getKeys()[0], getConflictingKey()); assertTrue("CCE expected in Development Mode", !TestUtils.isJvm()); } catch (IllegalArgumentException e) { // since we can't ensure CCEs in Production Mode, we may get IAE assertTrue("IllegalArgumentException in Development Mode", !TestUtils.isJvm()); } catch (ClassCastException e) { // expected outcome } }
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.subSet(Object, Object)'. * * @see java.util.SortedSet#subSet(Object, Object) *//* w w w .j a v a 2s . c o m*/ public void testSubMap_throwsIllegalArgumentException() { SortedSet<E> SortedSet = createNavigableSet(); try { SortedSet.subSet(getGreaterThanMaximumKey(), getLessThanMinimumKey()); fail("expected exception"); } catch (IllegalArgumentException e) { // from key is greater than the to key // expected outcome } }
From source file:org.jasig.schedassist.model.VisibleScheduleBuilder.java
@Override public VisibleSchedule calculateVisibleSchedule(final Date startTime, final Date endTime, final Calendar calendar, final AvailableSchedule schedule, final IScheduleOwner owner, final IScheduleVisitor visitor) { Validate.notNull(startTime, "startTime cannot be null"); Validate.notNull(endTime, "endTime cannot be null"); Validate.notNull(calendar, "calendar cannot be null"); Validate.notNull(schedule, "available schedule cannot be null"); Validate.notNull(owner, "owner cannot be null"); ICalendarAccount visitorCalendarAccount = null; if (visitor != null) { visitorCalendarAccount = visitor.getCalendarAccount(); }/*from w ww .jav a 2 s . com*/ if (endTime.before(startTime)) { throw new IllegalArgumentException( "cannot pass end time (" + endTime + ") that is before start time (" + startTime + ")"); } LOG.debug("startTime: " + startTime + "; endTime: " + endTime); final MeetingDurations durations = owner.getPreferredMeetingDurations(); // expand the passed in schedule's availableBlocks SortedSet<AvailableBlock> availableBlocks = AvailableBlockBuilder.expand(schedule.getAvailableBlocks(), durations.getMinLength()); // create endpoints for the subset of availableBlocks AvailableBlock availabilityStartBlock = AvailableBlockBuilder.createPreferredMinimumDurationBlock(startTime, durations); AvailableBlock availabilityEndBlock = AvailableBlockBuilder.createPreferredMinimumDurationBlock(endTime, durations); // trim the availableBlocks set to within startTime/endTime availableBlocks = availableBlocks.subSet(availabilityStartBlock, availabilityEndBlock); // construct our return value VisibleSchedule visibleSchedule = new VisibleSchedule(durations); // add the trimmed availableSchedule to the visibleSchedule as "FREE" blocks visibleSchedule.addFreeBlocks(availableBlocks); // now iterate through the schedule and construct blocks to overwrite in the visibleSchedul ComponentList events = calendar.getComponents(Component.VEVENT); for (Object component : events) { VEvent event = (VEvent) component; boolean causesConflict = this.eventUtils.willEventCauseConflict(owner.getCalendarAccount(), event); if (!causesConflict) { if (LOG.isDebugEnabled()) { LOG.debug("event will not cause conflict, skipping: " + event); } continue; } // if we reach this point, this event is not skippable, // it's going to be either BUSY, FREE with visitors, or ATTENDING if (eventUtils.isEventRecurring(event)) { // expand the recurrence rules PeriodList recurrenceList = this.eventUtils.calculateRecurrence(event, startTime, endTime); for (Object o : recurrenceList) { Period period = (Period) o; mutateAppropriateBlockInVisibleSchedule(visibleSchedule, event, owner.getCalendarAccount(), visitorCalendarAccount, period.getStart(), period.getEnd(), true); } } else { // event is not recurring, just check block on start/end Date startDate = event.getStartDate().getDate(); Date endDate = event.getEndDate(true).getDate(); mutateAppropriateBlockInVisibleSchedule(visibleSchedule, event, owner.getCalendarAccount(), visitorCalendarAccount, startDate, endDate, true); } } return visibleSchedule; }
From source file:org.jasig.schedassist.model.VisibleScheduleBuilder.java
/** * /* w ww. j a va 2 s . co m*/ * @param startTime * @param endTime * @param calendar * @param schedule * @param meetingDurations * @param calendarAccount * @return an appropriate {@link VisibleSchedule} */ protected VisibleSchedule calculateVisibleScheduleNoAttendingCheck(Date startTime, Date endTime, Calendar calendar, AvailableSchedule schedule, MeetingDurations meetingDurations, ICalendarAccount calendarAccount) { Validate.notNull(startTime, "startTime cannot be null"); Validate.notNull(endTime, "endTime cannot be null"); Validate.notNull(calendar, "calendar cannot be null"); Validate.notNull(meetingDurations, "MeetingDurations argument cannot be null"); Validate.notNull(schedule, "AvailableSchedule argument cannot be null"); Validate.notNull(calendarAccount, "calendarAccount cannot be null"); if (endTime.before(startTime)) { throw new IllegalArgumentException( "cannot pass end time (" + endTime + ") that is before start time (" + startTime + ")"); } LOG.debug("startTime: " + startTime + "; endTime: " + endTime); // expand the passed in schedule's availableBlocks SortedSet<AvailableBlock> availableBlocks = AvailableBlockBuilder.expand(schedule.getAvailableBlocks(), meetingDurations.getMinLength()); // create endpoints for the subset of availableBlocks AvailableBlock availabilityStartBlock = AvailableBlockBuilder.createPreferredMinimumDurationBlock(startTime, meetingDurations); AvailableBlock availabilityEndBlock = AvailableBlockBuilder.createPreferredMinimumDurationBlock(endTime, meetingDurations); // trim the availableBlocks set to within startTime/endTime availableBlocks = availableBlocks.subSet(availabilityStartBlock, availabilityEndBlock); // construct our return value VisibleSchedule visibleSchedule = new VisibleSchedule(meetingDurations); // add the trimmed availableSchedule to the visibleSchedule as "FREE" blocks visibleSchedule.addFreeBlocks(availableBlocks); // now iterate through the schedule and construct blocks to overwrite in the visibleSchedul ComponentList events = calendar.getComponents(Component.VEVENT); for (Object component : events) { VEvent event = (VEvent) component; boolean causesConflict = this.eventUtils.willEventCauseConflict(calendarAccount, event); if (!causesConflict) { if (LOG.isDebugEnabled()) { LOG.debug("event will not cause conflict, skipping: " + event); } continue; } // if we reach this point, this event is not skippable, // it's going to be either BUSY, FREE with visitors, or ATTENDING // whether event is recurring or not, check block on start/end Date startDate = event.getStartDate().getDate(); Date endDate = event.getEndDate(true).getDate(); mutateAppropriateBlockInVisibleSchedule(visibleSchedule, event, calendarAccount, null, startDate, endDate, false); if (eventUtils.isEventRecurring(event)) { // expand the recurrence rules PeriodList recurrenceList = this.eventUtils.calculateRecurrence(event, startTime, endTime); for (Object o : recurrenceList) { Period period = (Period) o; mutateAppropriateBlockInVisibleSchedule(visibleSchedule, event, calendarAccount, null, period.getStart(), period.getEnd(), false); } } } return visibleSchedule; }
From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java
private static void addTypeTo(final Set<Class<?>> target, final SortedSet<String> sortedSet) { addTypeTo(target, (Collection<?>) sortedSet); addTypeTo(target, (Set<String>) sortedSet.headSet("foo")); addTypeTo(target, (Set<String>) sortedSet.tailSet("foo")); addTypeTo(target, (Set<String>) sortedSet.subSet("foo", "foo")); }