Java Code Examples for javax.xml.datatype.Duration

The following examples show how to use javax.xml.datatype.Duration. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jdmn   Source File: DefaultDateTimeType.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: yawl   Source File: caseMgt.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
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 3
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 Project: jdmn   Source File: CredDecSignavioBenchmarkTest.java    License: Apache License 2.0 6 votes vote down vote up
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 5
@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 6
Source Project: jdmn   Source File: DoubleMixedJavaTimeFEELLib.java    License: Apache License 2.0 5 votes vote down vote up
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 Project: jdmn   Source File: DoubleSignavioDurationType.java    License: Apache License 2.0 5 votes vote down vote up
@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 8
Source Project: jdk1.8-source-analysis   Source File: DurationDV.java    License: Apache License 2.0 5 votes vote down vote up
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 9
Source Project: cxf   Source File: DatatypeFactory.java    License: Apache License 2.0 5 votes vote down vote up
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 10
Source Project: yawl   Source File: XMLUtils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source Project: jdmn   Source File: MixedJavaTimeFEELLib.java    License: Apache License 2.0 5 votes vote down vote up
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 12
Source Project: jdmn   Source File: MixedJavaTimeFEELLib.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: JDKSourceCode1.8   Source File: DurationDV.java    License: MIT License 5 votes vote down vote up
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 14
Source Project: jdmn   Source File: DefaultSignavioDurationType.java    License: Apache License 2.0 5 votes vote down vote up
@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 15
Source Project: jdmn   Source File: DoubleDurationType.java    License: Apache License 2.0 5 votes vote down vote up
@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 16
Source Project: jdmn   Source File: JavaTimeCalendarType.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: jdmn   Source File: DefaultDurationType.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
public String print(Duration duration) {
    return duration.toString();
}
 
Example 19
Source Project: hottub   Source File: DatatypeFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
    * <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 20
Source Project: Bytecoder   Source File: DatatypeFactoryImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
    * <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 21
Source Project: yawl   Source File: YTimer.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public long schedule(YTimedObject timee, Duration duration) {
    long durationAsMilliseconds = duration.getTimeInMillis(new Date());
    return schedule(timee, durationAsMilliseconds);
}
 
Example 22
Source Project: jdk8u60   Source File: DatatypeFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
    * <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 23
Source Project: java-client-api   Source File: DocumentManagerImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void protect(String temporalDocumentURI, String temporalCollection, ProtectionLevel level, Duration duration, Transaction transaction) {
  protect(temporalDocumentURI, temporalCollection, transaction, level, duration.toString(), null, null);
}
 
Example 24
@Override
protected DMNDialectDefinition<Double, LocalDate, OffsetTime, ZonedDateTime, Duration, TestCases> makeDialect() {
    return new DoubleMixedJavaTimeKotlinStandardDMNDialectDefinition();
}
 
Example 25
Source Project: jdmn   Source File: BaseDefaultDurationType.java    License: Apache License 2.0 4 votes vote down vote up
protected int compare(javax.xml.datatype.Duration duration1, javax.xml.datatype.Duration duration2) {
    javax.xml.datatype.Duration lhs = normalize(duration1);
    javax.xml.datatype.Duration rhs = normalize(duration2);
    return lhs.compare(rhs);
}
 
Example 26
/**
    * <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 27
Source Project: jdmn   Source File: StandardDMNDialectDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public FEELLib<BigDecimal, XMLGregorianCalendar, XMLGregorianCalendar, XMLGregorianCalendar, Duration> createFEELLib() {
    return new DefaultFEELLib();
}
 
Example 28
Source Project: yawl   Source File: Utils.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Duration stringXML2Duration(String lexicalRepresentation)
           throws DatatypeConfigurationException {
	return DatatypeFactory.newInstance().newDuration(lexicalRepresentation);
}
 
Example 29
public String print(Duration duration) {
    return duration.toString();
}
 
Example 30
Source Project: jdmn   Source File: Person.java    License: Apache License 2.0 4 votes vote down vote up
@com.fasterxml.jackson.annotation.JsonGetter("Years and Months Duration")
Duration getYearsAndMonthsDuration();