mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
Fix for spelling error joel pointed out, as well as a simple unit test around the TimeUnit conversions
This commit is contained in:
parent
8b7f689e1a
commit
996e52170f
@ -34,7 +34,7 @@ public enum TimeUnit {
|
||||
|
||||
@Override
|
||||
public long toMinutes(long d) {
|
||||
return d / NANOSECONDS_PER_MINUET;
|
||||
return d / NANOSECONDS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,7 +80,7 @@ public enum TimeUnit {
|
||||
|
||||
@Override
|
||||
public long toMinutes(long d) {
|
||||
return d / MICROSECONDS_PER_MINUET;
|
||||
return d / MICROSECONDS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,7 +126,7 @@ public enum TimeUnit {
|
||||
|
||||
@Override
|
||||
public long toMinutes(long d) {
|
||||
return d / MILLISECONDS_PER_MINUET;
|
||||
return d / MILLISECONDS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -172,7 +172,7 @@ public enum TimeUnit {
|
||||
|
||||
@Override
|
||||
public long toMinutes(long d) {
|
||||
return d / SECONDS_PER_MINUET;
|
||||
return d / SECONDS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -198,22 +198,22 @@ public enum TimeUnit {
|
||||
MINUTES {
|
||||
@Override
|
||||
public long toNanos(long d) {
|
||||
return scale(d, NANOSECONDS_PER_MINUET);
|
||||
return scale(d, NANOSECONDS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long toMicros(long d) {
|
||||
return scale(d, MICROSECONDS_PER_MINUET);
|
||||
return scale(d, MICROSECONDS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long toMillis(long d) {
|
||||
return scale(d, MILLISECONDS_PER_MINUET);
|
||||
return scale(d, MILLISECONDS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long toSeconds(long d) {
|
||||
return scale(d, SECONDS_PER_MINUET);
|
||||
return scale(d, SECONDS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -337,26 +337,26 @@ public enum TimeUnit {
|
||||
private static final long NANOSECONDS_PER_MICROSECOND = 1000L;
|
||||
private static final long MICROSECONDS_PER_MILLISECOND = 1000L;
|
||||
private static final long MILLISECONDS_PER_SECOND = 1000L;
|
||||
private static final long SECONDS_PER_MINUET = 60;
|
||||
private static final long SECONDS_PER_MINUTE = 60;
|
||||
private static final long MINUETS_PER_HOUR = 60;
|
||||
private static final long HOURS_PER_DAY = 24;
|
||||
|
||||
private static final long NANOSECONDS_PER_MILLISECOND = NANOSECONDS_PER_MICROSECOND * MICROSECONDS_PER_MILLISECOND;
|
||||
private static final long NANOSECONDS_PER_SECOND = NANOSECONDS_PER_MILLISECOND * MILLISECONDS_PER_SECOND;
|
||||
private static final long NANOSECONDS_PER_MINUET = NANOSECONDS_PER_SECOND * SECONDS_PER_MINUET;
|
||||
private static final long NANOSECONDS_PER_HOUR = NANOSECONDS_PER_MINUET * MINUETS_PER_HOUR;
|
||||
private static final long NANOSECONDS_PER_MINUTE = NANOSECONDS_PER_SECOND * SECONDS_PER_MINUTE;
|
||||
private static final long NANOSECONDS_PER_HOUR = NANOSECONDS_PER_MINUTE * MINUETS_PER_HOUR;
|
||||
private static final long NANOSECONDS_PER_DAY = NANOSECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
||||
private static final long MICROSECONDS_PER_SECOND = MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_SECOND;
|
||||
private static final long MICROSECONDS_PER_MINUET = MICROSECONDS_PER_SECOND * SECONDS_PER_MINUET;
|
||||
private static final long MICROSECONDS_PER_HOUR = MICROSECONDS_PER_MINUET * MINUETS_PER_HOUR;
|
||||
private static final long MICROSECONDS_PER_MINUTE = MICROSECONDS_PER_SECOND * SECONDS_PER_MINUTE;
|
||||
private static final long MICROSECONDS_PER_HOUR = MICROSECONDS_PER_MINUTE * MINUETS_PER_HOUR;
|
||||
private static final long MICROSECONDS_PER_DAY = MICROSECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
||||
private static final long MILLISECONDS_PER_MINUET = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUET;
|
||||
private static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUET * MINUETS_PER_HOUR;
|
||||
private static final long MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * SECONDS_PER_MINUTE;
|
||||
private static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * MINUETS_PER_HOUR;
|
||||
private static final long MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
||||
private static final long SECONDS_PER_HOUR = SECONDS_PER_MINUET * MINUETS_PER_HOUR;
|
||||
private static final long SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUETS_PER_HOUR;
|
||||
private static final long SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
||||
private static final long MINUETS_PER_DAY = MINUETS_PER_HOUR * HOURS_PER_DAY;
|
||||
|
117
test/TimeUnitConversions.java
Normal file
117
test/TimeUnitConversions.java
Normal file
@ -0,0 +1,117 @@
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TimeUnitConversions {
|
||||
private static void expect(long v1, long v2) {
|
||||
if (v1 != v2) {
|
||||
throw new RuntimeException(v1 + " != " + v2);
|
||||
}
|
||||
}
|
||||
|
||||
private static void toNanoConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.MINUTES), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.NANOSECONDS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toMicroConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1000, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.SECONDS), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.MINUTES), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.MICROSECONDS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toMilliConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.MILLISECONDS.convert(1000L * 1000, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.MILLISECONDS.convert(1000, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expectedValue *= 1000;
|
||||
expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toSecondConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.SECONDS.convert(1000L * 1000 * 1000, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.SECONDS.convert(1000L * 1000, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expect(TimeUnit.SECONDS.convert(1000, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expect(TimeUnit.SECONDS.convert(1, TimeUnit.SECONDS), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.SECONDS.convert(1, TimeUnit.MINUTES), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.SECONDS.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.SECONDS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toMinuteConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.MINUTES.convert(1000L * 1000 * 1000 * 60, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.MINUTES.convert(1000L * 1000 * 60, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expect(TimeUnit.MINUTES.convert(1000L * 60, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expect(TimeUnit.MINUTES.convert(60, TimeUnit.SECONDS), expectedValue);
|
||||
expect(TimeUnit.MINUTES.convert(1, TimeUnit.MINUTES), expectedValue);
|
||||
expectedValue *= 60;
|
||||
expect(TimeUnit.MINUTES.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.MINUTES.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toHourConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.HOURS.convert(1000L * 1000 * 1000 * 60 * 60, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.HOURS.convert(1000L * 1000 * 60 * 60, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expect(TimeUnit.HOURS.convert(1000L * 60 * 60, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expect(TimeUnit.HOURS.convert(60L * 60, TimeUnit.SECONDS), expectedValue);
|
||||
expect(TimeUnit.HOURS.convert(60, TimeUnit.MINUTES), expectedValue);
|
||||
expect(TimeUnit.HOURS.convert(1, TimeUnit.HOURS), expectedValue);
|
||||
expectedValue *= 24;
|
||||
expect(TimeUnit.HOURS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
private static void toDayConversionTest() {
|
||||
long expectedValue = 1;
|
||||
expect(TimeUnit.DAYS.convert(1000L * 1000 * 1000 * 60 * 60 * 24, TimeUnit.NANOSECONDS), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(1000L * 1000 * 60 * 60 * 24, TimeUnit.MICROSECONDS), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(1000L * 60 * 60 * 24, TimeUnit.MILLISECONDS), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(60L * 60 * 24, TimeUnit.SECONDS), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(60L * 24, TimeUnit.MINUTES), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(24, TimeUnit.HOURS), expectedValue);
|
||||
expect(TimeUnit.DAYS.convert(1, TimeUnit.DAYS), expectedValue);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
toNanoConversionTest();
|
||||
toMicroConversionTest();
|
||||
toMilliConversionTest();
|
||||
toSecondConversionTest();
|
||||
toMinuteConversionTest();
|
||||
toHourConversionTest();
|
||||
toDayConversionTest();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user