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:org.apache.druid.timeline.VersionedIntervalTimeline.java

License:Apache License

public boolean isOvershadowed(Interval interval, VersionType version, ObjectType object) {
    lock.readLock().lock();/* w  w w . ja v a 2 s  . com*/
    try {
        TimelineEntry entry = completePartitionsTimeline.get(interval);
        if (entry != null) {
            final int majorVersionCompare = versionComparator.compare(version, entry.getVersion());
            if (majorVersionCompare == 0) {
                for (PartitionChunk<ObjectType> chunk : entry.partitionHolder) {
                    if (chunk.getObject().overshadows(object)) {
                        return true;
                    }
                }
                return false;
            } else {
                return majorVersionCompare < 0;
            }
        }

        Interval lower = completePartitionsTimeline.floorKey(new Interval(interval.getStart(), DateTimes.MAX));

        if (lower == null || !lower.overlaps(interval)) {
            return false;
        }

        Interval prev = null;
        Interval curr = lower;

        do {
            if (curr == null || //no further keys
                    (prev != null && curr.getStartMillis() > prev.getEndMillis()) //a discontinuity
            ) {
                return false;
            }

            final TimelineEntry timelineEntry = completePartitionsTimeline.get(curr);
            final int versionCompare = versionComparator.compare(version, timelineEntry.getVersion());

            //lower or same version
            if (versionCompare > 0) {
                return false;
            } else if (versionCompare == 0) {
                if (timelineEntry.partitionHolder.stream()
                        .noneMatch(chunk -> chunk.getObject().overshadows(object))) {
                    return false;
                }
            }

            prev = curr;
            curr = completePartitionsTimeline.higherKey(curr);

        } while (interval.getEndMillis() > prev.getEndMillis());

        return true;
    } finally {
        lock.readLock().unlock();
    }
}

From source file:org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat.java

License:Apache License

private static List<List<Interval>> createSplitsIntervals(List<Interval> intervals, int numSplits) {

    long startTime = intervals.get(0).getStartMillis();
    long endTime = startTime;
    long currTime = 0;
    List<List<Interval>> newIntervals = new ArrayList<>();
    long totalTime = 0;
    for (Interval interval : intervals) {
        totalTime += interval.getEndMillis() - interval.getStartMillis();
    }//from   ww  w.j a  va  2  s .  c om
    for (int i = 0, posIntervals = 0; i < numSplits; i++) {
        final long rangeSize = Math.round((double) (totalTime * (i + 1)) / numSplits)
                - Math.round((double) (totalTime * i) / numSplits);
        // Create the new interval(s)
        List<Interval> currentIntervals = new ArrayList<>();
        while (posIntervals < intervals.size()) {
            final Interval interval = intervals.get(posIntervals);
            final long expectedRange = rangeSize - currTime;
            if (interval.getEndMillis() - startTime >= expectedRange) {
                endTime = startTime + expectedRange;
                currentIntervals.add(new Interval(startTime, endTime, ISOChronology.getInstanceUTC()));
                startTime = endTime;
                currTime = 0;
                break;
            }
            endTime = interval.getEndMillis();
            currentIntervals.add(new Interval(startTime, endTime, ISOChronology.getInstanceUTC()));
            currTime += (endTime - startTime);
            startTime = intervals.get(++posIntervals).getStartMillis();
        }
        newIntervals.add(currentIntervals);
    }
    assert endTime == intervals.get(intervals.size() - 1).getEndMillis();
    return newIntervals;
}

From source file:org.apache.hadoop.hive.ql.optimizer.calcite.druid.DruidIntervalUtils.java

License:Apache License

public static long extractTotalTime(List<Interval> intervals) {
    long totalTime = 0;
    for (Interval interval : intervals) {
        totalTime += (interval.getEndMillis() - interval.getStartMillis());
    }/*from   w w w.j a  va2 s. c  o  m*/
    return totalTime;
}

From source file:org.datanucleus.store.types.jodatime.converters.JodaIntervalTimestampsConverter.java

License:Open Source License

public Timestamp[] toDatastoreType(Interval itv) {
    if (itv == null) {
        return null;
    }//from ww  w.ja v a2  s. co  m
    Timestamp[] timestamps = new Timestamp[2];
    timestamps[0] = new Timestamp(itv.getStartMillis());
    timestamps[1] = new Timestamp(itv.getEndMillis());
    return timestamps;
}

From source file:org.datanucleus.store.types.jodatime.rdbms.mapping.JodaIntervalMapping.java

License:Open Source License

/**
 * Method to return the value to be stored in the specified datastore index given the overall value for
 * this java type.//w w  w .j  av  a  2  s .c om
 * @param nucleusCtx NucleusContext
 * @param index The datastore index
 * @param value The overall value for this java type
 * @return The value for this datastore index
 */
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) {
    Interval intvl = (Interval) value;
    if (getNumberOfDatastoreMappings() == 1) {
        return super.getValueForDatastoreMapping(nucleusCtx, index, value);
    } else if (index == 0) {
        return intvl.getStartMillis();
    } else if (index == 1) {
        return intvl.getEndMillis();
    }
    throw new IndexOutOfBoundsException();
}

From source file:org.datanucleus.store.types.jodatime.rdbms.mapping.JodaIntervalMapping.java

License:Open Source License

public void setObject(ExecutionContext ec, PreparedStatement ps, int[] exprIndex, Object value) {
    Interval interval = (Interval) value;

    if (datastoreMappings != null && datastoreMappings.length == 1 && datastoreMappings[0].isStringBased()) {
        if (value == null) {
            getDatastoreMapping(0).setObject(ps, exprIndex[0], null);
        } else {/*from w ww  .  j a va2 s .co m*/
            // String column
            TypeConverter conv = ec.getNucleusContext().getTypeManager().getTypeConverterForType(Interval.class,
                    String.class);
            if (conv != null) {
                getDatastoreMapping(0).setObject(ps, exprIndex[0], conv.toDatastoreType(value));
            } else {
                throw new NucleusUserException("This type doesn't support persistence as a String");
            }
        }
    } else {
        // Timestamp columns
        if (interval == null) {
            getDatastoreMapping(0).setObject(ps, exprIndex[0], null);
            getDatastoreMapping(1).setObject(ps, exprIndex[1], null);
        } else {
            getDatastoreMapping(0).setObject(ps, exprIndex[0], new Timestamp(interval.getStartMillis()));
            getDatastoreMapping(1).setObject(ps, exprIndex[1], new Timestamp(interval.getEndMillis()));
        }
    }
}

From source file:org.estatio.dom.lease.InvoicingFrequency.java

License:Apache License

private LocalDate dueDateOfInterval(final Interval interval) {
    if (interval == null) {
        return null;
    }/*w  ww  .j a  va2  s  . c o  m*/
    return paidIn == PaidIn.ADVANCE ? new LocalDate(interval.getStartMillis())
            : new LocalDate(interval.getEndMillis()).minusDays(1);
}

From source file:org.estatio.dom.valuetypes.AbstractInterval.java

License:Apache License

public AbstractInterval(final Interval interval) {
    if (interval == null) {
        throw new IllegalArgumentException("interval cannot be null");
    }/*from www .  j av  a 2s. co  m*/
    startDate = IntervalUtil.toLocalDate(interval.getStartMillis());
    endDate = IntervalUtil.toLocalDate(interval.getEndMillis());
}

From source file:org.estatio.dscm.dom.playlist.Playlist.java

License:Apache License

@Programmatic
public List<LocalDateTime> nextOccurences(LocalDate endDate) {
    List<LocalDateTime> nextList = new ArrayList<LocalDateTime>();
    final LocalDate start = getStartDate().isBefore(clockService.now()) ? clockService.now() : getStartDate();
    final LocalDate end = ObjectUtils.min(endDate, getEndDate());

    if (end.compareTo(start) >= 0 && end.compareTo(clockService.now()) >= 0) {
        List<Interval> intervals = CalendarUtils.intervalsInRange(start, end, getRepeatRule());

        for (Interval interval : intervals) {
            nextList.add(/*  w  ww. ja va2 s  .c om*/
                    new LocalDateTime(interval.getStartMillis()).withHourOfDay(getStartTime().getHourOfDay())
                            .withMinuteOfHour(getStartTime().getMinuteOfHour()));
        }
    }

    return nextList;
}

From source file:org.fenixedu.spaces.ui.services.OccupationService.java

License:Open Source License

public String exportEvents(Occupation occupation) {
    JsonArray events = new JsonArray();
    for (final Interval i : occupation.getIntervals()) {
        JsonObject event = new JsonObject();
        event.addProperty("start", i.getStartMillis() / 1000);
        event.addProperty("end", i.getEndMillis() / 1000);
        events.add(event);/*from   w ww  .jav  a  2s.c  o  m*/
    }
    return events.toString();
}