List of usage examples for org.joda.time Duration equals
public boolean equals(Object duration)
From source file:com.github.dbourdette.otto.data.DataTableUtils.java
License:Apache License
/** * Finds best Duration of rows for a {@link SimpleDataTable} based on given table interval *///from ww w.j a v a 2 s . co m public static Duration findBest(Interval interval) { Duration duration = new Duration(interval.getStart(), interval.getEnd()); if (duration.isShorterThan(ONE_DAY) || duration.equals(ONE_DAY)) { return Duration.standardMinutes(5); } else if (duration.isShorterThan(FIVE_DAYS) || duration.equals(FIVE_DAYS)) { return Duration.standardMinutes(30); } else { return Duration.standardDays(1); } }
From source file:com.thoughtworks.go.i18n.Localizer.java
License:Apache License
public String localize(Duration d) { if (d.equals(new Duration(0))) return ""; return PeriodFormat.getDefault().withLocale(currentLocale.getLocale()).print(d.toPeriod()); }
From source file:org.apache.beam.runners.direct.ExecutorServiceParallelExecutor.java
License:Apache License
@Override public State waitUntilFinish(Duration duration) throws Exception { Instant completionTime;//w w w. j a v a 2s . c o m if (duration.equals(Duration.ZERO)) { completionTime = new Instant(Long.MAX_VALUE); } else { completionTime = Instant.now().plus(duration); } VisibleExecutorUpdate update = null; while (Instant.now().isBefore(completionTime) && (update == null || isTerminalStateUpdate(update))) { // Get an update; don't block forever if another thread has handled it. The call to poll will // wait the entire timeout; this call primarily exists to relinquish any core. update = visibleUpdates.tryNext(Duration.millis(25L)); if (update == null && pipelineState.get().isTerminal()) { // there are no updates to process and no updates will ever be published because the // executor is shutdown return pipelineState.get(); } else if (update != null && update.thrown.isPresent()) { Throwable thrown = update.thrown.get(); if (thrown instanceof Exception) { throw (Exception) thrown; } else if (thrown instanceof Error) { throw (Error) thrown; } else { throw new Exception("Unknown Type of Throwable", thrown); } } } return pipelineState.get(); }
From source file:org.graylog2.lookup.LookupDataAdapterRefreshService.java
License:Open Source License
/** * Add the given {@link LookupDataAdapter} to the refresh service. * <p>//from w ww . j ava 2 s .c om * The {@link LookupDataAdapter#doRefresh(LookupCachePurge) refresh method} method will be called periodically * according to the {@link LookupDataAdapter#refreshInterval() refresh interval} of the data adapter. * @param dataAdapter the adapter to be added */ public void add(LookupDataAdapter dataAdapter) { if (state() == State.STOPPING || state() == State.TERMINATED) { LOG.debug("Service is in state <{}> - not adding new job for <{}/{}/@{}>", state(), dataAdapter.name(), dataAdapter.id(), objectId(dataAdapter)); return; } final Duration interval = dataAdapter.refreshInterval(); // No need to schedule the data adapter refresh if it doesn't implement a refresh if (!interval.equals(Duration.ZERO)) { // Using the adapter object ID here to make it possible to have multiple jobs for the same adapter final String instanceId = objectId(dataAdapter); // Manually synchronize here to avoid overwriting an existing refresh job for the given data adapter. // ConcurrentMap#computeIfAbsent() does not work here because scheduling a job is not idempotent. synchronized (futures) { if (!futures.containsKey(instanceId)) { LOG.info("Adding job for <{}/{}/@{}> [interval={}ms]", dataAdapter.name(), dataAdapter.id(), instanceId, interval.getMillis()); futures.put(instanceId, schedule(dataAdapter, interval)); } else { LOG.warn("Job for <{}/{}/@{}> already exists, not adding it again.", dataAdapter.name(), dataAdapter.id(), instanceId); } } } }
From source file:org.kalypso.model.rcm.RainfallGenerationOp.java
License:Open Source License
/** * Check if all timeseries that get combined here have the same timestep<br/> * Necessary, because the timestep of the combined timeseries is the timestep of the first timseries. */// ww w.j ava 2 s .c om private static void checkCombinedTimestep(final IObservation[] observations) throws CoreException { Period combinedTimestep = null; for (final IObservation observation : observations) { final Period currentTimestep = MetadataHelper.getTimestep(observation.getMetadataList()); final boolean hasValues = hasValues(observation); if (currentTimestep == null && hasValues) { final IStatus status = new Status(IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, Messages.getString("RainfallGenerationOp_5")); //$NON-NLS-1$ throw new CoreException(status); } if (combinedTimestep != null) { final Duration currentDuration = currentTimestep.toStandardDuration(); final Duration combinedDuration = combinedTimestep.toStandardDuration(); if (!currentDuration.equals(combinedDuration)) { final String message = String.format(Messages.getString("RainfallGenerationOp_6"), //$NON-NLS-1$ combinedTimestep, currentTimestep); final IStatus status = new Status(IStatus.ERROR, KalypsoModelRcmActivator.PLUGIN_ID, message); throw new CoreException(status); } } combinedTimestep = currentTimestep; } }