/** * Creates a new millisecond. * * @param millisecond the millisecond (0-999). * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Millisecond(int millisecond, int second, int minute, int hour, int day, int month, int year) { this(millisecond, new Second(second, minute, hour, day, month, year)); }
/** * get the second immediately after the input argument. * Note that Second#next() returns incorrect result due to time zone differences. */ public static Second next( Second second) { Date date = new Date( second.getFirstMillisecond() + 1000 ); return new Second( date, TimeZone.getTimeZone( "GMT" ), Locale.getDefault() ); } }
/** * Returns the second preceding this one. * * @return The second preceding this one. */ @Override public RegularTimePeriod previous() { Second result = null; if (this.second != FIRST_SECOND_IN_MINUTE) { result = new Second(this.second - 1, getMinute()); } else { Minute previous = (Minute) getMinute().previous(); if (previous != null) { result = new Second(LAST_SECOND_IN_MINUTE, previous); } } return result; }
private static double getCoveredPart( Second second, long sampleStart, long sampleEnd ) { double firstCovered = Math.max( sampleStart, second.getFirstMillisecond() ); double lastCovered = Math.min( sampleEnd, second.getLastMillisecond() ); return lastCovered - firstCovered + 1; }
/** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); }
/** * Constructs a millisecond. * * @param millisecond the millisecond (0-999). * @param second the second. */ public Millisecond(int millisecond, Second second) { this.millisecond = millisecond; this.second = (byte) second.getSecond(); this.minute = (byte) second.getMinute().getMinute(); this.hour = (byte) second.getMinute().getHourValue(); this.day = second.getMinute().getDay(); peg(Calendar.getInstance()); }
/** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * {@code http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf} * * @return A hashcode. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.millisecond; result = 37 * result + getSecond().hashCode(); return result; }
/** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar ({@code null} not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); }
/** * Constructs a millisecond. * * @param millisecond the millisecond (0-999). * @param second the second. */ public Millisecond(int millisecond, Second second) { this.millisecond = millisecond; this.second = (byte) second.getSecond(); this.minute = (byte) second.getMinute().getMinute(); this.hour = (byte) second.getMinute().getHourValue(); this.day = second.getMinute().getDay(); peg(Calendar.getInstance()); }
/** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hashcode. */ public int hashCode() { int result = 17; result = 37 * result + this.millisecond; result = 37 * result + getSecond().hashCode(); return result; }
/** * Creates a new millisecond. * * @param millisecond the millisecond (0-999). * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Millisecond(int millisecond, int second, int minute, int hour, int day, int month, int year) { this(millisecond, new Second(second, minute, hour, day, month, year)); }
/** * Returns the second preceding this one. * * @return The second preceding this one. */ public RegularTimePeriod previous() { Second result = null; if (this.second != FIRST_SECOND_IN_MINUTE) { result = new Second(this.second - 1, getMinute()); } else { Minute previous = (Minute) getMinute().previous(); if (previous != null) { result = new Second(LAST_SECOND_IN_MINUTE, previous); } } return result; }
/** * Returns the last millisecond of the second. * * @param calendar the calendar/timezone ({@code null} not permitted). * * @return The last millisecond. * * @throws NullPointerException if {@code calendar} is {@code null}. */ @Override public long getLastMillisecond(Calendar calendar) { return getFirstMillisecond(calendar) + 999L; }
public static Second toSecond(long epochSecond) { return new Second(Date.from(Instant.ofEpochSecond(epochSecond))); } }
/** * Returns the second following this one. * * @return The second following this one. */ public RegularTimePeriod next() { Second result = null; if (this.second != LAST_SECOND_IN_MINUTE) { result = new Second(this.second + 1, getMinute()); } else { Minute next = (Minute) getMinute().next(); if (next != null) { result = new Second(FIRST_SECOND_IN_MINUTE, next); } } return result; }
/** * Returns the last millisecond of the second. * * @param calendar the calendar/timezone (<code>null</code> not permitted). * * @return The last millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ public long getLastMillisecond(Calendar calendar) { return getFirstMillisecond(calendar) + 999L; }
public static Second createSecond( long millisecond ) { Date date = new Date( millisecond ); return new Second( date, TimeZone.getTimeZone( "GMT" ), Locale.getDefault() ); }
/** * Returns the second following this one. * * @return The second following this one. */ @Override public RegularTimePeriod next() { Second result = null; if (this.second != LAST_SECOND_IN_MINUTE) { result = new Second(this.second + 1, getMinute()); } else { Minute next = (Minute) getMinute().next(); if (next != null) { result = new Second(FIRST_SECOND_IN_MINUTE, next); } } return result; }
private TimeSeries extractTimeSeries( String name, IncrementCalculator incrementCalculator ) { TimeSeries series = new TimeSeries( name ); for ( ResponsetimeSample sample : samples ) { long sampleStart = sample.getStartTime(); long sampleEndTime = sample.getEndTime(); Second second = ModelUtil.createSecond( sampleStart ); while ( second.getFirstMillisecond() <= sampleEndTime ) { double increment = incrementCalculator.getIncrement( second, sampleStart, sampleEndTime ); updateSeries( series, second, increment ); second = ModelUtil.next( second ); } } return series; }
int second = Integer.parseInt(secstr); if ((second >= 0) && (second <= 59)) { result = new Second(second, m);