當前位置: 首頁>>代碼示例>>Java>>正文


Java DatatypeFactory.newDuration方法代碼示例

本文整理匯總了Java中javax.xml.datatype.DatatypeFactory.newDuration方法的典型用法代碼示例。如果您正苦於以下問題:Java DatatypeFactory.newDuration方法的具體用法?Java DatatypeFactory.newDuration怎麽用?Java DatatypeFactory.newDuration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.datatype.DatatypeFactory的用法示例。


在下文中一共展示了DatatypeFactory.newDuration方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyOutages

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
public AppliedOutages applyOutages(Calendar calendar, boolean assumeConnected) {
	appliedOutages = ModelParser.applyOutages(calendar, rdfModel, assumeConnected);
	GregorianCalendar gregorianCalendar = new GregorianCalendar();
	gregorianCalendar.setTime(appliedOutages.getEffectiveEnd().getTime());
	try {
		DatatypeFactory factory = DatatypeFactory.newInstance();
		endDate = factory.newXMLGregorianCalendar(gregorianCalendar);
		Duration oneSecond = factory.newDuration("PT1S");
		endDate.add(oneSecond);
	} catch (DatatypeConfigurationException e) {
		// do nothing
	}
	return appliedOutages;
}
 
開發者ID:OmniPrise,項目名稱:cim-processor,代碼行數:15,代碼來源:ModelParser.java

示例2: onCreate

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
@Override
public void onCreate(TaskInfo taskInfo) {
    String taskDefinitionKey = taskInfo.getCode();

    String processDefinitionId = taskInfo.getProcessDefinitionId();
    List<DeadlineDTO> deadlines = taskDefinitionConnector.findDeadlines(
            taskDefinitionKey, processDefinitionId);

    for (DeadlineDTO deadline : deadlines) {
        try {
            String durationText = deadline.getDuration();

            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);

            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
            Duration duration = datatypeFactory.newDuration(durationText);
            duration.addTo(calendar);

            Date deadlineTime = calendar.getTime();
            TaskDeadline taskDeadline = new TaskDeadline();
            taskDeadline.setTaskInfo(taskInfo);
            taskDeadline.setType(deadline.getType());
            taskDeadline.setDeadlineTime(deadlineTime);
            taskDeadline
                    .setNotificationType(deadline.getNotificationType());
            taskDeadline.setNotificationTemplateCode(deadline
                    .getNotificationTemplateCode());
            taskDeadline.setNotificationReceiver(deadline
                    .getNotificationReceiver());
            taskDeadlineManager.save(taskDeadline);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:38,代碼來源:DeadlineHumanTaskListener.java

示例3: createTestFile

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
 * Create test files
 *
 * @param javaVersion JDK version
 */
public void createTestFile(String javaVersion) {
    try {
        DatatypeFactory dtf = DatatypeFactory.newInstance();
        XMLGregorianCalendar c = dtf.newXMLGregorianCalendar(EXPECTED_CAL);
        Duration d = dtf.newDuration(EXPECTED_DURATION);
        toFile((Serializable) c, filePath + javaVersion + FILENAME_CAL);
        toFile((Serializable) d, filePath + javaVersion + FILENAME_DURATION);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:SerializationTest.java

示例4: test

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
@Test
public void test() throws DatatypeConfigurationException {
    DatatypeFactory df = DatatypeFactory.newInstance();
    Duration durationx = df.newDuration(Long.MIN_VALUE);
    Assert.assertEquals(durationx.toString(), "-P292277024Y7M16DT7H12M55.808S");
    durationx = df.newDuration(Long.MAX_VALUE);
    Assert.assertEquals(durationx.toString(), "P292277024Y7M16DT7H12M55.807S");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:JDK8068839Test.java

示例5: newDurationTester

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
private void newDurationTester(boolean isPositive, boolean normalizedIsPositive, BigInteger years, BigInteger normalizedYears, BigInteger months,
        BigInteger normalizedMonths, BigInteger days, BigInteger normalizedDays, BigInteger hours, BigInteger normalizedHours, BigInteger minutes,
        BigInteger normalizedMinutes, BigDecimal seconds, BigDecimal normalizedSeconds, long durationInMilliSeconds, long normalizedDurationInMilliSeconds,
        String lexicalRepresentation, String normalizedLexicalRepresentation) {

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    // create 4 Durations using the 4 different constructors

    Duration durationBigInteger = datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
    durationAssertEquals(durationBigInteger, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationInt = datatypeFactory.newDuration(isPositive, years.intValue(), months.intValue(), days.intValue(), hours.intValue(),
            minutes.intValue(), seconds.intValue());
    durationAssertEquals(durationInt, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationMilliseconds = datatypeFactory.newDuration(durationInMilliSeconds);
    durationAssertEquals(durationMilliseconds, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    Duration durationLexical = datatypeFactory.newDuration(lexicalRepresentation);
    durationAssertEquals(durationLexical, DatatypeConstants.DURATION, normalizedIsPositive, normalizedYears.intValue(), normalizedMonths.intValue(),
            normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:DurationTest.java

示例6: testCompareWithInderterminateRelation

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
 * See JDK-5077522, Duration.compare returns equal for INDETERMINATE
 * comparisons
 */
public void testCompareWithInderterminateRelation() {

    final String [][] partialOrder = { // partialOrder
       {"P1Y", "<>", "P365D"},
       {"P1Y", "<>", "P366D"},
       {"P1M", "<>", "P28D"},
       {"P1M", "<>", "P29D"},
       {"P1M", "<>", "P30D"},
       {"P1M", "<>", "P31D"},
       {"P5M", "<>", "P150D"},
       {"P5M", "<>", "P151D"},
       {"P5M", "<>", "P152D"},
       {"P5M", "<>", "P153D"},
       {"PT2419200S", "<>", "P1M"},
       {"PT2678400S", "<>", "P1M"},
       {"PT31536000S", "<>", "P1Y"},
       {"PT31622400S", "<>", "P1Y"},
       {"PT525600M", "<>", "P1Y"},
       {"PT527040M", "<>", "P1Y"},
       {"PT8760H", "<>", "P1Y"},
       {"PT8784H", "<>", "P1Y"},
       {"P365D", "<>", "P1Y"},
    };

    DatatypeFactory df = null;
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        fail(ex.toString());
    }

    for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
        Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
        Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
        int cmp = duration1.compare(duration2);
        int expected = ">".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.GREATER
                 : "<".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.LESSER
                 : "==".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.EQUAL
                 : DatatypeConstants.INDETERMINATE;

        if (expected != cmp) {
            fail("returned " + cmp2str(cmp)
                + " for durations \'" + duration1 + "\' and "
                + duration2 + "\', but expected " + cmp2str(expected));
        } else {
            success("Comparing " + duration1 + " and " + duration2 +
                    ": INDETERMINATE");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:59,代碼來源:DurationComparison.java

示例7: testVerifyOtherRelations

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
 * Verify cases around the INDETERMINATE relations
 */
public void testVerifyOtherRelations() {

    final String [][] partialOrder = { // partialOrder
       {"P1Y", ">", "P364D"},
       {"P1Y", "<", "P367D"},
       {"P1Y2D", ">", "P366D"},
       {"P1M", ">", "P27D"},
       {"P1M", "<", "P32D"},
       {"P1M", "<", "P31DT1H"},
       {"P5M", ">", "P149D"},
       {"P5M", "<", "P154D"},
       {"P5M", "<", "P153DT1H"},
       {"PT2419199S", "<", "P1M"},  //PT2419200S -> P28D
       {"PT2678401S", ">", "P1M"},  //PT2678400S -> P31D
       {"PT31535999S", "<", "P1Y"}, //PT31536000S -> P365D
       {"PT31622401S", ">", "P1Y"}, //PT31622400S -> P366D
       {"PT525599M59S", "<", "P1Y"},  //PT525600M -> P365D
       {"PT527040M1S", ">", "P1Y"},  //PT527040M -> P366D
       {"PT8759H59M59S", "<", "P1Y"},    //PT8760H -> P365D
       {"PT8784H1S", ">", "P1Y"},    //PT8784H -> P366D
    };

    DatatypeFactory df = null;
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        fail(ex.toString());
    }

    for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
        Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
        Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
        int cmp = duration1.compare(duration2);
        int expected = ">".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.GREATER
                 : "<".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.LESSER
                 : "==".equals(partialOrder[valueIndex][1])
                 ? DatatypeConstants.EQUAL
                 : DatatypeConstants.INDETERMINATE;

        if (expected != cmp) {
            fail("returned " + cmp2str(cmp)
                + " for durations \'" + duration1 + "\' and "
                + duration2 + "\', but expected " + cmp2str(expected));
        } else {
            success("Comparing " + duration1 + " and " + duration2 +
                    ": expected: " + cmp2str(expected) +
                    " actual: " + cmp2str(cmp));
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:57,代碼來源:DurationComparison.java

示例8: testCompareWithInderterminateRelation

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
/**
 * Inspired by CR 5077522 Duration.compare makes mistakes for some values.
 */
@Test
public void testCompareWithInderterminateRelation() {

    final String[][] partialOrder = { // partialOrder
    { "P1Y", "<>", "P365D" }, { "P1Y", "<>", "P366D" }, { "P1M", "<>", "P28D" }, { "P1M", "<>", "P29D" }, { "P1M", "<>", "P30D" }, { "P1M", "<>", "P31D" },
            { "P5M", "<>", "P150D" }, { "P5M", "<>", "P151D" }, { "P5M", "<>", "P152D" }, { "P5M", "<>", "P153D" }, { "PT2419200S", "<>", "P1M" },
            { "PT2678400S", "<>", "P1M" }, { "PT31536000S", "<>", "P1Y" }, { "PT31622400S", "<>", "P1Y" }, { "PT525600M", "<>", "P1Y" },
            { "PT527040M", "<>", "P1Y" }, { "PT8760H", "<>", "P1Y" }, { "PT8784H", "<>", "P1Y" }, { "P365D", "<>", "P1Y" }, };

    DatatypeFactory df = null;
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    boolean compareErrors = false;

    for (int valueIndex = 0; valueIndex < partialOrder.length; ++valueIndex) {
        Duration duration1 = df.newDuration(partialOrder[valueIndex][0]);
        Duration duration2 = df.newDuration(partialOrder[valueIndex][2]);
        int cmp = duration1.compare(duration2);
        int expected = ">".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.GREATER
                : "<".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.LESSER : "==".equals(partialOrder[valueIndex][1]) ? DatatypeConstants.EQUAL
                        : DatatypeConstants.INDETERMINATE;

        // just note any errors, do not fail until all cases have been
        // tested
        if (expected != cmp) {
            compareErrors = true;
            System.err.println("returned " + cmp2str(cmp) + " for durations \'" + duration1 + "\' and " + duration2 + "\', but expected "
                    + cmp2str(expected));
        }
    }

    if (compareErrors) {
        // TODO; fix bug, these tests should pass
        if (false) {
            Assert.fail("Errors in comparing indeterminate relations, see Stderr");
        } else {
            System.err.println("Please fix this bug: " + "Errors in comparing indeterminate relations, see Stderr");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:49,代碼來源:DurationTest.java

示例9: testNewInstance

import javax.xml.datatype.DatatypeFactory; //導入方法依賴的package包/類
@Test(dataProvider = "parameters")
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance(DATATYPE_FACTORY_CLASSNAME, null);
    Duration duration = dtf.newDuration(true, 1, 1, 1, 1, 1, 1);
    assertNotNull(duration);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:FactoryNewInstanceTest.java


注:本文中的javax.xml.datatype.DatatypeFactory.newDuration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。