本文整理汇总了Java中java.util.concurrent.TimeUnit.DAYS属性的典型用法代码示例。如果您正苦于以下问题:Java TimeUnit.DAYS属性的具体用法?Java TimeUnit.DAYS怎么用?Java TimeUnit.DAYS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.concurrent.TimeUnit
的用法示例。
在下文中一共展示了TimeUnit.DAYS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideForShouldNotBeSerialized
@DataProvider(name = SHOULD_NOT_BE_SERIALIZED_PROVIDER)
public Object[][] provideForShouldNotBeSerialized() {
Date time = Calendar.getInstance().getTime();
return new Object[][]{
{TimeUnit.DAYS},
{0},
{(short) 0},
{(byte) 0},
{0L},
{0.0D},
{0.0F},
{'c'},
{"string"},
{time},
{null}
};
}
示例2: updateMinutes
private void updateMinutes() {
Integer minutes = null;
try {
Integer value = Integer.valueOf(valueTxt.getText());
if (unitCombo.getValue() == TimeUnit.DAYS) {
minutes = Math.toIntExact(TimeUnit.DAYS.toMinutes(value));
} else if (unitCombo.getValue() == TimeUnit.HOURS) {
minutes = Math.toIntExact(TimeUnit.HOURS.toMinutes(value));
} else {
minutes = value;
}
} catch (NumberFormatException e) {
// DO nothing
}
reminder.setMinutes(minutes);
}
示例3: calculateRadiusOfGyrationOverTime
/**
* Calculates a list of progressing radius of gyration numbers based on time
* unit given. Currently, day is supported.
*
* @param traces
* location traces of an individual
* @param unit
* spatial distance unit
* @param timeUnit
* time unit for radius of gyration calculation. Day is supported.
* @return an array of calculated radius of gyration.
* @throws TimeUnitNotSupportedException
*/
public double[] calculateRadiusOfGyrationOverTime(List<LocationTrace> traces,
SpatialDistanceUnit unit, TimeUnit timeUnit) throws TimeUnitNotSupportedException{
if (timeUnit != TimeUnit.DAYS){
throw new TimeUnitNotSupportedException(
timeUnit + " is not supported. Please pass days as time unit.");
}
LocationTraceHelper traceHelper = new LocationTraceHelper();
List<LocationTrace> selectedTraces;
LocalDateTime firstTraceTime = traces.get(0).getLocalTime().minusMinutes(1);
LocalDateTime lastTraceTime = traces.get(traces.size()-1).getLocalTime();
double[] rogResults;
LocalDateTime curentEndDate;
int numberOfDays = Days.daysBetween(firstTraceTime, lastTraceTime).getDays();
rogResults = new double[numberOfDays-1];
for(int i=1; i < numberOfDays; i++ ){
curentEndDate = firstTraceTime.plusDays(i).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
selectedTraces = traceHelper.selectBetweenDates(traces, firstTraceTime, curentEndDate);
rogResults[i-1] = calculateRadiusOfGyration(selectedTraces);
}
return rogResults;
}
示例4: testCompareUnits
public void testCompareUnits() {
long number = randomNonNegativeLong();
TimeUnit randomUnit = randomValueOtherThan(TimeUnit.DAYS, ()->randomFrom(TimeUnit.values()));
TimeValue firstValue = new TimeValue(number, randomUnit);
TimeValue secondValue = new TimeValue(number, TimeUnit.DAYS);
assertTrue(firstValue.compareTo(secondValue) < 0);
assertTrue(secondValue.compareTo(firstValue) > 0);
}
示例5: niceTimeRounded
public static long niceTimeRounded ( final long value )
{
final TimeUnit tu;
if ( value >= TimeUnit.DAYS.toMillis ( 1 ) )
{
tu = TimeUnit.DAYS;
}
else if ( value >= TimeUnit.HOURS.toMillis ( 1 ) )
{
tu = TimeUnit.HOURS;
}
else if ( value >= TimeUnit.MINUTES.toMillis ( 1 ) )
{
tu = TimeUnit.MINUTES;
}
else if ( value >= TimeUnit.SECONDS.toMillis ( 1 ) )
{
tu = TimeUnit.SECONDS;
}
else
{
tu = TimeUnit.MILLISECONDS;
}
double v = (double)value / (double)tu.toMillis ( 1 );
v = niceNum ( v, true );
return (long) ( v * tu.toMillis ( 1 ) );
}
示例6: parse
@Override
public void parse(CacheBuilderSpec spec, String key, String value) {
checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
try {
char lastChar = value.charAt(value.length() - 1);
TimeUnit timeUnit;
switch (lastChar) {
case 'd':
timeUnit = TimeUnit.DAYS;
break;
case 'h':
timeUnit = TimeUnit.HOURS;
break;
case 'm':
timeUnit = TimeUnit.MINUTES;
break;
case 's':
timeUnit = TimeUnit.SECONDS;
break;
default:
throw new IllegalArgumentException(
format(
"key %s invalid format. was %s, must end with one of [dDhHmMsS]", key, value));
}
long duration = Long.parseLong(value.substring(0, value.length() - 1));
parseDuration(spec, duration, timeUnit);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
format("key %s value set to %s, must be integer", key, value));
}
}
示例7: computeFirstResetTime
protected static LocalDateTime computeFirstResetTime(LocalDateTime baseTime, int time, TimeUnit unit) {
if (unit != TimeUnit.SECONDS && unit != TimeUnit.MINUTES && unit != TimeUnit.HOURS && unit != TimeUnit.DAYS) {
throw new IllegalArgumentException();
}
LocalDateTime t = baseTime;
switch (unit) {
case DAYS:
t = t.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
break;
case HOURS:
if (24 % time == 0) {
t = t.plusHours(time - t.getHour() % time);
} else {
t = t.plusHours(1);
}
t = t.withMinute(0).withSecond(0).withNano(0);
break;
case MINUTES:
if (60 % time == 0) {
t = t.plusMinutes(time - t.getMinute() % time);
} else {
t = t.plusMinutes(1);
}
t = t.withSecond(0).withNano(0);
break;
case SECONDS:
if (60 % time == 0) {
t = t.plusSeconds(time - t.getSecond() % time);
} else {
t = t.plusSeconds(1);
}
t = t.withNano(0);
break;
}
return t;
}
示例8: createFromSaveString
/**
* Creates a TimeOut object from a given, by createSaveString() generated, saveString
* @param s the SaveString
* @return the TimeOut object
*/
public static TimeOut createFromSaveString(String s) {
String [] split = s.split("\n</duration>\n");
Long duration = Long.parseLong(split[0].replace("<duration>\n", ""));
split = split[1].split("\n</timeunit>\n");
TimeUnit timeUnit = TimeUnit.MINUTES;
String timeunit = split[0].replace("<timeunit>\n", "");
switch(timeunit) {
case "MILLISECONDS":
timeUnit = TimeUnit.MILLISECONDS;
break;
case "MINUTES":
timeUnit = TimeUnit.MINUTES;
duration = TimeUnit.MILLISECONDS.toMinutes(duration);
break;
case "SECONDS":
timeUnit = TimeUnit.SECONDS;
duration = TimeUnit.MILLISECONDS.toSeconds(duration);
break;
case "HOURS":
timeUnit = TimeUnit.HOURS;
duration = TimeUnit.MILLISECONDS.toHours(duration);
break;
case "DAYS":
timeUnit = TimeUnit.DAYS;
duration = TimeUnit.MILLISECONDS.toDays(duration);
break;
default:
break;
}
return new TimeOut(timeUnit, duration);
}
示例9: ImportManager
public ImportManager(TaskListener<Void> listener, Context context) {
this.listener = listener;
HighMemoryGovernor governor = new HighMemoryGovernor();
DebugManager.debugPrint("Restoring up to " + governor.concurrentTasks() + " entities at the same time.", context);
this.poolExecutor = new ThreadPoolExecutor(governor.concurrentTasks(), governor.concurrentTasks(), 100, TimeUnit.DAYS, new ArrayBlockingQueue<Runnable>(256));
this.context = context;
}
示例10: ConcurrentExecute
/**
* Create the ConcurrentExecute to perform a number of jobs concurrently
* @param concurrentThreads The amount of threads to concurrently perform the job
*/
public ConcurrentExecute(int concurrentThreads) {
this.nextId = new AtomicLong(0);
this.jobEntries = new ArrayList<>();
this.pool = new ThreadPoolExecutor(concurrentThreads, concurrentThreads, 1, TimeUnit.DAYS, new LinkedBlockingQueue<>());
this.timeoutHandler = new TimeoutHandler();
}
示例11: parseTimeValue
public static TimeValue parseTimeValue(String sValue, TimeValue defaultValue, String settingName) {
settingName = Objects.requireNonNull(settingName);
if (sValue == null) {
return defaultValue;
}
final String normalized = sValue.toLowerCase(Locale.ROOT).trim();
if (normalized.endsWith("nanos")) {
return new TimeValue(parse(sValue, normalized, 5), TimeUnit.NANOSECONDS);
} else if (normalized.endsWith("micros")) {
return new TimeValue(parse(sValue, normalized, 6), TimeUnit.MICROSECONDS);
} else if (normalized.endsWith("ms")) {
return new TimeValue(parse(sValue, normalized, 2), TimeUnit.MILLISECONDS);
} else if (normalized.endsWith("s")) {
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.SECONDS);
} else if (sValue.endsWith("m")) {
// parsing minutes should be case sensitive as `M` is generally
// accepted to mean months not minutes. This is the only case where
// the upper and lower case forms indicate different time units
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.MINUTES);
} else if (normalized.endsWith("h")) {
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.HOURS);
} else if (normalized.endsWith("d")) {
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.DAYS);
} else if (normalized.matches("-0*1")) {
return TimeValue.MINUS_ONE;
} else if (normalized.matches("0+")) {
return TimeValue.ZERO;
} else {
// Missing units:
throw new ElasticsearchParseException(
"failed to parse setting [{}] with value [{}] as a time value: unit is missing or unrecognized",
settingName,
sValue);
}
}
示例12:
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Single<RootSearchResponse> searchDiscogs(Single<RootSearchResponse> searchDiscogsSingle, DynamicKey searchTerm);
示例13:
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Observable<Reply<List<String>>> getHotWords(Observable<List<String>> strs);
示例14: testHasDefaultProfileCreator
@Test
public void testHasDefaultProfileCreator() {
final DirectFormClient formClient = new DirectFormClient(new LocalCachingAuthenticator<>(new SimpleTestUsernamePasswordAuthenticator(), 10, 10, TimeUnit.DAYS));
formClient.init(null);
}
示例15: testTimeout
/**
* Test of class TimeoutValueHandler testing both input and output at different configurations.
*/
@Test
public void testTimeout() {
System.out.println("set/getTimeout");
JComboBox<String> comboBox = new JComboBox<String>();
JSpinner spinner = new JSpinner();
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();
model.addElement("s");
model.addElement("m");
model.addElement("h");
model.addElement("d");
model.addElement("faultyEntry");
comboBox.setModel(model);
TimeoutValueHandler handler = new TimeoutValueHandler(spinner, comboBox);
handler.setReacts(true);
spinner.setValue(1);
comboBox.setSelectedIndex(2);
TimeOut expResult = new TimeOut(TimeUnit.SECONDS, 0);
spinner.setValue(0);
comboBox.setSelectedIndex(0);
handler.setValue(handler.getTimeout());
TimeOut result = handler.getTimeout();
boolean minTest = (expResult.getDuration() == result.getDuration()
&& expResult.getOrigUnit().equals(result.getOrigUnit())
&& !result.isActive());
expResult = new TimeOut(TimeUnit.DAYS, 3653);
spinner.setValue(3653);
comboBox.setSelectedIndex(3);
handler.setValue(handler.getTimeout());
result = handler.getTimeout();
boolean maxTest = (expResult.getDuration() == result.getDuration()
&& expResult.getOrigUnit().equals(result.getOrigUnit())
&& result.isActive());
expResult = new TimeOut(TimeUnit.DAYS, 0);
spinner.setValue(-1);
handler.setValue(handler.getTimeout());
result = handler.getTimeout();
boolean falseValueTest = (expResult.getDuration() == result.getDuration()
&& expResult.getOrigUnit().equals(result.getOrigUnit())
&& !result.isActive());
expResult = new TimeOut(TimeUnit.SECONDS, 0);
spinner.setValue(42);
comboBox.setSelectedIndex(4);
handler.setValue(handler.getTimeout());
result = handler.getTimeout();
//System.out.println(handler.hasChanged() + " max " + handler.getTimeout().getDuration() + " " + handler.getTimeout().getOrigUnit());
//System.out.println(handler.hasChanged() + " max " + expResult.getDuration() + " " + expResult.getOrigUnit());
boolean falseUnitTest = (expResult.getDuration() == result.getDuration()
&& expResult.getOrigUnit().equals(result.getOrigUnit())
&& !result.isActive());
assertTrue(minTest && maxTest && falseValueTest && falseUnitTest);
}