本文整理汇总了Java中javax.xml.datatype.DatatypeConstants类的典型用法代码示例。如果您正苦于以下问题:Java DatatypeConstants类的具体用法?Java DatatypeConstants怎么用?Java DatatypeConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatatypeConstants类属于javax.xml.datatype包,在下文中一共展示了DatatypeConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalize
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Normalize this instance to UTC.</p>
*
* <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
* <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
*/
public XMLGregorianCalendar normalize() {
XMLGregorianCalendar normalized = normalizeToTimezone(timezone);
// if timezone was undefined, leave it undefined
if (getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
normalized.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
}
// if milliseconds was undefined, leave it undefined
if (getMillisecond() == DatatypeConstants.FIELD_UNDEFINED) {
normalized.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
}
return normalized;
}
示例2: createDateTime
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Create a Java instance of XML Schema builtin datatype dateTime.</p>
*
* @param year represents both high-order eons and low-order year.
* @param month of <code>dateTime</code>
* @param day of <code>dateTime</code>
* @param hour of <code>dateTime</code>
* @param minute of <code>dateTime</code>
* @param second of <code>dateTime</code>
*
* @return <code>XMLGregorianCalendar</code> created from parameter values.
*
* @throws IllegalArgumentException if any parameter is outside value constraints for the field as specified in
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
*
* @see DatatypeConstants#FIELD_UNDEFINED
*/
public static XMLGregorianCalendar createDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second) {
return new XMLGregorianCalendarImpl(
year,
month,
day,
hour,
minute,
second,
DatatypeConstants.FIELD_UNDEFINED, //millisecond
DatatypeConstants.FIELD_UNDEFINED //timezone
);
}
示例3: createTime
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* Create a Java instance of XML Schema builtin datatype <code>time</code>.
* @param hours number of hours
* @param minutes number of minutes
* @param seconds number of seconds
* @param timezone offset in minutes. {@link DatatypeConstants#FIELD_UNDEFINED} indicates optional field is not set.
*
* @return <code>XMLGregorianCalendar</code> created from parameter values.
*
* @see DatatypeConstants#FIELD_UNDEFINED
*
* @throws IllegalArgumentException if any parameter is outside value
* constraints for the field as specified in
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
*/
public static XMLGregorianCalendar createTime(
int hours,
int minutes,
int seconds,
int timezone) {
return new XMLGregorianCalendarImpl(
DatatypeConstants.FIELD_UNDEFINED, // Year
DatatypeConstants.FIELD_UNDEFINED, // Month
DatatypeConstants.FIELD_UNDEFINED, // Day
hours,
minutes,
seconds,
DatatypeConstants.FIELD_UNDEFINED, //Millisecond
timezone);
}
示例4: getEonAndYear
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Return XML Schema 1.0 dateTime datatype field for
* <code>year</code>.</p>
*
* <p>Value constraints for this value are summarized in
* <a href="#datetimefield-year">year field of date/time field mapping table</a>.</p>
*
* @return sum of <code>eon</code> and <code>BigInteger.valueOf(year)</code>
* when both fields are defined. When only <code>year</code> is defined,
* return it. When both <code>eon</code> and <code>year</code> are not
* defined, return <code>null</code>.
*
* @see #getEon()
* @see #getYear()
*/
public BigInteger getEonAndYear() {
// both are defined
if (year != DatatypeConstants.FIELD_UNDEFINED
&& eon != null) {
return eon.add(BigInteger.valueOf((long) year));
}
// only year is defined
if (year != DatatypeConstants.FIELD_UNDEFINED
&& eon == null) {
return BigInteger.valueOf((long) year);
}
// neither are defined
// or only eon is defined which is not valid without a year
return null;
}
示例5: compareField
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <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);
}
}
}
示例6: hashCode
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Returns a hash code consistent with the definition of the equals method.</p>
*
* @return hash code of this object.
*/
public int hashCode() {
// Following two dates compare to EQUALS since in different timezones.
// 2000-01-15T12:00:00-05:00 == 2000-01-15T13:00:00-04:00
//
// Must ensure both instances generate same hashcode by normalizing
// this to UTC timezone.
int timezone = getTimezone();
if (timezone == DatatypeConstants.FIELD_UNDEFINED) {
timezone = 0;
}
XMLGregorianCalendar gc = this;
if (timezone != 0) {
gc = this.normalizeToTimezone(getTimezone());
}
return gc.getYear() + gc.getMonth() + gc.getDay() +
gc.getHour() + gc.getMinute() + gc.getSecond();
}
示例7: DurationImpl
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Constructs a new Duration object by specifying each field
* individually.</p>
*
* <p>This method is functionally equivalent to
* invoking another constructor by wrapping
* all non-zero parameters into {@link BigInteger} and {@link BigDecimal}.
* Zero value of int parameter is equivalent of null value of
* the corresponding field.</p>
*
* @see #DurationImpl(boolean, BigInteger, BigInteger, BigInteger, BigInteger,
* BigInteger, BigDecimal)
*/
protected DurationImpl(
final boolean isPositive,
final int years,
final int months,
final int days,
final int hours,
final int minutes,
final int seconds) {
this(
isPositive,
wrap(years),
wrap(months),
wrap(days),
wrap(hours),
wrap(minutes),
seconds != DatatypeConstants.FIELD_UNDEFINED ? new BigDecimal(String.valueOf(seconds)) : null);
}
示例8: getFieldAsBigDecimal
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Gets the value of the field as a {@link BigDecimal}.</p>
*
* <p>If the field is unset, return 0.</p>
*
* @param f Field to get value for.
*
* @return non-null valid {@link BigDecimal}.
*/
private BigDecimal getFieldAsBigDecimal(DatatypeConstants.Field f) {
if (f == DatatypeConstants.SECONDS) {
if (seconds != null) {
return seconds;
} else {
return ZERO;
}
} else {
BigInteger bi = (BigInteger) getField(f);
if (bi == null) {
return ZERO;
} else {
return new BigDecimal(bi);
}
}
}
示例9: setYear
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Set year of XSD <code>dateTime</code> year field.</p>
*
* <p>Unset this field by invoking the setter with a parameter value of
* {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
*
* <p>Note: if the absolute value of the <code>year</code> parameter
* is less than 10^9, the eon component of the XSD year field is set to
* <code>null</code> by this method.</p>
*
* @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
* If year is {@link DatatypeConstants#FIELD_UNDEFINED}, then eon is set to <code>null</code>.
*/
public final void setYear(int year) {
if (year == DatatypeConstants.FIELD_UNDEFINED) {
this.year = DatatypeConstants.FIELD_UNDEFINED;
this.eon = null;
}
else if (Math.abs(year) < BILLION_I) {
this.year = year;
this.eon = null;
} else {
BigInteger theYear = BigInteger.valueOf((long) year);
BigInteger remainder = theYear.remainder(BILLION_B);
this.year = remainder.intValue();
setEon(theYear.subtract(remainder));
}
}
示例10: equals
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <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;
}
示例11: getFieldAsBigDecimal
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Gets the value of the field as a {@link BigDecimal}.</p>
*
* <p>If the field is unset, return 0.</p>
*
* @param f Field to get value for.
*
* @return non-null valid {@link BigDecimal}.
*/
private BigDecimal getFieldAsBigDecimal(DatatypeConstants.Field f) {
if (f == DatatypeConstants.SECONDS) {
if (seconds != null) {
return seconds;
}
else {
return ZERO;
}
}
else {
BigInteger bi = (BigInteger) getField(f);
if (bi == null) {
return ZERO;
}
else {
return new BigDecimal(bi);
}
}
}
示例12: getXmlDate
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
public static XMLGregorianCalendar getXmlDate(Date dateAndTime) {
ParamUtil.requireNonNull("dateAndTime", dateAndTime);
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(UTC);
cal.setTime(dateAndTime);
try {
XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
return ret;
} catch (DatatypeConfigurationException ex) {
return null;
}
}
示例13: createDate
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Create a Java representation of XML Schema builtin datatype <code>date</code> or <code>g*</code>.</p>
*
* <p>For example, an instance of <code>gYear</code> can be created invoking this factory
* with <code>month</code> and <code>day</code> parameters set to
* {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
*
* @param year of <code>XMLGregorianCalendar</code> to be created.
* @param month of <code>XMLGregorianCalendar</code> to be created.
* @param day of <code>XMLGregorianCalendar</code> to be created.
* @param timezone offset in minutes. {@link DatatypeConstants#FIELD_UNDEFINED} indicates optional field is not set.
*
* @return <code>XMLGregorianCalendar</code> created from parameter values.
*
* @see DatatypeConstants#FIELD_UNDEFINED
*
* @throws IllegalArgumentException if any parameter is outside value
* constraints for the field as specified in
* <a href="#datetimefieldmapping">date/time field mapping table</a>.
*/
public static XMLGregorianCalendar createDate(
int year,
int month,
int day,
int timezone) {
return new XMLGregorianCalendarImpl(
year,
month,
day,
DatatypeConstants.FIELD_UNDEFINED, // hour
DatatypeConstants.FIELD_UNDEFINED, // minute
DatatypeConstants.FIELD_UNDEFINED, // second
DatatypeConstants.FIELD_UNDEFINED, // millisecond
timezone);
}
示例14: getSeconds
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* @return result of adding second and fractional second field
*/
private BigDecimal getSeconds() {
if (second == DatatypeConstants.FIELD_UNDEFINED) {
return DECIMAL_ZERO;
}
BigDecimal result = BigDecimal.valueOf((long) second);
if (fractionalSecond != null) {
return result.add(fractionalSecond);
} else {
return result;
}
}
示例15: setYear
import javax.xml.datatype.DatatypeConstants; //导入依赖的package包/类
/**
* <p>Set year of XSD <code>dateTime</code> year field.</p>
*
* <p>Unset this field by invoking the setter with a parameter value of
* {@link DatatypeConstants#FIELD_UNDEFINED}.</p>
*
* <p>Note: if the absolute value of the <code>year</code> parameter
* is less than 10^9, the eon component of the XSD year field is set to
* <code>null</code> by this method.</p>
*
* @param year value constraints are summarized in <a href="#datetimefield-year">year field of date/time field mapping table</a>.
* If year is {@link DatatypeConstants#FIELD_UNDEFINED}, then eon is set to <code>null</code>.
*/
public void setYear(int year) {
if (year == DatatypeConstants.FIELD_UNDEFINED) {
this.year = DatatypeConstants.FIELD_UNDEFINED;
this.eon = null;
} else if (Math.abs(year) < BILLION.intValue()) {
this.year = year;
this.eon = null;
} else {
BigInteger theYear = BigInteger.valueOf((long) year);
BigInteger remainder = theYear.remainder(BILLION);
this.year = remainder.intValue();
setEon(theYear.subtract(remainder));
}
}