src/share/classes/java/nio/file/attribute/FileTime.java

Print this page




 293      * Represents a FileTime's value as two longs: the number of days since
 294      * the epoch, and the excess (in nanoseconds). This is used for comparing
 295      * values with different units of granularity.
 296      */
 297     private static class DaysAndNanos implements Comparable<DaysAndNanos> {
 298         // constants for conversion
 299         private static final long C0 = 1L;
 300         private static final long C1 = C0 * 24L;
 301         private static final long C2 = C1 * 60L;
 302         private static final long C3 = C2 * 60L;
 303         private static final long C4 = C3 * 1000L;
 304         private static final long C5 = C4 * 1000L;
 305         private static final long C6 = C5 * 1000L;
 306 
 307         /**
 308          * The value (in days) since the epoch; can be negative.
 309          */
 310         private final long days;
 311 
 312         /**
 313          * The excess (in nanoseconds); can be negative if days <= 0.
 314          */
 315         private final long excessNanos;
 316 
 317         /**
 318          * Initializes a new instance of this class.
 319          */
 320         DaysAndNanos(long value, TimeUnit unit) {
 321             long scale;
 322             switch (unit) {
 323                 case DAYS         : scale = C0; break;
 324                 case HOURS        : scale = C1; break;
 325                 case MINUTES      : scale = C2; break;
 326                 case SECONDS      : scale = C3; break;
 327                 case MILLISECONDS : scale = C4; break;
 328                 case MICROSECONDS : scale = C5; break;
 329                 case NANOSECONDS  : scale = C6; break;
 330                 default : throw new AssertionError("Unit not handled");
 331             }
 332             this.days = unit.toDays(value);
 333             this.excessNanos = unit.toNanos(value - (this.days * scale));




 293      * Represents a FileTime's value as two longs: the number of days since
 294      * the epoch, and the excess (in nanoseconds). This is used for comparing
 295      * values with different units of granularity.
 296      */
 297     private static class DaysAndNanos implements Comparable<DaysAndNanos> {
 298         // constants for conversion
 299         private static final long C0 = 1L;
 300         private static final long C1 = C0 * 24L;
 301         private static final long C2 = C1 * 60L;
 302         private static final long C3 = C2 * 60L;
 303         private static final long C4 = C3 * 1000L;
 304         private static final long C5 = C4 * 1000L;
 305         private static final long C6 = C5 * 1000L;
 306 
 307         /**
 308          * The value (in days) since the epoch; can be negative.
 309          */
 310         private final long days;
 311 
 312         /**
 313          * The excess (in nanoseconds); can be negative if days &lt;= 0.
 314          */
 315         private final long excessNanos;
 316 
 317         /**
 318          * Initializes a new instance of this class.
 319          */
 320         DaysAndNanos(long value, TimeUnit unit) {
 321             long scale;
 322             switch (unit) {
 323                 case DAYS         : scale = C0; break;
 324                 case HOURS        : scale = C1; break;
 325                 case MINUTES      : scale = C2; break;
 326                 case SECONDS      : scale = C3; break;
 327                 case MILLISECONDS : scale = C4; break;
 328                 case MICROSECONDS : scale = C5; break;
 329                 case NANOSECONDS  : scale = C6; break;
 330                 default : throw new AssertionError("Unit not handled");
 331             }
 332             this.days = unit.toDays(value);
 333             this.excessNanos = unit.toNanos(value - (this.days * scale));