javax.xml.datatype.Duration Java Examples
The following examples show how to use
javax.xml.datatype.Duration.
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: DefaultDateTimeType.java From jdmn with Apache License 2.0 | 6 votes |
@Override public XMLGregorianCalendar dateTimeAddDuration(XMLGregorianCalendar xmlGregorianCalendar, Duration duration) { if (xmlGregorianCalendar == null || duration == null) { return null; } try { XMLGregorianCalendar clone = (XMLGregorianCalendar) xmlGregorianCalendar.clone(); clone.add(duration); return clone; } catch (Exception e) { String message = String.format("dateTimeSubtract(%s, %s)", xmlGregorianCalendar, duration); logError(message, e); return null; } }
Example #2
Source File: CredDecSignavioBenchmarkTest.java From jdmn with Apache License 2.0 | 6 votes |
public void executeInterpreter(long startTime) throws Exception { ApplicantImpl applicant = new ApplicantImpl(); applicant.setName("Amy"); applicant.setAge(lib.number("38")); applicant.setCreditScore(lib.number("100")); applicant.setPriorIssues(lib.asList("Late payment")); BigDecimal currentRiskAppetite = lib.number("50"); BigDecimal lendingThreshold = lib.number("25"); String pathName = "exported/dmn/complex/Example credit decision.dmn"; DMNModelRepository repository = readDMN(pathName); DMNInterpreter<BigDecimal, XMLGregorianCalendar, XMLGregorianCalendar, XMLGregorianCalendar, Duration> interpreter = dialectDefinition.createDMNInterpreter(repository, new LinkedHashMap<>()); RuntimeEnvironment runtimeEnvironment = RuntimeEnvironmentFactory.instance().makeEnvironment(); runtimeEnvironment.bind("applicant", applicant); runtimeEnvironment.bind("currentRiskAppetite", currentRiskAppetite); runtimeEnvironment.bind("lendingThreshold", lendingThreshold); TDRGElement decision = repository.findDRGElementByName(repository.getRootDefinitions(), "generateOutputData"); Object result = interpreter.evaluate(repository.makeDRGElementReference(decision), null, runtimeEnvironment); System.out.println(result); long endTime = System.currentTimeMillis(); System.out.println(String.format("Interpreted version took %s ms", endTime - startTime)); }
Example #3
Source File: XMLDatatypeMathUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static Literal operationsBetweenDurations(Literal leftLit, Literal rightLit, MathOp op) { Duration left = XMLDatatypeUtil.parseDuration(leftLit.getLabel()); Duration right = XMLDatatypeUtil.parseDuration(rightLit.getLabel()); try { switch (op) { case PLUS: // op:add-yearMonthDurations and op:add-dayTimeDurations return buildLiteral(left.add(right)); case MINUS: // op:subtract-yearMonthDurations and op:subtract-dayTimeDurations return buildLiteral(left.subtract(right)); case MULTIPLY: throw new ValueExprEvaluationException("Multiplication is not defined on xsd:duration."); case DIVIDE: throw new ValueExprEvaluationException("Division is not defined on xsd:duration."); default: throw new IllegalArgumentException("Unknown operator: " + op); } } catch (IllegalStateException e) { throw new ValueExprEvaluationException(e); } }
Example #4
Source File: caseMgt.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
private boolean validateDelayValue() { _sb.setDelayValueError(""); String value = (String) txtDelayValue.getText(); if (rbTime.isChecked()) { long delaySeconds = StringUtil.strToLong(value, -1); if (delaySeconds < 0) { _sb.setDelayValueError("Invalid seconds value"); } else _sb.setDelaySeconds(delaySeconds); } if (rbDuration.isChecked()) { Duration delayDuration = StringUtil.strToDuration(value); if (delayDuration == null) { _sb.setDelayValueError("Invalid Duration value"); } else _sb.setDelayDuration(delayDuration); } if (rbDate.isChecked()) { long seconds = StringUtil.xmlDateToLong(value); if (seconds < 0) { _sb.setDelayValueError("Invalid Datetime value (yyyy-MM-ddThh:mm:ss)"); } else _sb.setDelayDate(new Date(seconds)); } return _sb.getDelayValueError().length() == 0; }
Example #5
Source File: DefaultSignavioDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Boolean durationGreaterEqualThan(Duration first, Duration second) { if (first == null && second == null) { return null; } else if (first == null) { return null; } else if (second == null) { return null; } else { int compare = compare(first, second); return compare == DatatypeConstants.GREATER || compare == DatatypeConstants.EQUAL; } }
Example #6
Source File: DoubleMixedJavaTimeFEELLib.java From jdmn with Apache License 2.0 | 5 votes |
public Duration yearsAndMonthsDuration(LocalDate from, LocalDate to) { try { return this.durationLib.yearsAndMonthsDuration(from, to); } catch (Exception e) { String message = String.format("yearsAndMonthsDuration(%s, %s)", from, to); logError(message, e); return null; } }
Example #7
Source File: TestTimeDuration.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testStuff2() throws DatatypeConfigurationException { DatatypeFactory factory = DatatypeFactory.newInstance(); Duration d = factory.newDuration("P3D"); long secs1 = d.getTimeInMillis(new Date()) / 1000; Calendar c = Calendar.getInstance(); c.set(1970, 0, 1, 0, 0, 0); long secs2 = d.getTimeInMillis(c.getTime()) / 1000; System.out.printf("%d %d same = %s%n", secs1, secs2, secs1 == secs2); }
Example #8
Source File: DatatypeFactory.java From cxf with Apache License 2.0 | 5 votes |
public static Duration createDuration(String s) { try { return javax.xml.datatype.DatatypeFactory.newInstance().newDuration(s); } catch (DatatypeConfigurationException ex) { LogUtils.log(LOG, Level.SEVERE, "DATATYPE_FACTORY_INSTANTIATION_EXC", ex); } return null; }
Example #9
Source File: DoubleSignavioDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Boolean durationGreaterEqualThan(Duration first, Duration second) { if (first == null && second == null) { return null; } else if (first == null) { return null; } else if (second == null) { return null; } else { int compare = compare(first, second); return compare == DatatypeConstants.GREATER || compare == DatatypeConstants.EQUAL; } }
Example #10
Source File: DefaultDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Duration durationAdd(Duration first, Duration second) { if (first == null || second == null) { return null; } try { return first.add(second); } catch (Exception e) { String message = String.format("durationAdd(%s, %s)", first, second); logError(message, e); return null; } }
Example #11
Source File: DurationDV.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
protected Duration getDuration(DateTimeData date) { int sign = 1; if ( date.year<0 || date.month<0 || date.day<0 || date.hour<0 || date.minute<0 || date.second<0) { sign = -1; } return datatypeFactory.newDuration(sign == 1, date.year != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.year):null, date.month != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.month):null, date.day != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.day):null, date.hour != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.hour):null, date.minute != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.minute):null, date.second != DatatypeConstants.FIELD_UNDEFINED?new BigDecimal(String.valueOf(sign*date.second)):null); }
Example #12
Source File: JavaTimeCalendarType.java From jdmn with Apache License 2.0 | 5 votes |
protected TemporalAmount toTemporalDuration(Duration duration) { int days = normalize(duration.getDays()); int hours = normalize(duration.getHours()); int minutes = normalize(duration.getMinutes()); int seconds = normalize(duration.getSeconds()); java.time.Duration timeDuration = java.time.Duration.ofDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds); return duration.getSign() == -1 ? timeDuration.negated() : timeDuration; }
Example #13
Source File: XMLUtils.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public static Integer getDurationValueInMinutes(Element element, boolean withValidation) { try { Duration d = getDurationValue(element, withValidation); return Utils.duration2Minutes(d); } catch (Exception e) { // logger.error("'" + element.getName() + "' must be duration", e); addErrorValue(element, withValidation, "msgIntegerError"); return null; } }
Example #14
Source File: DoubleDurationType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public Duration durationAdd(Duration first, Duration second) { if (first == null || second == null) { return null; } try { return first.add(second); } catch (Exception e) { String message = String.format("durationAdd(%s, %s)", first, second); logError(message, e); return null; } }
Example #15
Source File: MixedJavaTimeFEELLib.java From jdmn with Apache License 2.0 | 5 votes |
public Duration timeOffset(ZonedDateTime dateTime) { try { return this.timeLib.timeOffset(dateTime); } catch (Exception e) { String message = String.format("timeOffset(%s)", dateTime); logError(message, e); return null; } }
Example #16
Source File: MixedJavaTimeFEELLib.java From jdmn with Apache License 2.0 | 5 votes |
@Override public BigDecimal years(Duration duration) { try { return BigDecimal.valueOf(this.durationLib.years(duration)); } catch (Exception e) { String message = String.format("years(%s)", duration); logError(message, e); return null; } }
Example #17
Source File: DurationDV.java From JDKSourceCode1.8 with MIT License | 5 votes |
protected Duration getDuration(DateTimeData date) { int sign = 1; if ( date.year<0 || date.month<0 || date.day<0 || date.hour<0 || date.minute<0 || date.second<0) { sign = -1; } return datatypeFactory.newDuration(sign == 1, date.year != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.year):null, date.month != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.month):null, date.day != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.day):null, date.hour != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.hour):null, date.minute != DatatypeConstants.FIELD_UNDEFINED?BigInteger.valueOf(sign*date.minute):null, date.second != DatatypeConstants.FIELD_UNDEFINED?new BigDecimal(String.valueOf(sign*date.second)):null); }
Example #18
Source File: DatatypeFactoryImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * <p>Obtain a new instance of a <code>Duration</code> * specifying the <code>Duration</code> as isPositive, years, months, days, hours, minutes, seconds.</p> * * <p>The XML Schema specification states that values can be of an arbitrary size. * Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values. * An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits * if implementation capacities are exceeded.</p> * * @param isPositive Set to <code>false</code> to create a negative duration. When the length * of the duration is zero, this parameter will be ignored. * @param years of this <code>Duration</code> * @param months of this <code>Duration</code> * @param days of this <code>Duration</code> * @param hours of this <code>Duration</code> * @param minutes of this <code>Duration</code> * @param seconds of this <code>Duration</code> * * @return New <code>Duration</code> created from the specified values. * * @throws IllegalArgumentException If values are not a valid representation of a <code>Duration</code>. * @throws UnsupportedOperationException If implementation cannot support requested values. * @throws NullPointerException If any values are <code>null</code>. * * @see #newDuration(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, * BigInteger hours, BigInteger minutes, BigDecimal seconds) */ public Duration newDuration( final boolean isPositive, final BigInteger years, final BigInteger months, final BigInteger days, final BigInteger hours, final BigInteger minutes, final BigDecimal seconds) { return new DurationImpl( isPositive, years, months, days, hours, minutes, seconds ); }
Example #19
Source File: DatatypeFactoryImpl.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * <p>Create a <code>Duration</code> of type <code>xdt:dayTimeDuration</code> using the specified * <code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> as defined in * <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration"> * XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>.</p> * * <p>The datatype <code>xdt:dayTimeDuration</code> is a subtype of <code>xs:duration</code> * whose lexical representation contains only day, hour, minute, and second components. * This datatype resides in the namespace <code>http://www.w3.org/2003/11/xpath-datatypes</code>.</p> * * <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.</p> * * @param isPositive Set to <code>false</code> to create a negative duration. When the length * of the duration is zero, this parameter will be ignored. * @param day Day of <code>Duration</code>. * @param hour Hour of <code>Duration</code>. * @param minute Minute of <code>Duration</code>. * @param second Second of <code>Duration</code>. * * @return New <code>Duration</code> created with the specified <code>day</code>, <code>hour</code>, <code>minute</code> * and <code>second</code>. * * @throws IllegalArgumentException If the values are not a valid representation of a * <code>Duration</code>: if any of the fields (day, hour, ...) is negative. */ public Duration newDurationDayTime( final boolean isPositive, final int day, final int hour, final int minute, final int second) { return new DurationDayTimeImpl( isPositive, day, hour, minute, second ); }
Example #20
Source File: YTimerParameters.java From yawl with GNU Lesser General Public License v3.0 | 4 votes |
public void setDuration(Duration duration) { _duration = duration; _timerType = TimerType.Duration; }
Example #21
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public String print(Duration duration) { return duration.toString(); }
Example #22
Source File: ICUDurationTest.java From j2objc with Apache License 2.0 | 4 votes |
@Override public Duration negate() { return new ICUTestDuration(-sign, fields); }
Example #23
Source File: Expiry.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
public void setDuration(Duration value) { this.duration = value; }
Example #24
Source File: DatatypeFactoryImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * <p>Obtain a new instance of a <code>Duration</code> * specifying the <code>Duration</code> as isPositive, years, months, days, hours, minutes, seconds.</p> * * <p>The XML Schema specification states that values can be of an arbitrary size. * Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values. * An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits * if implementation capacities are exceeded.</p> * * @param isPositive Set to <code>false</code> to create a negative duration. When the length * of the duration is zero, this parameter will be ignored. * @param years of this <code>Duration</code> * @param months of this <code>Duration</code> * @param days of this <code>Duration</code> * @param hours of this <code>Duration</code> * @param minutes of this <code>Duration</code> * @param seconds of this <code>Duration</code> * * @return New <code>Duration</code> created from the specified values. * * @throws IllegalArgumentException If values are not a valid representation of a <code>Duration</code>. * @throws UnsupportedOperationException If implementation cannot support requested values. * @throws NullPointerException If any values are <code>null</code>. * * @see #newDuration(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, * BigInteger hours, BigInteger minutes, BigDecimal seconds) */ public Duration newDuration( final boolean isPositive, final BigInteger years, final BigInteger months, final BigInteger days, final BigInteger hours, final BigInteger minutes, final BigDecimal seconds) { return new DurationImpl( isPositive, years, months, days, hours, minutes, seconds ); }
Example #25
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Duration parse(CharSequence lexical) { TODO.checkSpec("JSR222 Issue #42"); return DatatypeConverterImpl.getDatatypeFactory().newDuration(lexical.toString()); }
Example #26
Source File: DocumentManagerImpl.java From java-client-api with Apache License 2.0 | 4 votes |
@Override public void protect(String temporalDocumentURI, String temporalCollection, ProtectionLevel level, Duration duration, Transaction transaction) { protect(temporalDocumentURI, temporalCollection, transaction, level, duration.toString(), null, null); }
Example #27
Source File: AbstractDateTimeDV.java From JDKSourceCode1.8 with MIT License | 4 votes |
protected Duration getDuration(DateTimeData data) { return null; }
Example #28
Source File: StandardFEELProcessorTest.java From jdmn with Apache License 2.0 | 4 votes |
@Override protected DMNDialectDefinition<BigDecimal, XMLGregorianCalendar, XMLGregorianCalendar, XMLGregorianCalendar, Duration, TestCases> makeDialect() { return new StandardDMNDialectDefinition(); }
Example #29
Source File: StandardDMNDialectDefinition.java From jdmn with Apache License 2.0 | 4 votes |
@Override public FEELLib<BigDecimal, XMLGregorianCalendar, XMLGregorianCalendar, XMLGregorianCalendar, Duration> createFEELLib() { return new DefaultFEELLib(); }
Example #30
Source File: StandardCL2DMNInterpreterTest.java From jdmn with Apache License 2.0 | 4 votes |
@Override protected DMNDialectDefinition<BigDecimal, XMLGregorianCalendar, XMLGregorianCalendar, XMLGregorianCalendar, Duration, TestCases> getDialectDefinition() { return new StandardDMNDialectDefinition(); }