protected CacheBuilder<Object, Object> createCacheBuilder( Duration expireAfterWriteDuration, Duration refreshAfterWriteDuration) { return CacheBuilder.newBuilder() .expireAfterWrite(expireAfterWriteDuration.getValue(), expireAfterWriteDuration.getUnit()) .refreshAfterWrite( refreshAfterWriteDuration.getValue(), refreshAfterWriteDuration.getUnit()); }
/** Test method for {@link org.jajuk.ui.helpers.Duration#getDuration()}. */ @Test public void testGetDuration() { Duration dur = new Duration(234); Duration dur2 = new Duration(233); assertEquals(234, dur.getDuration()); assertEquals(233, dur2.getDuration()); }
/** Test of isContains method, of class Duration. */ public void testIsContains() { System.out.println("isContains"); Duration duration = new Duration(new SimpleDate(2008, 12, 26), new SimpleDate(2008, 12, 30)); Duration instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); boolean expResult = true; boolean result = instance.isContains(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); expResult = true; result = instance.isContains(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2008, 12, 24), new SimpleDate(2008, 12, 28)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); expResult = false; result = instance.isContains(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2008, 11, 24), new SimpleDate(2008, 11, 28)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); expResult = false; result = instance.isContains(duration); assertEquals(expResult, result); }
/** Test of getUnionDuration method, of class Duration. */ public void testGetUnionDuration() { System.out.println("getUnionDuration"); Duration duration = new Duration(new SimpleDate(2008, 12, 24), new SimpleDate(2008, 12, 28)); Duration instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); Duration expResult = new Duration(new SimpleDate(2008, 12, 24), new SimpleDate(2008, 12, 31)); Duration result = instance.getUnionDuration(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2007, 12, 24), new SimpleDate(2007, 12, 28)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); expResult = new Duration(new SimpleDate(2007, 12, 24), new SimpleDate(2008, 12, 31)); result = instance.getUnionDuration(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2008, 12, 28), new SimpleDate(2008, 12, 29)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 26)); expResult = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 29)); result = instance.getUnionDuration(duration); assertEquals(expResult, result); duration = new Duration(new SimpleDate(2008, 12, 31), new SimpleDate(2008, 12, 31)); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 25)); expResult = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); result = instance.getUnionDuration(duration); assertEquals(expResult, result); }
/** Test of getEndDate method, of class Duration. */ public void testGetEndDate() { System.out.println("getEndDate"); Duration instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 31)); SimpleDate expResult = new SimpleDate(2008, 12, 31); SimpleDate result = instance.getEndDate(); assertEquals(expResult, result); }
/** Test basic rendering and parsing of arguments */ public void testDurationRender() { final Duration duration = new Duration(); duration.setSnippet("1234"); final DRLOutput out = new DRLOutput(); duration.renderDRL(out); final String res = out.getDRL(); System.out.println(res); assertEquals("\tduration 1234\n", res); }
private static QueueDescriptor newQueueDescriptor(String name, String description) { QueueDescriptor desc = new QueueDescriptor(name); desc.setDescription(description); desc.setJndiName("jms/queue/" + name); desc.setMaxRetries(10); desc.setRetryDelay(Duration.parse("PT30S")); desc.setRetryDelayMultiplier(200); desc.setMaxRetryDelay(Duration.parse("PT10M")); return desc; }
/* */ public Duration newDurationYearMonth(long durationInMilliseconds) /* */ { /* 615 */ Duration fullDuration = newDuration(durationInMilliseconds); /* 616 */ boolean isPositive = fullDuration.getSign() != -1; /* 617 */ BigInteger years = (BigInteger) fullDuration.getField(DatatypeConstants.YEARS); /* */ /* 619 */ if (years == null) years = BigInteger.ZERO; /* 620 */ BigInteger months = (BigInteger) fullDuration.getField(DatatypeConstants.MONTHS); /* */ /* 622 */ if (months == null) months = BigInteger.ZERO; /* */ /* 624 */ return newDurationYearMonth(isPositive, years, months); /* */ }
/** * Normalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a * timeZone is present but it is not Z then we convert the date/time datatype to Z using the * addition operation defined in <a * href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes">Adding Duration to * dateTimes (W3C XML Schema, part 2 appendix E).</a> * * @see #addDuration */ public void normalize() { if (!isUTC()) return; else if ((_zoneHour == 0) && (_zoneMinute == 0)) return; else { Duration temp = new Duration(); temp.setHour(_zoneHour); temp.setMinute(_zoneMinute); if (isZoneNegative()) temp.setNegative(); this.addDuration(temp); // reset the zone this.setZone((short) 0, (short) 0); temp = null; } }
public void shouldSerializeAndDeserializeFromJson() throws Exception { Duration d = Duration.of("10m"); ObjectMapper om = new ObjectMapper(); String ser = om.writeValueAsString(d); Duration dd = om.readValue(ser, Duration.class); assertEquals(dd, d); }
/** {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((expiryDuration == null) ? 0 : expiryDuration.hashCode()); return result; }
public static void estimateKeyDerivationTime() { // This is run in the background after startup. If we haven't recorded it before, do a key // derivation to see // how long it takes. This helps us produce better progress feedback, as on Windows we don't // currently have a // native Scrypt impl and the Java version is ~3 times slower, plus it depends a lot on CPU // speed. checkGuiThread(); estimatedKeyDerivationTime = Main.instance.prefs.getExpectedKeyDerivationTime(); if (estimatedKeyDerivationTime == null) { new Thread( () -> { log.info("Doing background test key derivation"); KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS); long start = System.currentTimeMillis(); scrypt.deriveKey("test password"); long msec = System.currentTimeMillis() - start; log.info("Background test key derivation took {}msec", msec); Platform.runLater( () -> { estimatedKeyDerivationTime = Duration.ofMillis(msec); Main.instance.prefs.setExpectedKeyDerivationTime(estimatedKeyDerivationTime); }); }) .start(); } }
public void setLinger(TcpSocket fan, Duration v) { try { if (v == null) socket.setSoLinger(false, 0); else socket.setSoLinger(true, (int) (v.sec())); } catch (IOException e) { throw IOErr.make(e); } }
public void setReceiveTimeout(TcpSocket fan, Duration v) { try { if (v == null) socket.setSoTimeout(0); else socket.setSoTimeout((int) (v.millis())); } catch (IOException e) { throw IOErr.make(e); } }
public void testElapsedBusinessDays() { CalendarDate nov1 = CalendarDate.from(2004, 11, 1); CalendarDate nov30 = CalendarDate.from(2004, 11, 30); CalendarInterval interval = CalendarInterval.inclusive(nov1, nov30); assertEquals(Duration.days(30), interval.length()); // 1 holiday (Thanksgiving on a Thursday) + 8 weekend days. assertEquals(21, businessCalendar().getElapsedBusinessDays(interval)); }
/** Test of getDurationInDays method, of class Duration. */ public void testGetDurationInDays() { System.out.println("getDurationInDays"); Duration instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 25)); long expResult = 0L; long result = instance.getDurationInDays(); assertEquals(expResult, result); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2008, 12, 26)); expResult = 1L; result = instance.getDurationInDays(); assertEquals(expResult, result); instance = new Duration(new SimpleDate(2008, 12, 25), new SimpleDate(2009, 1, 1)); expResult = 7L; result = instance.getDurationInDays(); assertEquals(expResult, result); }
public String formatCompact(Object durationObject) { StringBuffer toAppendTo = new StringBuffer(); long duration = ((Duration) durationObject).getEncodedMillis(); if (((Duration) durationObject).isWork() && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) { duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit()); } double value = Duration.getValue(duration); int type = Duration.getEffectiveType(duration); if (value > 0D && showPlusSign) toAppendTo.append("+"); boolean isPercent = Duration.isPercent(duration); if (isPercent) value *= 100.0; toAppendTo.append(DECIMAL_FORMAT.format(value)); String unit = formatTypeUnit( type, (Math.abs(value) == 1.0), false, Duration.isPercent(duration), Duration.isEstimated(duration), 3); toAppendTo.append(unit); return toAppendTo.toString(); }
/* (non-Javadoc) * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) */ public StringBuffer format(Object durationObject, StringBuffer toAppendTo, FieldPosition pos) { long duration = ((Duration) durationObject).getEncodedMillis(); if (((Duration) durationObject).isWork() && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) { duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit()); } double value = Duration.getValue(duration); int type = Duration.getEffectiveType(duration); if (value > 0D && showPlusSign) toAppendTo.append("+"); boolean isPercent = Duration.isPercent(duration); if (isPercent) value *= 100.0; DECIMAL_FORMAT.format(value, toAppendTo, pos); String unit = formatTypeUnit( type, (Math.abs(value) == 1.0), EditOption.getInstance().isAddSpaceBeforeLabel(), Duration.isPercent(duration), Duration.isEstimated(duration), EditOption.getInstance().getViewAs(type)); toAppendTo.append(unit); return toAppendTo; }
/* (non-Javadoc) * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition) */ public Object parseObject(String durationString, ParsePosition pos) { Object result = null; if (durationString.length() == 0) return null; if (durationString.charAt(pos.getIndex()) == '+') // if string begins with + sign, ignore it pos.setIndex(pos.getIndex() + 1); Number numberResult = DECIMAL_FORMAT.parse(durationString, pos); if (numberResult == null) return null; String durationPart = durationString.substring(pos.getIndex()); durationPart = durationPart.trim(); Matcher matcher; for (int i = 0; i < TYPE_COUNT; i++) { // find hte appropriate units matcher = pattern[i].matcher(durationPart); if (matcher.matches()) { int timeUnit = (matcher.group(1) != null) ? i : TimeUnit .NONE; // first group is units. If no units, then it will match, but should use // default: NONE double value = numberResult.doubleValue(); if (timeUnit == TimeUnit.PERCENT || timeUnit == TimeUnit.ELAPSED_PERCENT) value /= 100.0; if (timeUnit == TimeUnit.NONE && isWork) { if (canBeNonTemporal) timeUnit = TimeUnit.NON_TEMPORAL; else timeUnit = ScheduleOption.getInstance() .getWorkUnit(); // use default work unit if work and nothing entered } long longResult = Duration.getInstance(value, timeUnit); if (Duration.millis(longResult) > Duration.MAX_DURATION) // check for too big return null; if (matcher.group(2).length() != 0) { // second group is estimated longResult = Duration.setAsEstimated(longResult, true); } result = new Duration(longResult); return result; } } return null; }
public Duration getLinger(TcpSocket fan) { try { int linger = socket.getSoLinger(); if (linger < 0) return null; return Duration.makeSec(linger); } catch (IOException e) { throw IOErr.make(e); } }
public Duration getReceiveTimeout(TcpSocket fan) { try { int timeout = socket.getSoTimeout(); if (timeout <= 0) return null; return Duration.makeMillis(timeout); } catch (IOException e) { throw IOErr.make(e); } }
public Date add(Date date, Duration duration) { Date end = null; if (duration.isBusinessTime()) { DayPart dayPart = findDayPart(date); boolean isInbusinessHours = (dayPart != null); if (!isInbusinessHours) { Object[] result = new Object[2]; findDay(date).findNextDayPartStart(0, date, result); date = (Date) result[0]; dayPart = (DayPart) result[1]; } long millis = convertToMillis(duration); end = dayPart.add(date, millis, duration.isBusinessTime()); } else { long millis = convertToMillis(duration); end = new Date(date.getTime() + millis); } return end; }
public TcpSocket connect(TcpSocket fan, IpAddr addr, long port, Duration timeout) { try { // connect int javaTimeout = (timeout == null) ? 0 : (int) timeout.millis(); socket.connect(new InetSocketAddress(addr.peer.java, (int) port), javaTimeout); connected(fan); return fan; } catch (IOException e) { throw IOErr.make(e); } }
/** Test of getTodayDurationByYears method, of class Duration. */ public void testGetTodayDurationByYears() { System.out.println("getTodayDurationByYears"); int durationInYears = 1; java.util.Calendar end = java.util.Calendar.getInstance(); java.util.Calendar start = java.util.Calendar.getInstance(); start.add(java.util.Calendar.YEAR, -durationInYears); Duration expResult = new Duration(start, end); Duration result = Duration.getTodayDurationByYears(durationInYears); assertEquals(expResult, result); }
public StatsCollector() { counters = new EnumMap<Counter, AtomicInteger>(Counter.class); durations = new EnumMap<Duration, AtomicLong>(Duration.class); for (Counter counter : Counter.values()) { counters.put(counter, new AtomicInteger(0)); } for (Duration duration : Duration.values()) { durations.put(duration, new AtomicLong(0)); } }
@Override public int hashCode() { int result = from.hashCode(); result = 31 * result + to.hashCode(); result = 31 * result + duration.hashCode(); result = 31 * result + holiday.hashCode(); result = 31 * result + (loc != null ? loc.hashCode() : 0); result = 31 * result + shifters.hashCode(); result = 31 * result + selector.hashCode(); result = 31 * result + (customDayOfMonth != null ? customDayOfMonth.hashCode() : 0); result = 31 * result + (customDayOfYear != null ? customDayOfYear.hashCode() : 0); return result; }
/** * Defines the characteristics of a <i>TranslateTransition</i>. Each call results in ONE segment * of motion. When that segment is finished, it "chains" another call to <i>startMotion()</i> * (which is NOT recursion)! The initial call is made by the managing <i>Army</i> object; * subsequent calls are made through the "chaining" process described here. * * @param engageInCombat TODO */ public void startMotion(boolean engageInCombat) { Army opposingArmy = armyAllegiance.getOpposingArmy(); Actor opponent = opposingArmy.findNearestOpponent( this); // could legitimately return a null: 1) no one is visible 2) no Actors in // opposing army Point2D newLocation; if (opponent != null) { System.out.printf( "ToMove:[%.1f:%.1f] Opponent:[%.1f:%.1f]\n", getAvatar().getTranslateX(), getAvatar().getTranslateY(), opponent.getAvatar().getTranslateX(), opponent.getAvatar().getTranslateX()); double DISTANCE_FOR_BATTLE = 50.0; if (engageInCombat && distanceTo(opponent) < DISTANCE_FOR_BATTLE) { double h1, h2, h3, h4; // debug code h1 = this.getHealth(); h2 = opponent.getHealth(); combatRound(opponent); h3 = this.getHealth(); h4 = opponent.getHealth(); h4 = h4; if (this.getHealth() <= 0.0) { armyAllegiance.removeNowDeadActor(this); } if (opponent.getHealth() <= 0.0) { opponent.armyAllegiance.removeNowDeadActor(opponent); } } // end if (combat) newLocation = findNewLocation(opponent); } else // end if (test for null opponent) newLocation = meander(); // null opponent means we wander around close to our current location if (tt.getStatus() != Animation.Status.RUNNING) { // if NOT yet RUNNING, start . . . otherwise, do nothing. // tt.setToX(Math.random()*getAvatar().getScene().getWidth()); // tt.setToY(Math.random()*getAvatar().getScene().getHeight()); tt.setToX(validateCoordinate(newLocation).getX()); tt.setToY(validateCoordinate(newLocation).getY()); tt.setDuration( Duration.seconds(MAX_SPEED / (getSpeed() * (armyAllegiance.getSpeedControllerValue())))); tt.setOnFinished(event -> startMotion(true)); // NOT RECURSION!!!! tt .play(); // give assembled object to the render engine (of course, play() is an // object-oriented method which has access to "this" inside, and it can use // "this" to give to the render engine. } } // end startMotion()
/** * Repeatedly applies this instance's input value to the given function until one of the following * occurs: * * <ol> * <li>the function returns neither null nor false, * <li>the function throws an unignored exception, * <li>the timeout expires, * <li> * <li>the current thread is interrupted * </ol> * * @param isTrue the parameter to pass to the {@link ExpectedCondition} * @param <V> The function's expected return type. * @return The functions' return value. */ public <V> V until(Function<? super T, V> isTrue) { long end = clock.laterBy(timeout.in(MILLISECONDS)); Throwable lastException = null; while (true) { try { V value = isTrue.apply(input); if (value != null && Boolean.class.equals(value.getClass())) { if (Boolean.TRUE.equals(value)) { return value; } } else if (value != null) { return value; } } catch (Throwable e) { lastException = propagateIfNotIngored(e); } // Check the timeout after evaluating the function to ensure conditions // with a zero timeout can succeed. if (!clock.isNowBefore(end)) { String toAppend = message == null ? " waiting for " + isTrue.toString() : ": " + message; String timeoutMessage = String.format("Timed out after %d seconds%s", timeout.in(SECONDS), toAppend); if (lastException instanceof RuntimeException || lastException == null) { throw timeoutException(timeoutMessage, (RuntimeException) lastException); } throw timeoutException(timeoutMessage, lastException); } try { sleeper.sleep(interval); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new WebDriverException(e); } } }
public Duration copy() { Duration dst = new Duration(); dst.value = value == null ? null : value.copy(); dst.comparator = comparator == null ? null : comparator.copy(); dst.units = units == null ? null : units.copy(); dst.system = system == null ? null : system.copy(); dst.code = code == null ? null : code.copy(); return dst; }
/** * Returns an appropriate XQuery type for the specified Java object. * * @param o object * @return item type or {@code null} if no appropriate type was found */ private static Type type(final Object o) { final Type t = type(o.getClass()); if (t != null) return t; if (o instanceof Element) return NodeType.ELM; if (o instanceof Document) return NodeType.DOC; if (o instanceof DocumentFragment) return NodeType.DOC; if (o instanceof Attr) return NodeType.ATT; if (o instanceof Comment) return NodeType.COM; if (o instanceof ProcessingInstruction) return NodeType.PI; if (o instanceof Text) return NodeType.TXT; if (o instanceof Duration) { final Duration d = (Duration) o; return !d.isSet(DatatypeConstants.YEARS) && !d.isSet(DatatypeConstants.MONTHS) ? AtomType.DTD : !d.isSet(DatatypeConstants.HOURS) && !d.isSet(DatatypeConstants.MINUTES) && !d.isSet(DatatypeConstants.SECONDS) ? AtomType.YMD : AtomType.DUR; } if (o instanceof XMLGregorianCalendar) { final QName type = ((XMLGregorianCalendar) o).getXMLSchemaType(); if (type == DatatypeConstants.DATE) return AtomType.DAT; if (type == DatatypeConstants.DATETIME) return AtomType.DTM; if (type == DatatypeConstants.TIME) return AtomType.TIM; if (type == DatatypeConstants.GYEARMONTH) return AtomType.YMO; if (type == DatatypeConstants.GMONTHDAY) return AtomType.MDA; if (type == DatatypeConstants.GYEAR) return AtomType.YEA; if (type == DatatypeConstants.GMONTH) return AtomType.MON; if (type == DatatypeConstants.GDAY) return AtomType.DAY; } return null; }