Example usage for org.joda.time Interval getStart

List of usage examples for org.joda.time Interval getStart

Introduction

In this page you can find the example usage for org.joda.time Interval getStart.

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:org.sleuthkit.autopsy.timeline.ui.VisualizationPanel.java

License:Open Source License

synchronized private void refreshHistorgram() {

    if (histogramTask != null) {
        histogramTask.cancel(true);/*from ww  w  .j av a  2 s  .co m*/
    }

    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:org.sleuthkit.autopsy.timeline.utils.RangeDivisionInfo.java

License:Open Source License

/**
 * Static factory method./*from  ww  w  .j  av  a  2s  .  c  o m*/
 *
 * Determine the period size, number of periods, whole period bounds, and
 * formatters to use to visualize the given timerange.
 *
 * @param timeRange
 *
 * @return
 */
public static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange) {
    //Check from largest to smallest unit

    //TODO: make this more generic... reduce code duplication -jm
    DateTimeFieldType timeUnit;
    final DateTime startWithZone = timeRange.getStart().withZone(TimeLineController.getJodaTimeZone());
    final DateTime endWithZone = timeRange.getEnd().withZone(TimeLineController.getJodaTimeZone());

    if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) {
        timeUnit = DateTimeFieldType.year();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Years.yearsIn(timeRange).get(timeUnit.getDurationType()) + 1,
                TimeUnits.YEARS, ISODateTimeFormat.year(), lower, upper);
    } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) {
        timeUnit = DateTimeFieldType.monthOfYear();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Months.monthsIn(timeRange).getMonths() + 1, TimeUnits.MONTHS,
                DateTimeFormat.forPattern("YYYY'-'MMMM"), lower, upper); // NON-NLS
    } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) {
        timeUnit = DateTimeFieldType.dayOfMonth();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Days.daysIn(timeRange).getDays() + 1, TimeUnits.DAYS,
                DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd"), lower, upper); // NON-NLS
    } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) {
        timeUnit = DateTimeFieldType.hourOfDay();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Hours.hoursIn(timeRange).getHours() + 1, TimeUnits.HOURS,
                DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH"), lower, upper); // NON-NLS
    } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) {
        timeUnit = DateTimeFieldType.minuteOfHour();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Minutes.minutesIn(timeRange).getMinutes() + 1,
                TimeUnits.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm"), lower, upper); // NON-NLS
    } else {
        timeUnit = DateTimeFieldType.secondOfMinute();
        long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis();
        long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis();
        return new RangeDivisionInfo(timeRange, Seconds.secondsIn(timeRange).getSeconds() + 1,
                TimeUnits.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"), lower, upper); // NON-NLS
    }
}

From source file:org.springframework.analytics.metrics.memory.InMemoryAggregateCounter.java

License:Apache License

public AggregateCounter getCounts(Interval interval, AggregateCounterResolution resolution) {
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();//from  w w w. j a  v  a2s  .c o m
    Chronology c = interval.getChronology();

    long[] counts;
    if (resolution == AggregateCounterResolution.minute) {
        List<long[]> days = accumulateDayCounts(minuteCountsByDay, start, end, 60 * 24);

        counts = MetricUtils.concatArrays(days, interval.getStart().getMinuteOfDay(),
                interval.toPeriod().toStandardMinutes().getMinutes() + 1);
    } else if (resolution == AggregateCounterResolution.hour) {
        List<long[]> days = accumulateDayCounts(hourCountsByDay, start, end, 24);

        counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(),
                interval.toPeriod().toStandardHours().getHours() + 1);
    } else if (resolution == AggregateCounterResolution.day) {
        DateTime startDay = new DateTime(c.dayOfYear().roundFloor(start.getMillis()));
        DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis()));
        int nDays = Days.daysBetween(startDay, endDay).getDays();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> yearDays = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis()));

        while (cursor.isBefore(endYear)) {
            long[] dayCounts = dayCountsByYear.get(cursor.getYear());
            if (dayCounts == null) {
                // Querying where we have no data
                dayCounts = new long[daysInYear(cursor.getYear())];
            }
            yearDays.add(dayCounts);
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(yearDays, startDay.getDayOfYear() - 1, nDays);

    } else if (resolution == AggregateCounterResolution.month) {
        DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis()));
        DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis()));
        int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> yearMonths = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis()));

        while (cursor.isBefore(endYear)) {
            long[] monthCounts = monthCountsByYear.get(cursor.getYear());
            if (monthCounts == null) {
                monthCounts = new long[12];
            }
            yearMonths.add(monthCounts);
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(yearMonths, startMonth.getMonthOfYear() - 1, nMonths);
    } else if (resolution == AggregateCounterResolution.year) {
        DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0);
        DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0);
        int nYears = Years.yearsBetween(startYear, endYear).getYears();
        counts = new long[nYears];

        for (int i = 0; i < nYears; i++) {
            long[] monthCounts = monthCountsByYear.get(startYear.plusYears(i).getYear());
            counts[i] = MetricUtils.sum(monthCounts);
        }

    } else {
        throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCounter(this.name, interval, counts, resolution);
}

From source file:org.springframework.analytics.metrics.redis.RedisAggregateCounterRepository.java

License:Apache License

/**
 * For each query, we need to convert the interval into two variations. One is the start and end points rounded to
 * the resolution (used to calculate the number of entries to be returned from the query). The second is the start
 * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying
 * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a
 * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets
 * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the
 * start day as the start index into the first array, and writing the total number of entries in sequence from that
 * point into the combined result counts array.
 *///from  ww  w  .j a v  a2 s.c om
@Override
public AggregateCounter getCounts(String name, Interval interval, AggregateCounterResolution resolution) {

    DateTime end = interval.getEnd();
    Chronology c = interval.getChronology();

    long[] counts;

    if (resolution == AggregateCounterResolution.minute) {
        // Iterate through each hour in the interval and load the minutes for it
        MutableDateTime dt = new MutableDateTime(interval.getStart());
        dt.setRounding(c.hourOfDay());
        Duration step = Duration.standardHours(1);
        List<long[]> hours = new ArrayList<long[]>();
        while (dt.isBefore(end) || dt.isEqual(end)) {
            hours.add(getMinCountsForHour(name, dt));
            dt.add(step);
        }
        counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(),
                interval.toPeriod().toStandardMinutes().getMinutes() + 1);

    } else if (resolution == AggregateCounterResolution.hour) {
        DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis()));
        List<long[]> days = new ArrayList<long[]>();
        Duration step = Duration.standardHours(24);
        while (cursor.isBefore(end)) {
            days.add(getHourCountsForDay(name, cursor));
            cursor = cursor.plus(step);
        }

        counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(),
                interval.toPeriod().toStandardHours().getHours() + 1);

    } else if (resolution == AggregateCounterResolution.day) {
        DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis()));
        DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis()));
        int nDays = Days.daysBetween(startDay, endDay).getDays();
        DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis()));
        List<long[]> months = new ArrayList<long[]>();
        DateTime endMonth = new DateTime(
                c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis()));
        while (cursor.isBefore(endMonth)) {
            months.add(getDayCountsForMonth(name, cursor));
            cursor = cursor.plusMonths(1);
        }

        counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays);
    } else if (resolution == AggregateCounterResolution.month) {
        DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis()));
        DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis()));
        int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> years = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis()));
        while (cursor.isBefore(endYear)) {
            years.add(getMonthCountsForYear(name, cursor));
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths);
    } else if (resolution == AggregateCounterResolution.year) {
        DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0);
        DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0);
        int nYears = Years.yearsBetween(startYear, endYear).getYears();
        Map<String, Long> yearCounts = getYearCounts(name);
        counts = new long[nYears];

        for (int i = 0; i < nYears; i++) {
            int year = startYear.plusYears(i).getYear();
            Long count = yearCounts.get(Integer.toString(year));
            if (count == null) {
                count = 0L;
            }
            counts[i] = count;
        }
    } else {
        throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCounter(name, interval, counts, resolution);
}

From source file:org.springframework.ws.samples.airline.dao.jpa.JpaFlightDao.java

License:Apache License

public List<Flight> findFlights(String fromAirportCode, String toAirportCode, Interval interval,
        ServiceClass serviceClass) throws DataAccessException {
    Query query = entityManager.createQuery("SELECT f FROM Flight f WHERE f.from.code = :fromParam "
            + "AND f.to.code = :toParam AND f.departureTime >= :start AND f.departureTime <= :end AND "
            + "f.serviceClass = :class");
    query.setParameter("fromParam", fromAirportCode);
    query.setParameter("toParam", toAirportCode);
    query.setParameter("start", interval.getStart());
    query.setParameter("end", interval.getEnd());
    query.setParameter("class", serviceClass);
    return query.getResultList();
}

From source file:org.springframework.xd.analytics.metrics.memory.InMemoryAggregateCounter.java

License:Apache License

public AggregateCount getCounts(Interval interval, AggregateCountResolution resolution) {
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();/*from   ww w. j a  va 2 s  .co m*/
    Chronology c = interval.getChronology();

    long[] counts;
    if (resolution == AggregateCountResolution.minute) {
        List<long[]> days = accumulateDayCounts(minuteCountsByDay, start, end, 60 * 24);

        counts = MetricUtils.concatArrays(days, interval.getStart().getMinuteOfDay(),
                interval.toPeriod().toStandardMinutes().getMinutes() + 1);
    } else if (resolution == AggregateCountResolution.hour) {
        List<long[]> days = accumulateDayCounts(hourCountsByDay, start, end, 24);

        counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(),
                interval.toPeriod().toStandardHours().getHours() + 1);
    } else if (resolution == AggregateCountResolution.day) {
        DateTime startDay = new DateTime(c.dayOfYear().roundFloor(start.getMillis()));
        DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis()));
        int nDays = Days.daysBetween(startDay, endDay).getDays();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> yearDays = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis()));

        while (cursor.isBefore(endYear)) {
            long[] dayCounts = dayCountsByYear.get(cursor.getYear());
            if (dayCounts == null) {
                // Querying where we have no data
                dayCounts = new long[daysInYear(cursor.getYear())];
            }
            yearDays.add(dayCounts);
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(yearDays, startDay.getDayOfYear() - 1, nDays);

    } else if (resolution == AggregateCountResolution.month) {
        DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis()));
        DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis()));
        int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> yearMonths = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis()));

        while (cursor.isBefore(endYear)) {
            long[] monthCounts = monthCountsByYear.get(cursor.getYear());
            if (monthCounts == null) {
                monthCounts = new long[12];
            }
            yearMonths.add(monthCounts);
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(yearMonths, startMonth.getMonthOfYear() - 1, nMonths);
    } else if (resolution == AggregateCountResolution.year) {
        DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0);
        DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0);
        int nYears = Years.yearsBetween(startYear, endYear).getYears();
        counts = new long[nYears];

        for (int i = 0; i < nYears; i++) {
            long[] monthCounts = monthCountsByYear.get(startYear.plusYears(i).getYear());
            counts[i] = MetricUtils.sum(monthCounts);
        }

    } else {
        throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCount(getName(), interval, counts, resolution);
}

From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java

License:Apache License

/**
 * For each query, we need to convert the interval into two variations. One is the start and end points rounded to
 * the resolution (used to calculate the number of entries to be returned from the query). The second is the start
 * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying
 * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a
 * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets
 * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the
 * start day as the start index into the first array, and writing the total number of entries in sequence from that
 * point into the combined result counts array.
 *///w w  w  .  j  a v  a  2  s .co m
@Override
public AggregateCount getCounts(String name, Interval interval, AggregateCountResolution resolution) {

    DateTime end = interval.getEnd();
    Chronology c = interval.getChronology();

    long[] counts;

    if (resolution == AggregateCountResolution.minute) {
        // Iterate through each hour in the interval and load the minutes for it
        MutableDateTime dt = new MutableDateTime(interval.getStart());
        dt.setRounding(c.hourOfDay());
        Duration step = Duration.standardHours(1);
        List<long[]> hours = new ArrayList<long[]>();
        while (dt.isBefore(end) || dt.isEqual(end)) {
            hours.add(getMinCountsForHour(name, dt));
            dt.add(step);
        }
        counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(),
                interval.toPeriod().toStandardMinutes().getMinutes() + 1);

    } else if (resolution == AggregateCountResolution.hour) {
        DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis()));
        List<long[]> days = new ArrayList<long[]>();
        Duration step = Duration.standardHours(24);
        while (cursor.isBefore(end)) {
            days.add(getHourCountsForDay(name, cursor));
            cursor = cursor.plus(step);
        }

        counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(),
                interval.toPeriod().toStandardHours().getHours() + 1);

    } else if (resolution == AggregateCountResolution.day) {
        DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis()));
        DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis()));
        int nDays = Days.daysBetween(startDay, endDay).getDays();
        DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis()));
        List<long[]> months = new ArrayList<long[]>();
        DateTime endMonth = new DateTime(
                c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis()));
        while (cursor.isBefore(endMonth)) {
            months.add(getDayCountsForMonth(name, cursor));
            cursor = cursor.plusMonths(1);
        }

        counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays);
    } else if (resolution == AggregateCountResolution.month) {
        DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis()));
        DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis()));
        int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths();
        DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis()));
        List<long[]> years = new ArrayList<long[]>();
        DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis()));
        while (cursor.isBefore(endYear)) {
            years.add(getMonthCountsForYear(name, cursor));
            cursor = cursor.plusYears(1);
        }

        counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths);
    } else if (resolution == AggregateCountResolution.year) {
        DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0);
        DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0);
        int nYears = Years.yearsBetween(startYear, endYear).getYears();
        Map<String, Long> yearCounts = getYearCounts(name);
        counts = new long[nYears];

        for (int i = 0; i < nYears; i++) {
            int year = startYear.plusYears(i).getYear();
            Long count = yearCounts.get(Integer.toString(year));
            if (count == null) {
                count = 0L;
            }
            counts[i] = count;
        }
    } else {
        throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCount(name, interval, counts, resolution);
}

From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java

License:Open Source License

private Interval map(final OccupationPeriod occupationPeriod, final Integer w) {
    final Interval startInterval = occupationPeriod.getPeriodInterval();
    final DateTime s = startInterval.getStart().plusWeeks(w - 1);
    final Interval i = new Interval(s, s.plusWeeks(1));
    return intersect(occupationPeriod, i);
}

From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java

License:Open Source License

public Stream<Integer> getWeeks(final Lesson lesson) {
    final SortedSet<Integer> weeks = new TreeSet<Integer>();
    final ExecutionCourse executionCourse = lesson.getExecutionCourse();
    final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft();
    for (final Interval interval : lesson.getAllLessonIntervals()) {
        final Integer week = Weeks.weeksBetween(firstPossibleLessonDay, interval.getStart().toLocalDate())
                .getWeeks() + 1;//  w w w  .  j a v  a2  s .c  o  m
        weeks.add(week);
    }
    return weeks.stream();
}

From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java

License:Open Source License

public SortedSet<Integer> getOccurrenceWeeksAsString(final Lesson lesson) {
    final SortedSet<Integer> weeks = new TreeSet<Integer>();

    final ExecutionCourse executionCourse = lesson.getExecutionCourse();
    final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft();
    final YearMonthDay lastPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getRight();
    for (final Interval interval : lesson.getAllLessonIntervals()) {
        final Integer week = Weeks.weeksBetween(firstPossibleLessonDay, interval.getStart().toLocalDate())
                .getWeeks() + 1;/*from ww w  .j a  va 2 s . c om*/
        weeks.add(week);
    }
    return weeks;
}