Java TimeUnit Calculate getTimeUnit(Object units)

Here you can find the source of getTimeUnit(Object units)

Description

get Time Unit

License

Open Source License

Declaration

public static TimeUnit getTimeUnit(Object units) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    private static final String EVENTS_DELIMITER = "EVENTS/";

    public static TimeUnit getTimeUnit(Object units) {
        if (units instanceof TimeUnit) {
            return (TimeUnit) units;
        } else if (units instanceof String) {
            return cleanUnitsString((String) units);
        }/*from   w w  w .j  a  v a 2 s. c o  m*/

        throw new IllegalArgumentException("unable to parse returned time units: " + units.toString());
    }

    public static TimeUnit cleanUnitsString(String units) {
        if (units == null) {
            return TimeUnit.SECONDS;
        }
        units = units.toUpperCase();

        if (units.contains(EVENTS_DELIMITER)) {
            units = units.substring(EVENTS_DELIMITER.length());
            units += "S";
        }

        return TimeUnit.valueOf(units);
    }
}

Related

  1. getProperUnitName(TimeUnit unit, long amount)
  2. getRandomTimeRound(int _duration, TimeUnit _unit)
  3. getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds)
  4. getTimeInMillis(TimeUnit unit)
  5. getTimeString(long value, TimeUnit unit)
  6. getTimeUnit(String timeUnit, TimeUnit defaultUnit)
  7. getTimeUnitByName(String timeUnit, TimeUnit defaultTimeUnit)
  8. getValueString(long value, TimeUnit unit)
  9. getWindowFlooredBinaryTime(TimeUnit unit, long timestamp, int windowSizeInSeconds)