Java Code Examples for java.util.concurrent.TimeUnit.DAYS

The following are Jave code examples for showing how to use DAYS of the java.util.concurrent.TimeUnit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Lagerta   File: JDBCKeyValueMapperUnitTest.java   View Source Code Vote up 6 votes
@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}
    };
}
 
Example 2
Project: CalendarFX   File: GoogleEntryDetailsView.java   View Source Code Vote up 6 votes
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);
}
 
Example 3
Project: human-mobility-modeling-utilities   File: RadiusOfGyration.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 4
Project: elasticsearch_my   File: TimeValueTests.java   View Source Code Vote up 5 votes
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);
}
 
Example 5
Project: neoscada   File: Helper.java   View Source Code Vote up 5 votes
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 ) );
}
 
Example 6
Project: googles-monorepo-demo   File: CacheBuilderSpec.java   View Source Code Vote up 5 votes
@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));
  }
}
 
Example 7
Project: jetcache   File: DefaultCacheMonitorManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: BEAST   File: TimeOutSaverLoader.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 9
Project: Loyalty   File: ImportManager.java   View Source Code Vote up 5 votes
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;
}
 
Example 10
Project: Drones-Simulator   File: ConcurrentExecute.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 11
Project: elasticsearch_my   File: TimeValue.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 12
Project: DiscogsBrowser   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Single<RootSearchResponse> searchDiscogs(Single<RootSearchResponse> searchDiscogsSingle, DynamicKey searchTerm);
 
Example 13
Project: Aurora   File: CommonCache.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Observable<Reply<List<String>>> getHotWords(Observable<List<String>> strs);
 
Example 14
Project: DiscogsBrowser   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Single<Master> fetchMasterDetails(Single<Master> fetchMasterDetailsSingle, DynamicKey masterId);
 
Example 15
Project: pac4j-plus   File: DirectFormClientTests.java   View Source Code Vote up 4 votes
@Test
public void testHasDefaultProfileCreator() {
    final DirectFormClient formClient = new DirectFormClient(new LocalCachingAuthenticator<>(new SimpleTestUsernamePasswordAuthenticator(), 10, 10, TimeUnit.DAYS));
    formClient.init(null);
}
 
Example 16
Project: DiscogsBrowser   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Single<RootLabelResponse> fetchLabelReleases(Single<RootLabelResponse> fetchLabelReleasesSingle, DynamicKey labelId);
 
Example 17
Project: DiscogsBrowser   File: CacheProviders.java   View Source Code Vote up 4 votes
@LifeCache(duration = 1, timeUnit = TimeUnit.DAYS)
Single<RootArtistReleaseResponse> fetchArtistsReleases(Single<RootArtistReleaseResponse> fetchArtistsReleasesSingle, DynamicKey artistId);
 
Example 18
Project: BEAST   File: TimeoutValueHandlerTest.java   View Source Code Vote up 4 votes
/**
 * 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);
}
 
Example 19
Project: hadoop   File: Configuration.java   View Source Code Vote up 0 votes
TimeUnit unit() { return TimeUnit.DAYS; } 
Example 20
Project: hadoop-oss   File: Configuration.java   View Source Code Vote up 0 votes
TimeUnit unit() { return TimeUnit.DAYS; }