Alachisoft.NCache.Common.Enum.Time Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Alachisoft.NCache.Common.Enum;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import java.text.ParseException;
import java.util.Date;
/**
* @author Muneeb Shahid
*/
public enum Time {
SEC, //second
mSEC, //milliSecond
uSEC, //microSecond
nSEC; //nanoSecond
public static java.util.Date ReferenceTime;
static {
try {
ReferenceTime = NCDateTime.getUTCDate(new Date(2016, 1, 1, 0, 0, 0));
} catch (ParseException e) {
e.printStackTrace();
}
}
/**
* @param time value to be converted
* @param unit current unit of time
* @return
*/
public static double toNanoSeconds(long time, Time unit) {
if (unit.equals(Time.SEC)) {
return time * 1000000000.0;
} else if (unit.equals(Time.mSEC)) {
return time * 1000000.0;
} else if (unit.equals(Time.uSEC)) {
return time * 1000.0;
} else {
return time * 1.0;
}
}
/**
* @param time value to be converted
* @param unit current unit of time
* @return
*/
public static double toMicroSeconds(long time, Time unit) {
if (unit.equals(Time.SEC)) {
return time * 1000000.0;
} else if (unit.equals(Time.mSEC)) {
return time * 1000.0;
} else if (unit.equals(Time.nSEC)) {
return time / 1000.0;
} else {
return time * 1.0;
}
}
/**
* @param time value to be converted
* @param unit current unit of time
* @return
*/
public static double toMilliSeconds(long time, Time unit) {
if (unit.equals(Time.SEC)) {
return time * 1000.0;
} else if (unit.equals(Time.uSEC)) {
return time / 1000.0;
} else if (unit.equals(Time.nSEC)) {
return time / 1000000.0;
} else {
return time * 1.0;
}
}
/**
* @param time value to be converted
* @param unit current unit of time
* @return
*/
public static double toSeconds(long time, Time unit) {
if (unit.equals(Time.mSEC)) {
return time / 1000.0;
} else if (unit.equals(Time.nSEC)) {
return time / 1000000000.0;
} else if (unit.equals(Time.uSEC)) {
return time / 1000000.0;
} else {
return time * 1.0;
}
}
}