All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.main.java.com.mgnt.utils.TimeUtils Maven / Gradle / Ivy

Go to download

Set of various Utils: stacktrace noise filter, String to/from unicode sequence converter, simple Http client JSON parser/serializer, Silent String parsing to Integer and other numeric types, Parsing String to time intervals with support for time unit suffixes, JSON parser that provides serialization/deserialization of classes to JSON, Version comparator and Version ranges operations, Self-throttling binary reader from Http request, File reader, A utility that automatically initiates a Factory with instances of all classes that implement user provided interface. An infrastructure for writing Scheduled Task classes where time interval for task execution is provided in humanly readable format (such as "9h" for 9 hours)

There is a newer version: 1.7.0.1
Show newest version
package com.mgnt.utils;

import com.mgnt.utils.entities.TimeInterval;

import java.util.concurrent.TimeUnit;

/**
 * This is simple Utility class that has a convenience sleep method that "swallows"
 * Created by Michael Gantman on 22/12/2015.
 */
public class TimeUtils {

    /**
     * This method is a convenience method for sleep that "swallows" {@link InterruptedException}  and
     * has {@link TimeUnit} parameter in addition to time period so it makes it very convenient. So with
     * this method there is no need to convert the time into milliseconds. Just simply write
     * 

*

{@code sleepFor(10, TimeUnit.SECONDS);}

*
No Exception catching needed * @param period time period to sleep * @param timeUnit {@link TimeUnit} that specifies in which units the time period is measured */ public static void sleepFor(long period, TimeUnit timeUnit) { try { timeUnit.sleep(period); } catch (InterruptedException ie) { } } /** * This is an overload for method {@link TimeUtils#sleepFor(long, TimeUnit)} which is provided for convenience. * Method {@link TimeUtils#sleepFor(long, TimeUnit)} could be very readable if you use actual values, for example

*

{@code sleepFor(10, TimeUnit.SECONDS);}

*
* But it you have your values stored in variables or especially already in instance of {@link TimeInterval}, then * it doesn't make it any more readable to write *

*

{@code TimeUtils.sleepFor(timeInterval.getValue(), timeInterval.getTimeUnit());}

*

* Hence this convenience method is provided * @param timeInterval {@link TimeInterval} instance that holds the time period to be waited for */ public static void sleepFor(TimeInterval timeInterval) { sleepFor(timeInterval.getValue(), timeInterval.getTimeUnit()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy