package ru.cdmlex.jtest;

public class Delay {
	private long delayNanos;
	private long passedNanos;
	
	private static final int NANOSECONDS_IN_MILLISECOND = 1000000;
    public static long nanosToMillis(long nanos) {
        return nanos / NANOSECONDS_IN_MILLISECOND;
    }
    public static long millisToNanos(long millis) {
        return millis * NANOSECONDS_IN_MILLISECOND;
    }
	
	public Delay(long delayMillis) {
		this.delayNanos = millisToNanos(delayMillis);
	}
	
	public boolean updateAndCheck(long deltaNanos) {
		passedNanos += deltaNanos;
		if (passedNanos > delayNanos) {
			passedNanos = 0;
			return true;
		} else {
			return false;
		}
	}
}

