List of usage examples for org.joda.time Duration compareTo
public int compareTo(ReadableDuration other)
From source file:kr.debop4j.timeperiod.test.samples.TimeRangePeriodRelationTestData.java
License:Apache License
public TimeRangePeriodRelationTestData(DateTime start, DateTime end, Duration duration) { Guard.shouldBe(duration.compareTo(Duration.ZERO) >= 0, "duration? 0??? ? ."); setReference(new TimeRange(start, end, true)); DateTime beforeEnd = start.minus(duration); DateTime beforeStart = beforeEnd.minus(reference.getDuration()); DateTime insideStart = start.plus(duration); DateTime insideEnd = end.minus(duration); DateTime afterStart = end.plus(duration); DateTime afterEnd = afterStart.plus(reference.getDuration()); after = new TimeRange(beforeStart, beforeEnd, true); startTouching = new TimeRange(beforeStart, start, true); startInside = new TimeRange(beforeStart, insideStart, true); insideStartTouching = new TimeRange(start, afterStart, true); enclosingStartTouching = new TimeRange(start, insideEnd, true); enclosing = new TimeRange(insideStart, insideEnd, true); enclosingEndTouching = new TimeRange(insideStart, end, true); exactMatch = new TimeRange(start, end, true); inside = new TimeRange(beforeStart, afterEnd, true); insideEndTouching = new TimeRange(beforeStart, end, true); endInside = new TimeRange(insideEnd, afterEnd, true); endTouching = new TimeRange(end, afterEnd, true); before = new TimeRange(afterStart, afterEnd, true); allPeriods.add(reference);//w w w.j av a 2 s . c om allPeriods.add(after); allPeriods.add(startTouching); allPeriods.add(startInside); allPeriods.add(insideStartTouching); allPeriods.add(enclosingStartTouching); allPeriods.add(enclosing); allPeriods.add(enclosingEndTouching); allPeriods.add(exactMatch); allPeriods.add(inside); allPeriods.add(insideEndTouching); allPeriods.add(endInside); allPeriods.add(endTouching); allPeriods.add(before); }
From source file:kr.debop4j.timeperiod.TimeBlock.java
License:Apache License
protected void assertValidDuration(Duration duration) { assert duration.compareTo(ZeroDuration) >= 0 : "duration? 0 ??? ."; }
From source file:kr.debop4j.timeperiod.TimeBlock.java
License:Apache License
@Override public ITimeBlock getPreviousBlock(Duration offset) { Duration endOffset = (offset.compareTo(ZERO) > 0) ? new Duration(-offset.getMillis()) : offset; return new TimeBlock(getDuration(), getStart().plus(endOffset), readonly); }
From source file:kr.debop4j.timeperiod.TimeBlock.java
License:Apache License
@Override public ITimeBlock getNextBlock(Duration offset) { Duration startOffset = (offset.compareTo(ZERO) > 0) ? offset : new Duration(-offset.getMillis()); return new TimeBlock(getEnd().plus(startOffset), getDuration(), readonly); }
From source file:kr.debop4j.timeperiod.TimePeriodChain.java
License:Apache License
/** moment ?? duration ?? ? ? ( ? ? ) */ protected void assertSpaceBefore(DateTime moment, Duration duration) { boolean hasSpace = moment != TimeSpec.MinPeriodTime; if (hasSpace) { Duration remaining = new Duration(TimeSpec.MinPeriodTime, moment); hasSpace = duration.compareTo(remaining) <= 0; }//ww w . j av a2 s . c om shouldBe(hasSpace, "duration [%s] is out of range.", duration); }
From source file:kr.debop4j.timeperiod.TimePeriodChain.java
License:Apache License
/** moment ?? duration ?? ? ? ( ? ? ) */ protected void assertSpaceAfter(DateTime moment, Duration duration) { boolean hasSpace = moment != TimeSpec.MaxPeriodTime; if (hasSpace) { Duration remaining = new Duration(moment, TimeSpec.MaxPeriodTime); hasSpace = duration.compareTo(remaining) <= 0; }/*from w w w. jav a2s .c o m*/ shouldBe(hasSpace, "duration [%s] is out of range.", duration); }
From source file:kr.debop4j.timeperiod.tools.Times.java
License:Apache License
/** * Min duration.//from w w w . j av a 2s .c o m * * @param a the a * @param b the b * @return the duration */ public static Duration min(Duration a, Duration b) { if (a == null && b == null) return null; if (a == null) return b; if (b == null) return a; return a.compareTo(b) < 0 ? a : b; }
From source file:kr.debop4j.timeperiod.tools.Times.java
License:Apache License
/** * Max duration.//w w w. j a v a2 s .com * * @param a the a * @param b the b * @return the duration */ public static Duration max(Duration a, Duration b) { if (a == null && b == null) return null; if (a == null) return b; if (b == null) return a; return a.compareTo(b) > 0 ? a : b; }
From source file:org.apache.beam.runners.reference.JobServicePipelineResult.java
License:Apache License
@Nullable @Override// w w w . j a v a2s .c o m public State waitUntilFinish(Duration duration) { if (duration.compareTo(Duration.millis(1)) < 1) { // Equivalent to infinite timeout. return waitUntilFinish(); } else { CompletableFuture<State> result = CompletableFuture.supplyAsync(this::waitUntilFinish); try { return result.get(duration.getMillis(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Null result indicates a timeout. return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } }
From source file:org.apache.cloudstack.utils.process.ProcessRunner.java
License:Apache License
/** * Executes a process with provided list of commands with a given timeout that is less * than or equal to DEFAULT_MAX_TIMEOUT//from www .j a va 2 s.c o m * @param commands list of string commands * @param timeOut timeout duration * @return returns process result */ public ProcessResult executeCommands(final List<String> commands, final Duration timeOut) { Preconditions.checkArgument(commands != null && timeOut != null && timeOut.getStandardSeconds() > 0L && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0) && executor != null); int retVal = -2; String stdOutput = null; String stdError = null; try { final Process process = new ProcessBuilder().command(commands).start(); final Future<Integer> processFuture = executor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return process.waitFor(); } }); try { retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS); } catch (ExecutionException e) { retVal = -2; stdError = e.getMessage(); if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command due to execution error: " + e.getMessage()); } } catch (TimeoutException e) { retVal = -1; stdError = "Operation timed out, aborted"; if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command within timeout: " + e.getMessage()); } } finally { if (Strings.isNullOrEmpty(stdError)) { stdOutput = CharStreams.toString(new InputStreamReader(process.getInputStream())); stdError = CharStreams.toString(new InputStreamReader(process.getErrorStream())); } process.destroy(); } if (LOG.isTraceEnabled()) { LOG.trace("Process standard output: " + stdOutput); LOG.trace("Process standard error output: " + stdError); } } catch (IOException | InterruptedException e) { stdError = e.getMessage(); LOG.error("Exception caught error running commands: " + e.getMessage()); } return new ProcessResult(stdOutput, stdError, retVal); }