Example usage for org.joda.time Interval getStartMillis

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

Introduction

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

Prototype

public long getStartMillis() 

Source Link

Document

Gets the start of this time interval which is inclusive.

Usage

From source file:com.metamx.druid.realtime.Sink.java

License:Open Source License

public Sink(Interval interval, Schema schema, List<FireHydrant> hydrants) {
    this.schema = schema;
    this.interval = interval;

    for (int i = 0; i < hydrants.size(); ++i) {
        final FireHydrant hydrant = hydrants.get(i);
        if (hydrant.getCount() != i) {
            throw new ISE("hydrant[%s] not the right count[%s]", hydrant, i);
        }//from  w w  w  . j  a  va  2  s .  co m
    }
    this.hydrants.addAll(hydrants);

    makeNewCurrIndex(interval.getStartMillis(), schema);
}

From source file:com.netflix.fenzo.triggers.IntervalTrigger.java

License:Apache License

/**
 * Creates an interval based trigger//from w w w. j a v  a 2s. c o  m
 * @param iso8601Interval - See https://en.wikipedia.org/wiki/ISO_8601 for how to specify intervals with start time/end
 *                        time/interval
 * @param repeatCount - repeat count after first trigger. Specify -1 to repeat indefinitely
 * @param name
 * @param data
 * @param dataType
 * @param action
 */
@JsonCreator
public IntervalTrigger(@JsonProperty("iso8601Interval") String iso8601Interval,
        @JsonProperty("repeatCount") int repeatCount, @JsonProperty("name") String name,
        @JsonProperty("data") T data, @JsonProperty("dataType") Class<T> dataType,
        @JsonProperty("action") Class<? extends Action1<T>> action) {
    super(name, data, dataType, action, Interval.parse(iso8601Interval).getStart().toDate(), null);
    final Interval jodaInterval = Interval.parse(iso8601Interval);
    this.repeatCount = repeatCount; // -1 is repeat indefinitely
    this.repeatInterval = Interval.parse(iso8601Interval).getEndMillis() - jodaInterval.getStartMillis();
}

From source file:com.peertopark.java.dates.Intervals.java

License:Apache License

public static Collection<Interval> split(Interval interval, Duration duration) {
    ArrayList<Interval> intervals = new ArrayList<Interval>();
    long startMillis = interval.getStartMillis();
    long endMillis = interval.getEndMillis();
    long chunks = interval.toDurationMillis() / duration.getMillis();
    for (int i = 0; i < chunks; i++) {
        long temporalEndMillis = startMillis + duration.getMillis();
        intervals.add(getInterval(startMillis, temporalEndMillis));
        startMillis = temporalEndMillis;
    }/*from   w  w  w.jav a  2s .c  o m*/
    if (startMillis < endMillis) {
        intervals.add(getInterval(startMillis, endMillis));
    }
    return intervals;
}

From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java

License:Apache License

@Override
public List<BuildBean> getAcceptedBuilds(String buildName, String branch, Interval interval, int limit)
        throws Exception {
    ResultSetHandler<List<BuildBean>> h = new BeanListHandler<>(BuildBean.class);
    if (StringUtils.isNotEmpty(branch)) {
        return new QueryRunner(dataSource).query(String.format(GET_ACCEPTED_BUILDS_BETWEEN_TEMPLATE2, buildName,
                branch, interval.getStartMillis(), interval.getEndMillis(), limit), h);
    } else {/*from www .jav a2s  . c  om*/
        return new QueryRunner(dataSource).query(String.format(GET_ACCEPTED_BUILDS_BETWEEN_TEMPLATE, buildName,
                interval.getStartMillis(), interval.getEndMillis(), limit), h);
    }
}

From source file:com.pinterest.deployservice.db.DBDeployDAOImpl.java

License:Apache License

@Override
public List<DeployBean> getAcceptedDeploys(String envId, Interval interval, int size) throws Exception {
    ResultSetHandler<List<DeployBean>> h = new BeanListHandler<>(DeployBean.class);
    String typesClause = QueryUtils.genEnumGroupClause(StateMachines.AUTO_PROMOTABLE_DEPLOY_TYPE);
    return new QueryRunner(dataSource).query(String.format(GET_ACCEPTED_DEPLOYS_TEMPLATE, envId, typesClause,
            interval.getStartMillis(), interval.getEndMillis(), size), h);
}

From source file:com.pinterest.deployservice.db.DBDeployDAOImpl.java

License:Apache License

@Override
public List<DeployBean> getAcceptedDeploysDelayed(String envId, Interval interval) throws Exception {
    ResultSetHandler<List<DeployBean>> h = new BeanListHandler<>(DeployBean.class);
    return new QueryRunner(dataSource).query(String.format(GET_ACCEPTED_DEPLOYS_DELAYED_TEMPLATE, envId,
            interval.getStartMillis(), interval.getEndMillis()), h);
}

From source file:com.sheepdog.mashmesh.models.VolunteerProfile.java

License:Apache License

private List<Interval> getAvailableIntervals(DateTime aroundDateTime) {
    List<Interval> intervals = new ArrayList<Interval>();
    Map<Integer, DateTime> adjacentDays = new HashMap<Integer, DateTime>(3);

    // Construct a map from days of the week to DateTimes representing adjacent days.
    for (int i = -1; i <= 1; i++) {
        DateTime dateTime = aroundDateTime.plusDays(i);
        int day = dateTime.getDayOfWeek();
        adjacentDays.put(day, dateTime);
    }//from   w ww . j  a v a2s.c  o m

    // Construct Intervals from time periods in adjacent days.
    for (AvailableTimePeriod availableTimePeriod : availableTimePeriods) {
        if (adjacentDays.containsKey(availableTimePeriod.getDay())) {
            LocalDate date = adjacentDays.get(availableTimePeriod.getDay()).toLocalDate();
            DateTime start = date.toDateTime(availableTimePeriod.getStartTime(), aroundDateTime.getZone());
            DateTime end = date.toDateTime(availableTimePeriod.getEndTime(), aroundDateTime.getZone());

            // Allow 00:00 - 00:00 to express 00:00 - 24:00 as we can't serialize a
            //  LocalTime representing 24:00.
            if (end.compareTo(start) <= 0) {
                end = end.plusDays(1);
            }

            intervals.add(new Interval(start, end));
        }
    }

    // Sort the Intervals so that adjacent time periods abut. Assumes that intervals don't overlap.
    Collections.sort(intervals, new Comparator<Interval>() {
        @Override
        public int compare(Interval i1, Interval i2) {
            return new Long(i1.getStartMillis()).compareTo(i2.getStartMillis());
        }
    });

    // Merge abutting intervals together
    List<Interval> mergedIntervals = new ArrayList<Interval>();
    Interval lastInterval = null;

    for (Interval interval : intervals) {
        if (lastInterval != null && lastInterval.abuts(interval)) {
            mergedIntervals.remove(mergedIntervals.size() - 1);
            interval = lastInterval.withEnd(interval.getEnd());
        }

        lastInterval = interval;
        mergedIntervals.add(interval);
    }

    return mergedIntervals;
}

From source file:com.yahoo.bard.webservice.util.SimplifiedIntervalList.java

License:Apache License

/**
 * Given a sorted linked list of intervals, add the following interval to the end, merging the incoming interval
 * to any tail intervals which overlap or abut with it.
 * <p>/*  ww w  .  jav  a2s .  co  m*/
 * In the case where added intervals are at the end of the list, this is efficient. In the case where they are not,
 * this degrades to an insertion sort.
 *
 * @param interval  The interval to be merged and added to this list
 */
private void appendWithMerge(Interval interval) {
    // Do not store empty intervals
    if (interval.toDurationMillis() == 0) {
        return;
    }

    if (isEmpty()) {
        addLast(interval);
        return;
    }
    final Interval previous = peekLast();

    // If this interval does not belong at the end, removeLast until it does
    if (interval.getStart().isBefore(previous.getStart())) {
        mergeInner(interval);
        return;
    }

    if (previous.gap(interval) != null) {
        addLast(interval);
        return;
    }
    removeLast();
    Interval newEnd = new Interval(Math.min(previous.getStartMillis(), interval.getStartMillis()),
            Math.max(previous.getEndMillis(), interval.getEndMillis()));
    addLast(newEnd);
}

From source file:de.avanux.smartapplianceenabler.appliance.Schedule.java

License:Open Source License

/**
 * Returns the current or next timeframe if the remaining time is greater than maximum running time; otherwise the next timeframe is returned.
 * @param now the time reference/*w w  w.j av a2s. c o  m*/
 * @param schedules the list of timeframes to choose from (current timeframe has to be first)
 * @param onlyAlreadyStarted consider only timeframe intervals already started
 * @param onlySufficient if true consider timeframe already started only if time to interval end exceeds min running time
 * @return the next timeframe becoming valid or null
 */
public static TimeframeInterval getCurrentOrNextTimeframeInterval(LocalDateTime now, List<Schedule> schedules,
        boolean onlyAlreadyStarted, boolean onlySufficient) {
    if (schedules == null || schedules.size() == 0) {
        return null;
    }
    Map<Long, TimeframeInterval> startDelayOfTimeframeInterval = new TreeMap<>();
    for (Schedule schedule : schedules) {
        Timeframe timeframe = schedule.getTimeframe();
        timeframe.setSchedule(schedule);
        List<TimeframeInterval> timeframeIntervals = timeframe.getIntervals(now);
        for (TimeframeInterval timeframeInterval : timeframeIntervals) {
            Interval interval = timeframeInterval.getInterval();
            if (interval.contains(now.toDateTime())) {
                // interval already started ...
                if (onlySufficient) {
                    if (now.plusSeconds(schedule.getMaxRunningTime()).plusSeconds(additionalRunningTime)
                            .isBefore(new LocalDateTime(interval.getEnd()))) {
                        // ... with remaining running time sufficient
                        return timeframeInterval;
                    }
                } else {
                    return timeframeInterval;
                }
            } else if (!onlyAlreadyStarted) {
                // interval starts in future
                startDelayOfTimeframeInterval.put(interval.getStartMillis() - now.toDateTime().getMillis(),
                        timeframeInterval);
            }
        }
    }
    if (startDelayOfTimeframeInterval.size() > 0) {
        Long startDelay = startDelayOfTimeframeInterval.keySet().iterator().next();
        return startDelayOfTimeframeInterval.get(startDelay);
    }
    return null;
}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.EntityInserter.java

License:Open Source License

private static <T extends StoreClause> T insertTimeInterval(T clause, DateTimePath<Timestamp> startPath,
        DateTimePath<Timestamp> endPath, TimeInterval time) {
    if (time == null) {
        return clause;
    }/*from  w w w.  j  a va  2  s .co  m*/
    Interval interval = time.getInterval();
    clause.set(startPath, new Timestamp(interval.getStartMillis()));
    clause.set(endPath, new Timestamp(interval.getEndMillis()));
    return clause;
}