Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;

public class Main {

    public static void main(String[] args) {
        System.out.println(convert(ChronoUnit.DAYS));
    }

    public static TimeUnit convert(ChronoUnit tu) {
        if (tu == null) {
            return null;
        }
        switch (tu) {
        case DAYS:
            return TimeUnit.DAYS;
        case HOURS:
            return TimeUnit.HOURS;
        case MINUTES:
            return TimeUnit.MINUTES;
        case SECONDS:
            return TimeUnit.SECONDS;
        case MICROS:
            return TimeUnit.MICROSECONDS;
        case MILLIS:
            return TimeUnit.MILLISECONDS;
        case NANOS:
            return TimeUnit.NANOSECONDS;
        default:
            //TODO support the rest
            throw new UnsupportedOperationException("Man, use a real temporal unit");
        }
    }

    public static ChronoUnit convert(TimeUnit tu) {
        if (tu == null) {
            return null;
        }
        switch (tu) {
        case DAYS:
            return ChronoUnit.DAYS;
        case HOURS:
            return ChronoUnit.HOURS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        default:
            assert false : "there are no other TimeUnit ordinal values";
            return null;
        }
    }
}