String displayChar = timeUnit.getDisplayChar(); if (displayChar.length() == 0) { throw new IllegalArgumentException("found nothing was expecting: " + c);
String displayChar = timeUnit.getDisplayChar(); if (displayChar.length() == 0) { throw new IllegalArgumentException("found nothing was expecting: " + c);
/** * Returns a string representing this timespan expressed with the units provided. * * @param timeUnits * the timeunits you want in the decomposition * * @return a string representation using the units. * * @see #getAsTimespans(EnumSet) */ public String getAsString(EnumSet<TimeUnit> timeUnits) { StringBuilder sb = new StringBuilder(); EnumMap<TimeUnit, Timespan> canonicalTimespans = getAsTimespans(timeUnits); for (TimeUnit timeUnit : TIME_UNIT_ORDER) { if (canonicalTimespans.containsKey(timeUnit)) { long duration = canonicalTimespans.get(timeUnit).getDuration(); if (duration > 0) { sb.append(duration).append(timeUnit.getDisplayChar()); } } } if (sb.length() == 0) { sb.append(0); if (timeUnits.contains(getTimeUnit())) { sb.append(getTimeUnit().getDisplayChar()); } } return sb.toString(); }
/** * Returns a string representing this timespan expressed with the units provided. * * @param timeUnits * the timeunits you want in the decomposition * * @return a string representation using the units. * * @see #getAsTimespans(EnumSet) */ public String getAsString(EnumSet<TimeUnit> timeUnits) { StringBuilder sb = new StringBuilder(); EnumMap<TimeUnit, Timespan> canonicalTimespans = getAsTimespans(timeUnits); for (TimeUnit timeUnit : TIME_UNIT_ORDER) { if (canonicalTimespans.containsKey(timeUnit)) { long duration = canonicalTimespans.get(timeUnit).getDuration(); if (duration > 0) { sb.append(duration).append(timeUnit.getDisplayChar()); } } } if (sb.length() == 0) { sb.append(0); if (timeUnits.contains(getTimeUnit())) { sb.append(getTimeUnit().getDisplayChar()); } } return sb.toString(); }
/** * Expresses the provided duration in the unit provided. Note that the timespan returned * represent only the truncated version of the duration: if duration is 1002ms and timeunit * is seconds, then the timespan returned is 1 second... leaving behind 2ms. * * @return the timespan */ private static Timespan truncateDurationToUnit(long durationInMillis, TimeUnit timeUnit) { Timespan res; if (durationInMillis >= timeUnit.getMillisecondsCount()) { res = new Timespan(durationInMillis / timeUnit.getMillisecondsCount(), timeUnit); } else { res = ZERO_TIMESPANS.get(timeUnit); } return res; }
/** * Expresses the provided duration in the unit provided. Note that the timespan returned * represent only the truncated version of the duration: if duration is 1002ms and timeunit * is seconds, then the timespan returned is 1 second... leaving behind 2ms. * * @return the timespan */ private static Timespan truncateDurationToUnit(long durationInMillis, TimeUnit timeUnit) { Timespan res; if (durationInMillis >= timeUnit.getMillisecondsCount()) { res = new Timespan(durationInMillis / timeUnit.getMillisecondsCount(), timeUnit); } else { res = ZERO_TIMESPANS.get(timeUnit); } return res; }
/** * @return the duration of this timespan in milliseconds */ public long getDurationInMilliseconds() { // 100% equivalent to getDuration(TimeUnit.MILLISECOND) but faster! return getDuration() * getTimeUnit().getMillisecondsCount(); }
/** * @return the duration of this timespan in milliseconds */ public long getDurationInMilliseconds() { // 100% equivalent to getDuration(TimeUnit.MILLISECOND) but faster! return getDuration() * getTimeUnit().getMillisecondsCount(); }