本文整理汇总了Java中javax.xml.datatype.DatatypeConstants.EQUAL属性的典型用法代码示例。如果您正苦于以下问题:Java DatatypeConstants.EQUAL属性的具体用法?Java DatatypeConstants.EQUAL怎么用?Java DatatypeConstants.EQUAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.datatype.DatatypeConstants
的用法示例。
在下文中一共展示了DatatypeConstants.EQUAL属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareField
/**
* <p>Implement Step B from
* http://www.w3.org/TR/xmlschema-2/#dateTime-order.</p>
*/
private static int compareField(int Pfield, int Qfield) {
if (Pfield == Qfield) {
//fields are either equal in value or both undefined.
// Step B. 1.1 AND optimized result of performing 1.1-1.4.
return DatatypeConstants.EQUAL;
} else {
if (Pfield == DatatypeConstants.FIELD_UNDEFINED || Qfield == DatatypeConstants.FIELD_UNDEFINED) {
// Step B. 1.2
return DatatypeConstants.INDETERMINATE;
} else {
// Step B. 1.3-4.
return (Pfield < Qfield ? DatatypeConstants.LESSER : DatatypeConstants.GREATER);
}
}
}
示例2: equals
/**
* <p>Indicates whether parameter <code>obj</code> is "equal to" this one.</p>
*
* @param obj to compare.
*
* @return <code>true</code> when <code>compare(this,(XMLGregorianCalendar)obj) == EQUAL.</code>.
*/
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
return false;
}
if (obj == this) {
return true;
}
return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
}
示例3: equals
/**
* <p>Indicates whether parameter <code>obj</code> is "equal to" this one.</p>
*
* @param obj to compare.
*
* @return <code>true</code> when <code>compare(this,(XMLGregorianCalendar)obj) == EQUAL.</code>.
*/
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof XMLGregorianCalendar)) {
return false;
}
return compare((XMLGregorianCalendar) obj) == DatatypeConstants.EQUAL;
}
示例4: cmp2str
public static String cmp2str(int cmp) {
return cmp == DatatypeConstants.LESSER ? "LESSER"
: cmp == DatatypeConstants.GREATER ? "GREATER"
: cmp == DatatypeConstants.EQUAL ? "EQUAL"
: cmp == DatatypeConstants.INDETERMINATE ? "INDETERMINATE"
: "UNDEFINED";
}
示例5: internalCompare
/**
*
* <p>Implements Step B from http://www.w3.org/TR/xmlschema-2/#dateTime-order </p>
* @param P calendar instance with normalized timezone offset or
* having same timezone as Q
* @param Q calendar instance with normalized timezone offset or
* having same timezone as P
*
* @return result of comparing P and Q, value of
* {@link DatatypeConstants#EQUAL},
* {@link DatatypeConstants#LESSER},
* {@link DatatypeConstants#GREATER} or
* {@link DatatypeConstants#INDETERMINATE}.
*/
private static int internalCompare(XMLGregorianCalendar P,
XMLGregorianCalendar Q) {
int result;
// compare Year.
if (P.getEon() == Q.getEon()) {
// Eon field is only equal when null.
// optimized case for comparing year not requiring eon field.
result = compareField(P.getYear(), Q.getYear());
if (result != DatatypeConstants.EQUAL) {
return result;
}
} else {
result = compareField(P.getEonAndYear(), Q.getEonAndYear());
if (result != DatatypeConstants.EQUAL) {
return result;
}
}
result = compareField(P.getMonth(), Q.getMonth());
if (result != DatatypeConstants.EQUAL) {
return result;
}
result = compareField(P.getDay(), Q.getDay());
if (result != DatatypeConstants.EQUAL) {
return result;
}
result = compareField(P.getHour(), Q.getHour());
if (result != DatatypeConstants.EQUAL) {
return result;
}
result = compareField(P.getMinute(), Q.getMinute());
if (result != DatatypeConstants.EQUAL) {
return result;
}
result = compareField(P.getSecond(), Q.getSecond());
if (result != DatatypeConstants.EQUAL) {
return result;
}
result = compareField(P.getFractionalSecond(), Q.getFractionalSecond());
return result;
}
示例6: isValid
/**
* Validate instance by <code>getXMLSchemaType()</code> constraints.
* @return true if data values are valid.
*/
public boolean isValid() {
// since setters do not allow for invalid values,
// (except for exceptional case of year field of zero),
// no need to check for anything except for constraints
// between fields.
//check if days in month is valid. Can be dependent on leap year.
if (getMonth() == DatatypeConstants.FEBRUARY) {
// years could not be set
int maxDays = 29;
if (eon == null) {
if(year!=DatatypeConstants.FIELD_UNDEFINED)
maxDays = maximumDayInMonthFor(year,getMonth());
} else {
BigInteger years = getEonAndYear();
if (years != null) {
maxDays = maximumDayInMonthFor(getEonAndYear(), DatatypeConstants.FEBRUARY);
}
}
if (getDay() > maxDays) {
return false;
}
}
// http://www.w3.org/2001/05/xmlschema-errata#e2-45
if (getHour() == 24) {
if(getMinute() != 0) {
return false;
} else if (getSecond() != 0) {
return false;
}
}
// XML Schema 1.0 specification defines year value of zero as
// invalid. Allow this class to set year field to zero
// since XML Schema 1.0 errata states that lexical zero will
// be allowed in next version and treated as 1 B.C.E.
if (eon == null) {
// optimize check.
if (year == 0) {
return false;
}
} else {
BigInteger yearField = getEonAndYear();
if (yearField != null) {
int result = compareField(yearField, BigInteger.ZERO);
if (result == DatatypeConstants.EQUAL) {
return false;
}
}
}
return true;
}
示例7: testCompareWithInderterminateRelation
/**
* 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");
}
}
}
示例8: testVerifyOtherRelations
/**
* 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));
}
}
}
示例9: testCompareWithInderterminateRelation
/**
* 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");
}
}
}
示例10: cmp2str
public static String cmp2str(int cmp) {
return cmp == DatatypeConstants.LESSER ? "LESSER" : cmp == DatatypeConstants.GREATER ? "GREATER" : cmp == DatatypeConstants.EQUAL ? "EQUAL"
: cmp == DatatypeConstants.INDETERMINATE ? "INDETERMINATE" : "UNDEFINED";
}