Example usage for javax.xml.datatype DatatypeConstants LESSER

List of usage examples for javax.xml.datatype DatatypeConstants LESSER

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants LESSER.

Prototype

int LESSER

To view the source code for javax.xml.datatype DatatypeConstants LESSER.

Click Source Link

Document

Comparison result.

Usage

From source file:DatatypeAPIUsage.java

public static void main(String[] args) {
    try {/*from   w  w  w.jav  a 2 s  . c om*/
        DatatypeFactory df = DatatypeFactory.newInstance();
        // my work number in milliseconds:
        Duration myPhone = df.newDuration(9054133519l);
        Duration myLife = df.newDuration(true, 29, 2, 15, 13, 45, 0);
        int compareVal = myPhone.compare(myLife);
        switch (compareVal) {
        case DatatypeConstants.LESSER:
            System.out.println("There are fewer milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.EQUAL:
            System.out.println("The same number of milliseconds are in my phone number and my lifespan.");
            break;
        case DatatypeConstants.GREATER:
            System.out.println("There are more milliseconds in my phone number than my lifespan.");
            break;
        case DatatypeConstants.INDETERMINATE:
            System.out.println("The comparison could not be carried out.");
        }

        // create a yearMonthDuration
        Duration ymDuration = df.newDurationYearMonth("P12Y10M");
        System.out.println("P12Y10M is of type: " + ymDuration.getXMLSchemaType());

        // create a dayTimeDuration (really this time)
        Duration dtDuration = df.newDurationDayTime("P10DT10H12M0S");
        System.out.println("P10DT10H12M0S is of type: " + dtDuration.getXMLSchemaType());

        // try to fool the factory!
        try {
            ymDuration = df.newDurationYearMonth("P12Y10M1D");
        } catch (IllegalArgumentException e) {
            System.out.println("'duration': P12Y10M1D is not 'yearMonthDuration'!!!");
        }

        XMLGregorianCalendar xgc = df.newXMLGregorianCalendar();
        xgc.setYear(1975);
        xgc.setMonth(DatatypeConstants.AUGUST);
        xgc.setDay(11);
        xgc.setHour(6);
        xgc.setMinute(44);
        xgc.setSecond(0);
        xgc.setMillisecond(0);
        xgc.setTimezone(5);
        xgc.add(myPhone);
        System.out.println("The approximate end of the number of milliseconds in my phone number was " + xgc);

        // adding a duration to XMLGregorianCalendar
        xgc.add(myLife);
        System.out.println("Adding the duration myLife to the above calendar:" + xgc);

        // create a new XMLGregorianCalendar using the string format of xgc.
        XMLGregorianCalendar xgcCopy = df.newXMLGregorianCalendar(xgc.toXMLFormat());

        // should be equal-if not what happened!!
        if (xgcCopy.compare(xgc) != DatatypeConstants.EQUAL) {
            System.out.println("oooops!");
        } else {
            System.out.println("Very good: " + xgc + " is equal to " + xgcCopy);
        }
    } catch (DatatypeConfigurationException dce) {
        System.err.println("error: Datatype error occurred - " + dce.getMessage());
        dce.printStackTrace(System.err);
    }
}

From source file:com.evolveum.midpoint.model.impl.trigger.TriggerScannerTaskHandler.java

/**
 * Returns true if the timestamp is in the "range of interest" for this scan run.
 *///from   w  w w  . j  ava2s . co  m
private boolean isHot(AbstractScannerResultHandler<ObjectType> handler, XMLGregorianCalendar timestamp) {
    if (handler.getThisScanTimestamp().compare(timestamp) == DatatypeConstants.LESSER) {
        return false;
    }
    return handler.getLastScanTimestamp() == null
            || handler.getLastScanTimestamp().compare(timestamp) == DatatypeConstants.LESSER;
}

From source file:com.evolveum.midpoint.schema.statistics.EnvironmentalPerformanceInformation.java

public static void addTo(EnvironmentalPerformanceInformationType rv,
        EnvironmentalPerformanceInformationType delta) {
    addProvisioningTo(rv, delta.getProvisioningStatistics());
    addMappingsTo(rv, delta.getMappingsStatistics());
    addNotificationsTo(rv, delta.getNotificationsStatistics());
    if (delta.getLastMessageTimestamp() != null) {
        if (rv.getLastMessageTimestamp() == null || rv.getLastMessageTimestamp()
                .compare(delta.getLastMessageTimestamp()) == DatatypeConstants.LESSER) {
            rv.setLastMessageTimestamp(delta.getLastMessageTimestamp());
            rv.setLastMessage(delta.getLastMessage());
        }//from w w  w  .  j a  va 2 s. c o m
    }
}

From source file:com.evolveum.midpoint.util.MiscUtil.java

public static boolean isBetween(XMLGregorianCalendar date, XMLGregorianCalendar start,
        XMLGregorianCalendar end) {
    return (date.compare(start) == DatatypeConstants.GREATER || date.compare(start) == DatatypeConstants.EQUAL)
            && (date.compare(end) == DatatypeConstants.LESSER || date.compare(end) == DatatypeConstants.EQUAL);
}

From source file:com.evolveum.midpoint.test.util.TestUtil.java

public static void assertBetween(String message, XMLGregorianCalendar start, XMLGregorianCalendar end,
        XMLGregorianCalendar actual) {
    assertNotNull(message + " is null", actual);
    if (start != null) {
        assertTrue(message + ": expected time to be after " + start + " but it was " + actual,
                actual.compare(start) == DatatypeConstants.GREATER
                        || actual.compare(start) == DatatypeConstants.EQUAL);
    }//  w  w  w .j a va 2 s  .  c  o  m
    if (end != null) {
        assertTrue(message + ": expected time to be before " + end + " but it was " + actual,
                actual.compare(end) == DatatypeConstants.LESSER
                        || actual.compare(end) == DatatypeConstants.EQUAL);
    }
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Returns a positive integer if ts1 depicts a time after ts2 (ts1 > ts2), 0 if ts1 and ts2 depict the same time
 * (ts1 == ts2), and a negative integer if if ts1 depicts a time before ts2 (ts1 < ts2).
 * // w ww.  j av  a  2 s . com
 * @param ts1
 *            The first timestamp.
 * @param ts2
 *            The second timestamp.
 * @return The comparison result.
 * @throws Exception
 *             If anything fails (e.g. one timstamp has incorrect format).
 */
public static int compareTimestamps(final String ts1, final String ts2) throws Exception {

    int result = 0;

    XMLGregorianCalendar date1 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts1);
    XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(ts2);

    int diff = date1.compare(date2);
    if (diff == DatatypeConstants.LESSER) {
        result = -1;
    } else if (diff == DatatypeConstants.GREATER) {
        result = 1;
    } else if (diff == DatatypeConstants.EQUAL) {
        result = 0;
    } else if (diff == DatatypeConstants.INDETERMINATE) {
        throw new Exception("Date comparing: INDETERMINATE");
    }

    return result;
}

From source file:org.atricore.idbus.capabilities.sso.main.sp.producers.AssertionConsumerProducer.java

private Calendar getSessionNotOnOrAfter(AssertionType assertion) {

    XMLGregorianCalendar sessionNotOnOrAfter = null;
    List<AuthnStatementType> authnStatements = getAuthnStatements(assertion);

    for (AuthnStatementType authnStatement : authnStatements) {

        if (authnStatement.getSessionNotOnOrAfter() != null) {
            if (sessionNotOnOrAfter == null)
                sessionNotOnOrAfter = authnStatement.getSessionNotOnOrAfter();
            else if (sessionNotOnOrAfter
                    .compare(authnStatement.getSessionNotOnOrAfter()) == DatatypeConstants.LESSER) {
                sessionNotOnOrAfter = authnStatement.getSessionNotOnOrAfter();
            }// ww w. j  a va  2s .c  o m
        }
    }

    if (sessionNotOnOrAfter != null)
        return sessionNotOnOrAfter.toGregorianCalendar();

    return null;
}