List of usage examples for org.joda.time Interval getEndMillis
public long getEndMillis()
From source file:org.apache.hadoop.hive.druid.HiveDruidQueryBasedInputFormat.java
License:Apache License
private static List<List<Interval>> createSplitsIntervals(List<Interval> intervals, int numSplits) { final long totalTime = DruidDateTimeUtils.extractTotalTime(intervals); long startTime = intervals.get(0).getStartMillis(); long endTime = startTime; long currTime = 0; List<List<Interval>> newIntervals = new ArrayList<>(); 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;/*from w ww.j a v a2 s .com*/ 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.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(); }/* w w w . j a va 2s .c o m*/ 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 ww w .jav a 2s. c om 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; }/*w w w . j a v a2 s. com*/ 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.// ww w . ja v a 2 s .co m * @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 w w . j a va 2 s . com // 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; }//from www. j a v a 2s . c om 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 w w w . j a v a 2 s .com*/ startDate = IntervalUtil.toLocalDate(interval.getStartMillis()); endDate = IntervalUtil.toLocalDate(interval.getEndMillis()); }
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);// ww w .j ava2 s .c o m } return events.toString(); }
From source file:org.gephi.desktop.timeline.TickGraph.java
License:Open Source License
private void drawDate(Graphics2D g) { int width = parameters.getWidth(); int height = parameters.getHeight(); //Font/*from w w w . j a va 2s . c o m*/ int fontSize = Math.min(parameters.getFontSize(), (int) (height / 4.)); fontSize = fontSize > parameters.getFontSize() / 4 && fontSize <= parameters.getFontSize() / 2 ? parameters.getFontSize() / 2 : fontSize; FontMetrics smallMetrics = null; Font smallFont = parameters.getFont(); Font bigFont; FontMetrics bigMetrics; if (smallFont != null && fontSize > parameters.getFontSize() / 4) { smallFont = smallFont.deriveFont(Font.PLAIN, fontSize); smallMetrics = g.getFontMetrics(smallFont); bigFont = smallFont.deriveFont(Font.PLAIN, (int) (fontSize * 2.5)); bigMetrics = g.getFontMetrics(bigFont); } else { smallFont = null; bigFont = null; } DateTick dateTick = DateTick.create(min, max, width); int TOP_TICK = 0; int LOWER_TICK = 1; //Lower tick if (dateTick.getTypeCount() > 1) { g.setFont(smallFont); g.setColor(parameters.getDateColor(LOWER_TICK)); Interval[] intervals = dateTick.getIntervals(LOWER_TICK); int labelWidth = smallMetrics != null ? smallMetrics.stringWidth("0000") : 0; for (Interval interval : intervals) { long ms = interval.getStartMillis(); int x = dateTick.getTickPixelPosition(ms, width); if (x >= 0) { g.setColor(parameters.getDateColor(LOWER_TICK)); //Height int h = (int) (Math.min(40, (int) (height / 15.0))); //Draw line g.drawLine(x, 0, x, h); //Label if (smallFont != null && width / intervals.length > labelWidth) { String label = dateTick.getTickValue(LOWER_TICK, interval.getStart()); int xLabel = x + 4; g.setColor(parameters.getDateColor(1)); int y = (int) (fontSize * 1.2); g.drawString(label, xLabel, y); } } } } //Top tick if (dateTick.getTypeCount() > 0) { g.setFont(bigFont); g.setColor(parameters.getDateColor(TOP_TICK)); Interval[] intervals = dateTick.getIntervals(TOP_TICK); for (Interval interval : intervals) { long ms = interval.getStartMillis(); int x = dateTick.getTickPixelPosition(ms, width); if (x >= 0) { g.setColor(parameters.getDateColor(TOP_TICK)); //Height int h = height; //Draw Line g.drawLine(x, 0, x, h); //Label if (bigFont != null) { String label = dateTick.getTickValue(TOP_TICK, interval.getStart()); int xLabel = x + 4; g.setColor(parameters.getDateColor(TOP_TICK)); int y = (int) (fontSize * 4); g.drawString(label, xLabel, y); } } else if (x > ((dateTick.getTickPixelPosition(interval.getEndMillis(), width) - x) / -2)) { if (bigFont != null) { String label = dateTick.getTickValue(TOP_TICK, interval.getStart()); g.setColor(parameters.getDateColor(TOP_TICK)); int y = (int) (fontSize * 4); g.drawString(label, 4, y); } } } } }