List of usage examples for org.joda.time Interval contains
public boolean contains(long millisInstant)
From source file:org.opentestsystem.delivery.testadmin.domain.Proctor.java
License:Open Source License
public boolean isAvailableForTimeSlot(final TimeSlot timeSlot) { // if the user has not setup any availability windows just return true so the proctor can be scheduled if (this.availabilityWindow == null || this.availabilityWindow.isEmpty()) { return true; }/*from ww w . j av a 2s .c o m*/ final Interval timeSlotInterval = new Interval(timeSlot.getStartTime(), timeSlot.getEndTime()); boolean passesAvailable = false; boolean passesUnavailable = true; for (final AvailabilityWindow window : this.availabilityWindow) { if (!passesAvailable || passesUnavailable) { final Interval windowInterval = new Interval(window.getStartDateTime(), window.getEndDateTime()); if (Availability.AVAILABLE == window.getAvailability()) { if (windowInterval.contains(timeSlotInterval)) { passesAvailable = true; } } else if (Availability.NOTAVAILABLE == window.getAvailability()) { if (windowInterval.contains(timeSlotInterval) || windowInterval.overlaps(timeSlotInterval)) { passesUnavailable = false; } } } } return passesAvailable && passesUnavailable; }
From source file:org.powertac.du.DefaultBrokerService.java
License:Apache License
private boolean activeContract(DateTime startDate) { for (Contract c : activeContracts.values()) { Interval interval = new Interval(c.getStartDate(), c.getEndDate()); if (interval.contains(new DateTime(startDate))) { return true; }/*from ww w . j a va 2 s . c om*/ } return false; }
From source file:org.projectbuendia.client.ui.dialogs.OrderExecutionDialogFragment.java
License:Apache License
/** Creates a new instance and registers the given UI, if specified. */ public static OrderExecutionDialogFragment newInstance(Order order, Interval interval, List<DateTime> executionTimes) { Bundle args = new Bundle(); args.putString("orderUuid", order.uuid); args.putString("instructions", order.instructions); args.putLong("orderStartMillis", order.start.getMillis()); args.putLong("intervalStartMillis", interval.getStartMillis()); args.putLong("intervalStopMillis", interval.getEndMillis()); List<Long> millis = new ArrayList<>(); for (DateTime dt : executionTimes) { if (interval.contains(dt)) { millis.add(dt.getMillis());//from w w w.j ava 2 s . c o m } } args.putLongArray("executionTimes", Utils.toArray(millis)); // To avoid the possibility of confusion when the dialog is opened just // before midnight, save the current time for use as the encounter time later. DateTime encounterTime = DateTime.now(); args.putLong("encounterTimeMillis", encounterTime.getMillis()); args.putBoolean("editable", interval.contains(encounterTime)); OrderExecutionDialogFragment f = new OrderExecutionDialogFragment(); f.setArguments(args); return f; }
From source file:org.sleuthkit.autopsy.timeline.ui.countsview.CountsViewPane.java
License:Open Source License
@Override protected Task<Boolean> getUpdateTask() { return new LoggedTask<Boolean>(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.name"), true) {// w ww . java2 s . c o m @Override protected Boolean call() throws Exception { if (isCancelled()) { return null; } updateProgress(-1, 1); updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.prepUpdate")); Platform.runLater(() -> { setCursor(Cursor.WAIT); }); final RangeDivisionInfo rangeInfo = RangeDivisionInfo .getRangeDivisionInfo(filteredEvents.timeRange().get()); chart.setRangeInfo(rangeInfo); //extend range to block bounderies (ie day, month, year) final long lowerBound = rangeInfo.getLowerBound(); final long upperBound = rangeInfo.getUpperBound(); final Interval timeRange = new Interval( new DateTime(lowerBound, TimeLineController.getJodaTimeZone()), new DateTime(upperBound, TimeLineController.getJodaTimeZone())); int max = 0; int p = 0; // progress counter //clear old data, and reset ranges and series Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.resetUI")); eventTypeMap.clear(); dataSets.clear(); dateAxis.getCategories().clear(); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { //add bar/'category' label for the current interval final String dateString = start.toString(rangeInfo.getTickFormatter()); dateAxis.getCategories().add(dateString); //increment for next iteration start = start.plus(rangeInfo.getPeriodSize().getPeriod()); } //make all series to ensure they get created in consistent order EventType.allTypes.forEach(CountsViewPane.this::getSeries); }); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { final String dateString = start.toString(rangeInfo.getTickFormatter()); DateTime end = start.plus(rangeInfo.getPeriodSize().getPeriod()); final Interval interval = new Interval(start, end); //query for current range Map<EventType, Long> eventCounts = filteredEvents.getEventCounts(interval); //increment for next iteration start = end; int dateMax = 0; //used in max tracking //for each type add data to graph for (final EventType et : eventCounts.keySet()) { if (isCancelled()) { return null; } final Long count = eventCounts.get(et); final int fp = p++; if (count > 0) { final double adjustedCount = count == 0 ? 0 : scale.get().adjust(count); dateMax += adjustedCount; final XYChart.Data<String, Number> xyData = new BarChart.Data<>(dateString, adjustedCount); xyData.nodeProperty().addListener((Observable o) -> { final Node node = xyData.getNode(); if (node != null) { node.setStyle("-fx-border-width: 2; -fx-border-color: " + ColorUtilities.getRGBCode(et.getSuperType().getColor()) + "; -fx-bar-fill: " + ColorUtilities.getRGBCode(et.getColor())); // NON-NLS node.setCursor(Cursor.HAND); node.setOnMouseEntered((MouseEvent event) -> { //defer tooltip creation till needed, this had a surprisingly large impact on speed of loading the chart final Tooltip tooltip = new Tooltip( NbBundle.getMessage(this.getClass(), "CountsViewPane.tooltip.text", count, et.getDisplayName(), dateString, interval.getEnd().toString(rangeInfo.getTickFormatter()))); tooltip.setGraphic(new ImageView(et.getFXImage())); Tooltip.install(node, tooltip); node.setEffect(new DropShadow(10, et.getColor())); }); node.setOnMouseExited((MouseEvent event) -> { if (selectedNodes.contains(node)) { node.setEffect(SELECTED_NODE_EFFECT); } else { node.setEffect(null); } }); node.addEventHandler(MouseEvent.MOUSE_CLICKED, new BarClickHandler(node, dateString, interval, et)); } }); max = Math.max(max, dateMax); final double fmax = max; Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.updatingCounts")); getSeries(et).getData().add(xyData); if (scale.get().equals(ScaleType.LINEAR)) { countAxis.setTickUnit( Math.pow(10, Math.max(0, Math.floor(Math.log10(fmax)) - 1))); } else { countAxis.setTickUnit(Double.MAX_VALUE); } countAxis.setUpperBound(1 + fmax * 1.2); layoutDateLabels(); updateProgress(fp, rangeInfo.getPeriodsInRange()); }); } else { final double fmax = max; Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.updatingCounts")); updateProgress(fp, rangeInfo.getPeriodsInRange()); }); } } } Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.wrappingUp")); updateProgress(1, 1); layoutDateLabels(); setCursor(Cursor.NONE); }); return max > 0; } }; }
From source file:org.sleuthkit.autopsy.timeline.ui.ViewFrame.java
License:Open Source License
/** * Refresh the Histogram to represent the current state of the DB. *//* w ww.j a v a2s. c o m*/ @NbBundle.Messages({ "ViewFrame.histogramTask.title=Rebuilding Histogram", "ViewFrame.histogramTask.preparing=Preparing", "ViewFrame.histogramTask.resetUI=Resetting UI", "ViewFrame.histogramTask.queryDb=Querying FB", "ViewFrame.histogramTask.updateUI2=Updating UI" }) synchronized private void refreshHistorgram() { if (histogramTask != null) { histogramTask.cancel(true); } histogramTask = new LoggedTask<Void>(Bundle.ViewFrame_histogramTask_title(), true) { private final Lighting lighting = new Lighting(); @Override protected Void call() throws Exception { updateMessage(ViewFrame_histogramTask_preparing()); long max = 0; final RangeDivisionInfo rangeInfo = RangeDivisionInfo .getRangeDivisionInfo(filteredEvents.getSpanningInterval()); final long lowerBound = rangeInfo.getLowerBound(); final long upperBound = rangeInfo.getUpperBound(); Interval timeRange = new Interval(new DateTime(lowerBound, TimeLineController.getJodaTimeZone()), new DateTime(upperBound, TimeLineController.getJodaTimeZone())); //extend range to block bounderies (ie day, month, year) int p = 0; // progress counter //clear old data, and reset ranges and series Platform.runLater(() -> { updateMessage(ViewFrame_histogramTask_resetUI()); }); ArrayList<Long> bins = new ArrayList<>(); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { if (isCancelled()) { return null; } DateTime end = start.plus(rangeInfo.getPeriodSize().getPeriod()); final Interval interval = new Interval(start, end); //increment for next iteration start = end; updateMessage(ViewFrame_histogramTask_queryDb()); //query for current range long count = filteredEvents.getEventCounts(interval).values().stream().mapToLong(Long::valueOf) .sum(); bins.add(count); max = Math.max(count, max); final double fMax = Math.log(max); final ArrayList<Long> fbins = new ArrayList<>(bins); Platform.runLater(() -> { updateMessage(ViewFrame_histogramTask_updateUI2()); histogramBox.getChildren().clear(); for (Long bin : fbins) { if (isCancelled()) { break; } Region bar = new Region(); //scale them to fit in histogram height bar.prefHeightProperty() .bind(histogramBox.heightProperty().multiply(Math.log(bin)).divide(fMax)); bar.setMaxHeight(USE_PREF_SIZE); bar.setMinHeight(USE_PREF_SIZE); bar.setBackground(GRAY_BACKGROUND); bar.setOnMouseEntered((MouseEvent event) -> { Tooltip.install(bar, new Tooltip(bin.toString())); }); bar.setEffect(lighting); //they each get equal width to fill the histogram horizontally HBox.setHgrow(bar, Priority.ALWAYS); histogramBox.getChildren().add(bar); } }); } return null; } }; new Thread(histogramTask).start(); controller.monitorTask(histogramTask); }
From source file:org.sleuthkit.autopsy.timeline.ui.VisualizationPanel.java
License:Open Source License
synchronized private void refreshHistorgram() { if (histogramTask != null) { histogramTask.cancel(true);// ww w . j a v a2 s . c om } histogramTask = new LoggedTask<Void>( NbBundle.getMessage(this.getClass(), "VisualizationPanel.histogramTask.title"), true) { @Override protected Void call() throws Exception { updateMessage(NbBundle.getMessage(this.getClass(), "VisualizationPanel.histogramTask.preparing")); long max = 0; final RangeDivisionInfo rangeInfo = RangeDivisionInfo .getRangeDivisionInfo(filteredEvents.getSpanningInterval()); final long lowerBound = rangeInfo.getLowerBound(); final long upperBound = rangeInfo.getUpperBound(); Interval timeRange = new Interval(new DateTime(lowerBound, TimeLineController.getJodaTimeZone()), new DateTime(upperBound, TimeLineController.getJodaTimeZone())); //extend range to block bounderies (ie day, month, year) int p = 0; // progress counter //clear old data, and reset ranges and series Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "VisualizationPanel.histogramTask.resetUI")); }); ArrayList<Long> bins = new ArrayList<>(); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { if (isCancelled()) { return null; } DateTime end = start.plus(rangeInfo.getPeriodSize().getPeriod()); final Interval interval = new Interval(start, end); //increment for next iteration start = end; updateMessage(NbBundle.getMessage(this.getClass(), "VisualizationPanel.histogramTask.queryDb")); //query for current range long count = filteredEvents.getEventCounts(interval).values().stream().mapToLong(Long::valueOf) .sum(); bins.add(count); max = Math.max(count, max); final double fMax = Math.log(max); final ArrayList<Long> fbins = new ArrayList<>(bins); Platform.runLater(() -> { updateMessage( NbBundle.getMessage(this.getClass(), "VisualizationPanel.histogramTask.updateUI2")); histogramBox.getChildren().clear(); for (Long bin : fbins) { if (isCancelled()) { break; } Region bar = new Region(); //scale them to fit in histogram height bar.prefHeightProperty() .bind(histogramBox.heightProperty().multiply(Math.log(bin)).divide(fMax)); bar.setMaxHeight(USE_PREF_SIZE); bar.setMinHeight(USE_PREF_SIZE); bar.setBackground(background); bar.setOnMouseEntered((MouseEvent event) -> { Tooltip.install(bar, new Tooltip(bin.toString())); }); bar.setEffect(lighting); //they each get equal width to fill the histogram horizontally HBox.setHgrow(bar, Priority.ALWAYS); histogramBox.getChildren().add(bar); } }); } return null; } }; new Thread(histogramTask).start(); controller.monitorTask(histogramTask); }
From source file:pt.ist.fenixedu.integration.api.infra.FenixAPIFromExternalServer.java
License:Open Source License
public static String getCanteen(String daySearch, String canteenName) { String canteenUrl = FenixEduIstIntegrationConfiguration.getConfiguration().getFenixApiCanteenUrl() .concat("?name=" + canteenName); JsonObject canteenInfo = getInformation(canteenUrl); String lang = I18N.getLocale().toLanguageTag(); if (!canteenInfo.has(lang)) { return empty.toString(); }/* w w w. j a v a 2s . co m*/ JsonArray jsonArrayWithLang = canteenInfo.getAsJsonObject().getAsJsonArray(lang); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } Interval validInterval = new Interval(dayToCompareStart, dayToCompareEnd); JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (validInterval.contains(dateToCompare)) { jsonResult.add(jObj); } } return gson.toJson(jsonResult); }
From source file:pt.ist.fenixedu.integration.api.OldNewsSyncService.java
License:Open Source License
@GET @Produces("application/xml") public Response get(@QueryParam("announcementBoardId") String announcementBoardId, @QueryParam("selectedYear") int selectedYear, @QueryParam("selectedMonth") int selectedMonth, @QueryParam("language") String language) { Set<Post> posts;// w w w. java 2 s. co m if (announcementBoardId.equals(EVENTS)) { posts = Site.fromSlug("tecnicolisboa").categoryForSlug("eventos").getPostsSet(); } else { posts = Site.fromSlug("tecnicolisboa").categoryForSlug("noticias").getPostsSet(); } Locale locale; if ("pt".equals(language)) { locale = PT; } else { locale = EN; } DateTime begin = new DateTime().toDateMidnight().withYear(selectedYear).withMonthOfYear(selectedMonth) .withDayOfMonth(1).toDateTime(); DateTime end = begin.dayOfMonth().withMaximumValue().hourOfDay().withMaximumValue().minuteOfHour() .withMaximumValue().secondOfMinute().withMaximumValue(); Interval i = new Interval(begin, end); Category stickyCategory = Bennu.getInstance().getDefaultSite().categoryForSlug("sticky"); String result = "SUCCESS\n"; result += "<list>\n"; int index = 1; for (Post post : posts.stream().sorted(Post.CREATION_DATE_COMPARATOR) .filter(x -> i.contains(x.getPublicationBegin())).filter(x -> x.getActive()) .collect(Collectors.toList())) { result += " <net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementDTO>\n"; result += " <creationDate>" + post.getCreationDate().toString("dd/MM/yyyy HH:mm:ss") + "</creationDate>\n"; result += " <referedSubjectBegin>" + (post.getPublicationBegin() != null ? post.getPublicationBegin().toString("dd/MM/yyyy HH:mm:ss") : "") + "</referedSubjectBegin>\n"; result += " <publicationBegin>" + (post.getPublicationBegin() != null ? post.getPublicationBegin().toString("dd/MM/yyyy HH:mm:ss") : "") + "</publicationBegin>\n"; result += " <publicationEnd>" + (post.getPublicationEnd() != null ? post.getPublicationEnd().toString("dd/MM/yyyy HH:mm:ss") : "") + "</publicationEnd>\n"; result += " <lastModification>" + (post.getModificationDate() != null ? post.getModificationDate().toString("dd/MM/yyyy HH:mm:ss") : "") + "</lastModification>\n"; result += " <subject><![CDATA[" + post.getName().getContent(locale) + "]]></subject>\n"; result += " <keywords></keywords>\n"; result += " <body><![CDATA[" + post.getBody().getContent(locale) + "]]></body>\n"; result += " <author>GCRP</author>\n"; result += " <authorEmail>gcrp@ist.utl.pt</authorEmail>\n"; result += " <place></place>"; result += " <visible>" + post.isVisible() + "</visible>\n"; result += " <id>" + post.getExternalId() + "</id>\n"; result += " <photoUrl></photoUrl>\n"; result += " <campus>Alameda</campus>\n"; result += " <categories/>\n"; result += " <pressRelease>false</pressRelease>\n"; result += " <sticky>" + post.getCategoriesSet().contains(stickyCategory) + "</sticky>\n"; result += " <priority>" + index++ + "</priority>\n"; result += " </net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementDTO>\n"; } result += "</list>"; return Response.ok(result).build(); }
From source file:pt.ist.fenixedu.teacher.domain.TeacherCredits.java
License:Open Source License
private static boolean isSabbaticalForSemester(Teacher teacher, Interval exemptionInterval, Interval semesterPeriod) { double overlapPercentageThisSemester = calculateLessonsIntervalAndExemptionOverlapPercentage(semesterPeriod, exemptionInterval);/*from w w w . j a va2 s. co m*/ if (overlapPercentageThisSemester == 1) { return true; } if (semesterPeriod.contains(exemptionInterval.getStart())) { return overlapPercentageThisSemester >= 0.5; } ExecutionSemester firstExecutionPeriod = ExecutionSemester.readByDateTime(exemptionInterval.getStart()); Interval firstExecutionPeriodInterval = new Interval( firstExecutionPeriod.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(), firstExecutionPeriod.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay()); double overlapPercentageFirstSemester = calculateLessonsIntervalAndExemptionOverlapPercentage( firstExecutionPeriodInterval, exemptionInterval); return overlapPercentageFirstSemester < 0.5; }
From source file:sg.atom.managex.api.net.telnet.TelnetServerHandler.java
License:Apache License
private String getMessages(DateTime start, DateTime end) { final Interval interval = new Interval(start, end); ImmutableList<Message> filteredMessages = ImmutableList .copyOf(Iterables.filter(messages, new Predicate<Message>() { @Override/* ww w.jav a 2s .c om*/ public boolean apply(Message msg) { return interval.contains(msg.time); } })); return Strings.join("\r\n", Lists.transform(filteredMessages, toLineFunction)); }