Java Code Examples for java.time.Duration#equals()
The following examples show how to use
java.time.Duration#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionLanguage.java From diirt with MIT License | 6 votes |
/** * A synchronized array from the given expression. * * @param tolerance maximum time difference between samples in the * reconstructed array * @param cacheDepth maximum time difference between samples in the caches * used to reconstruct the array * @param expressions the expressions from which to reconstruct the array * @return an expression for the array */ public static DesiredRateExpression<VMultiDouble> synchronizedArrayOf(Duration tolerance, Duration cacheDepth, SourceRateExpressionList<VDouble> expressions) { if (cacheDepth.equals(Duration.ofMillis(0)) && TimeDuration.toSecondsDouble(cacheDepth) > 0) throw new IllegalArgumentException("Distance between samples must be non-zero and positive"); List<String> names = new ArrayList<String>(); List<ReadFunction<List<VDouble>>> collectors = new ArrayList<ReadFunction<List<VDouble>>>(); DesiredRateExpressionList<List<VDouble>> desiredRateExpressions = new DesiredRateExpressionListImpl<List<VDouble>>(); for (SourceRateExpression<VDouble> expression : expressions.getSourceRateExpressions()) { DesiredRateExpression<List<VDouble>> collectorExp = timedCacheOf(expression, cacheDepth); desiredRateExpressions.and(collectorExp); collectors.add(collectorExp.getFunction()); names.add(expression.getName()); } SynchronizedVDoubleAggregator aggregator = new SynchronizedVDoubleAggregator(names, collectors, tolerance); return new DesiredRateExpressionImpl<VMultiDouble>(desiredRateExpressions, (ReadFunction<VMultiDouble>) aggregator, "syncArray"); }
Example 2
Source File: RequestReplyFunction.java From flink-statefun with Apache License 2.0 | 6 votes |
private static Expiration resolveStateTtlExpiration(List<StateSpec> stateSpecs) { // TODO applying the below limitations due to state multiplexing (see FLINK-17954) // TODO 1) use the max TTL duration across all state, 2) only allow AFTER_READ_AND_WRITE Duration maxDuration = Duration.ZERO; for (StateSpec stateSpec : stateSpecs) { if (stateSpec.ttlDuration().compareTo(maxDuration) > 0) { maxDuration = stateSpec.ttlDuration(); } } if (maxDuration.equals(Duration.ZERO)) { return Expiration.none(); } return Expiration.expireAfterReadingOrWriting(maxDuration); }
Example 3
Source File: TimeSeries.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
private Duration checkRegularSpacing() { if (times.size() < 2) { throw new TimeSeriesException("At least 2 rows are expected"); } Duration spacing = null; for (int i = 1; i < times.size(); i++) { Duration duration = Duration.between(times.get(i - 1), times.get(i)); if (spacing == null) { spacing = duration; } else { if (!duration.equals(spacing)) { throw new TimeSeriesException("Time spacing has to be regular"); } } } return spacing; }
Example 4
Source File: TimeUtils.java From dynein with Apache License 2.0 | 5 votes |
public JobSchedulePolicy getPreferredSchedulePolicy(Duration delay, Clock clock) { Preconditions.checkArgument( !delay.isNegative(), "Scheduled Delay should be positive, got %s", delay); if (delay.equals(Duration.ZERO)) { return getSchedulePolicyWithEpochMillis(delay, JobScheduleType.IMMEDIATE, clock); } else if (delay.minus(Duration.ofMinutes(15)).isNegative()) { return getSchedulePolicyWithEpochMillis(delay, JobScheduleType.SQS_DELAYED, clock); } else { return getSchedulePolicyWithEpochMillis(delay, JobScheduleType.SCHEDULED, clock); } }
Example 5
Source File: RetryPolicyExecutor.java From failsafe with Apache License 2.0 | 5 votes |
private long getFixedOrRandomDelayNanos(long waitNanos) { Duration delay = policy.getDelay(); Duration delayMin = policy.getDelayMin(); Duration delayMax = policy.getDelayMax(); if (waitNanos == -1 && delay != null && !delay.equals(Duration.ZERO)) waitNanos = delay.toNanos(); else if (delayMin != null && delayMax != null) waitNanos = randomDelayInRange(delayMin.toNanos(), delayMax.toNanos(), Math.random()); return waitNanos; }
Example 6
Source File: PollingConfigurationView.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
private static boolean compareDurations(final Duration d1, final Duration d2) { if (d1 == null && d2 == null) { return true; } if (d1 != null) { return d1.equals(d2); } // d1 == null, d2 != null return false; }
Example 7
Source File: DurationConverter.java From LGoodDatePicker with MIT License | 5 votes |
public static void main(String[] args) { DurationConverterSettings settings = new DurationConverterSettings(); settings.smallestUsedUnit = DurationUnit.Second; settings.largestUsedUnit = DurationUnit.Year; settings.pluralUnitsMap = settings.getSimplePluralUnitsMap(true); String s1 = convertStringFromDuration(null, settings); String s2 = convertStringFromDuration(Duration.ofSeconds(-1), settings); String s3 = convertStringFromDuration(Duration.ofSeconds(0), settings); String s4 = convertStringFromDuration(Duration.ofSeconds(1), settings); String s5 = convertStringFromDuration(Duration.ofSeconds(1).plusNanos(2), settings); Duration m1 = convertStringToDuration("", settings); Duration m2 = convertStringToDuration(" ", settings); Duration m3 = convertStringToDuration("gobbldy gook", settings); Duration m4 = convertStringToDuration("gobbldy gook 55", settings); Duration m5 = convertStringToDuration("5.5g", settings); Duration m6 = convertStringToDuration("5.5m", settings); Duration m7 = convertStringToDuration("3.62h", settings); String ss7 = convertStringFromDuration(m7, settings); Duration m8 = convertStringToDuration("5.5d", settings); Duration m9 = convertStringToDuration("5.5w", settings); for (Duration duration = Duration.ofSeconds(0).plusNanos(0); duration.compareTo(Duration.ofDays(1000)) <= 0; duration = duration.plusHours(1)) { String textDuration = convertStringFromDuration(duration, settings); Duration durationParsed = convertStringToDuration(textDuration, settings); System.out.println("Duration: " + duration.toString() + ", Text: " + textDuration + ", DurationParsed: " + ((durationParsed == null) ? "null" : durationParsed.toString())); if (durationParsed == null || (!durationParsed.equals(duration))) { throw new RuntimeException(""); } } }
Example 8
Source File: FXMLResultsController.java From pikatimer with GNU General Public License v3.0 | 5 votes |
@Override protected void updateItem(Duration d, boolean empty) { super.updateItem(d, empty); if (d == null || empty) { setText(null); } else if (d.isZero() || d.equals(Duration.ofNanos(Long.MAX_VALUE))){ if (showZero && d.isZero()) setText("0:00:00.000"); else setText(""); } else { // Format duration. setText(DurationFormatter.durationToString(d, 3, Boolean.TRUE)); } }
Example 9
Source File: ControlPoint.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Do a cycle of domination on this ControlPoint for the given team over the given duration. The team can be null, * which means no team is dominating the point, which can cause the state to change in some configurations. */ private void dominateAndFireEvents(@Nullable Competitor dominator, Duration duration) { final Duration oldProgress = progress; final Competitor oldCapturer = capturer; final Competitor oldOwner = owner; dominate(dominator, duration); if(!Objects.equals(oldCapturer, capturer) || !oldProgress.equals(progress)) { match.callEvent(new CapturingTimeChangeEvent(match, this)); match.callEvent(new GoalStatusChangeEvent(this)); } if(!Objects.equals(oldCapturer, capturer)) { match.callEvent(new CapturingTeamChangeEvent(match, this, oldCapturer, capturer)); } if(!Objects.equals(oldOwner, owner)) { match.callEvent(new ControllerChangeEvent(match, this, oldOwner, owner)); match.callEvent(new GoalCompleteEvent(this, owner != null, c -> c.equals(oldOwner), c -> c.equals(owner))); ScoreMatchModule smm = this.getMatch().getMatchModule(ScoreMatchModule.class); if (smm != null) { if (oldOwner != null) smm.incrementScore(oldOwner, getDefinition().getPointsOwned() * -1); if (owner != null) smm.incrementScore(owner, getDefinition().getPointsOwned()); } } }
Example 10
Source File: CooldownPlayerFacet.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Submit a new cooldown for an object. */ public void coolFor(Object object, Duration time) { if(objects.containsKey(object)) { throw new IllegalStateException(object + " already has an active cooldown"); } if(!time.equals(Duration.ZERO)) { objects.put(object, plus(match.getInstantNow(), time)); } }
Example 11
Source File: ShardKey.java From elastic-db-tools-for-java with MIT License | 5 votes |
/** * Converts given TimeSpan to normalized binary representation. * * @param value * Input TimeSpan value. * @return Normalized array of bytes. */ private static byte[] normalize(Duration value) { if (value.equals(Duration.ZERO)) { return ShardKey.EMPTY_ARRAY; } else { return normalize(value.getSeconds()); } }
Example 12
Source File: ControlPoint.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
/** * Do a cycle of domination on this ControlPoint for the given team over the given duration. The * team can be null, which means no team is dominating the point, which can cause the state to * change in some configurations. */ private void dominateAndFireEvents(@Nullable Competitor dominantTeam, Duration dominantTime) { Duration oldCapturingTime = this.capturingTime; Competitor oldCapturingTeam = this.capturingTeam; Competitor oldControllingTeam = this.controllingTeam; this.dominate(dominantTeam, dominantTime); if (oldCapturingTeam != this.capturingTeam || !oldCapturingTime.equals(this.capturingTime)) { this.match.callEvent(new CapturingTimeChangeEvent(this.match, this)); this.match.callEvent(new GoalStatusChangeEvent(this.match, this, null)); } if (oldCapturingTeam != this.capturingTeam) { this.match.callEvent( new CapturingTeamChangeEvent(this.match, this, oldCapturingTeam, this.capturingTeam)); } if (oldControllingTeam != this.controllingTeam) { this.match.callEvent( new ControllerChangeEvent(this.match, this, oldControllingTeam, this.controllingTeam)); if (this.controllingTeam == null) { this.match.callEvent(new GoalCompleteEvent(this.match, this, oldControllingTeam, false)); } else { this.match.callEvent(new GoalCompleteEvent(this.match, this, this.controllingTeam, true)); } } }
Example 13
Source File: Browser.java From aquality-selenium-java with Apache License 2.0 | 5 votes |
/** * Sets web driver implicit wait timeout * Be careful with using this method. Implicit timeout can affect to duration of driver operations * * @param timeout duration of time to wait */ public void setImplicitWaitTimeout(Duration timeout) { localizedLogger.debug("loc.browser.implicit.timeout", timeout.getSeconds()); if (!timeout.equals(getImplicitWaitTimeout())) { getDriver().manage().timeouts().implicitlyWait(timeout.getSeconds(), TimeUnit.SECONDS); implicitTimeout = timeout; } }
Example 14
Source File: TimeUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static long daysRoundingUp(Duration duration) { final long days = duration.toDays(); return duration.equals(Duration.ofDays(days)) ? days : days + 1; }
Example 15
Source File: DurationFormatter.java From pikatimer with GNU General Public License v3.0 | 4 votes |
public static final String durationToString(Duration d, Integer p, Boolean printHours, RoundingMode rm) { // d is the duration to print // p is the precision. 0 for no sub-seconds, // hours for padding the time with a 00: if it is under 1 hour // rm is the rounding mode. see java.math.RoundingMode for options Boolean isNegative = false; //System.out.println("durationToString start with " + d.toNanos() + " and " + p.toString() + " or " + d.toString()); //String result = d.toString(); //result = d.toString().replace("PT", "").replace("H",":").replace("M",":"); if (d == null || d.isZero() || d.equals(Duration.ofNanos(Long.MAX_VALUE))) return ""; if (d.isNegative()) { isNegative = true; d=d.negated(); } Long s = d.getSeconds(); Long H = s/3600; Long M = (s%3600)/60; s = s -(M*60 + H * 3600); Integer t = d.getNano(); //if (d.toNanos() == 0) return ""; BigDecimal S = new BigDecimal(d.getNano()).divide(new BigDecimal(1000000000)).setScale(p, rm); //System.out.println("DurationFormatter::durationToString: H:" + H.toString() + " M:" + M.toString() + " s:" + s.toString() + " S:" + S.toPlainString()); if (p == 0 && S.compareTo(new BigDecimal(1)) == 0) { s+= 1; if (s==60){ s=0L; M++; if (M==60) { M = 0L; H++ ; } } } String r = ""; if (isNegative) r = "-"; if (H > 0 ) r += H.toString() + ":"; if (H == 0 && printHours) r += "0:"; if (M > 9) r += M.toString() +":"; if (M < 10 && M > 0) { if (H > 0 || printHours ) r+= "0" + M.toString()+":"; else r+= M.toString()+":"; } if ((H > 0 || printHours ) && M == 0) r+= "00:"; if (s > 9 ) r+= s.toString(); if (s < 10 && s > 0) r+= "0" + s.toString(); if (p > 0 && s > 0) r += S.toPlainString().replace("0.", "."); if (p > 0 && s==0) r+="00" + S.toPlainString().replace("0.", "."); if (p == 0 && s == 0) r+="00"; return r; }
Example 16
Source File: Result.java From pikatimer with GNU General Public License v3.0 | 4 votes |
public void recalcTimeProperties(){ if (pendingRecalc){ //System.out.println("Result::recalcTimeProperties for bib " + bib.get()); // System.out.println(" StartDuration: " + startDuration.toString()); // System.out.println(" waveStartDuration: " + waveStartDuration.toString()); // System.out.println(" finishDuration: " + finishDuration.toString()); if (!startDuration.equals(startDurationProperty.get())) startDurationProperty.set(startDuration); if (!waveStartDuration.equals(waveStartDurationProperty.get())) waveStartDurationProperty.set(waveStartDuration); Duration startOffset = Duration.ZERO; if (splitMap.containsKey(0)) { startOffset = Duration.ofNanos(splitMap.get(0)).minus(waveStartDuration); } if (!startOffset.equals(startOffsetProperty.get())) startOffsetProperty.set(startOffset); if (finishDuration.isZero()) { finishDurationProperty.setValue(Duration.ofNanos(Long.MAX_VALUE)); finishTODProperty.setValue(Duration.ofNanos(Long.MAX_VALUE)); } else { finishDurationProperty.setValue(finishDuration.minus(startDuration)); if (finishDuration.toDays()> 0) { finishTODProperty.setValue(finishDuration.minus(Duration.ofDays(finishDuration.toDays()))); } else finishTODProperty.setValue(finishDuration); } if (finishDuration.isZero()) finishGunDurationProperty.setValue(Duration.ofNanos(Long.MAX_VALUE)); else finishGunDurationProperty.setValue(finishDuration.minus(waveStartDuration)); // // System.out.println(" chipTime: " + finishDurationProperty.get().toString()); // System.out.println(" gunTime: " + finishGunDurationProperty.get().toString()); // now loop through and fix the splits... // missing splits are set to MAX_VALUE splitMap.keySet().forEach(splitID -> { Duration d; if (splitID != 0){ d = Duration.ofNanos(splitMap.get(splitID)).minus(startDuration); if (d.isNegative()) d = Duration.ofNanos(Long.MAX_VALUE); } else { d = Duration.ofNanos(splitMap.get(splitID)); } if (splitPropertyMap.containsKey(splitID)) splitPropertyMap.get(splitID).set(d); else splitPropertyMap.put(splitID, new SimpleObjectProperty(d)); }); splitPropertyMap.keySet().forEach(splitID -> { if (!splitMap.containsKey(splitID)) splitPropertyMap.get(splitID).set(Duration.ofNanos(Long.MAX_VALUE)); }); revision.set(revision.get() + 1); //System.out.println("Result revision is now " + revision.getValue().toString()); pendingRecalc = false; } }
Example 17
Source File: MonoCacheTime.java From reactor-core with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void signalCached(Signal<T> signal) { Signal<T> signalToPropagate = signal; if (STATE.compareAndSet(main, this, signal)) { Duration ttl = null; try { ttl = main.ttlGenerator.apply(signal); } catch (Throwable generatorError) { signalToPropagate = Signal.error(generatorError); STATE.set(main, signalToPropagate); if (signal.isOnError()) { //noinspection ThrowableNotThrown Exceptions.addSuppressed(generatorError, signal.getThrowable()); } } if (ttl != null) { if (ttl.isZero()) { //immediate cache clear main.run(); } else if (!ttl.equals(DURATION_INFINITE)) { main.clock.schedule(main, ttl.toNanos(), TimeUnit.NANOSECONDS); } //else TTL is Long.MAX_VALUE, schedule nothing but still cache } else { //error during TTL generation, signal != updatedSignal, aka dropped if (signal.isOnNext()) { Operators.onNextDropped(signal.get(), currentContext()); } //if signal.isOnError(), avoid dropping the error. it is not really dropped but already suppressed //in all cases, unless nextDropped hook throws, immediate cache clear main.run(); } } for (Operators.MonoSubscriber<T, T> inner : SUBSCRIBERS.getAndSet(this, TERMINATED)) { if (signalToPropagate.isOnNext()) { inner.complete(signalToPropagate.get()); } else if (signalToPropagate.isOnError()) { inner.onError(signalToPropagate.getThrowable()); } else { inner.onComplete(); } } }