本文整理汇总了Java中org.joda.time.ReadablePartial.size方法的典型用法代码示例。如果您正苦于以下问题:Java ReadablePartial.size方法的具体用法?Java ReadablePartial.size怎么用?Java ReadablePartial.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.ReadablePartial
的用法示例。
在下文中一共展示了ReadablePartial.size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: between
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Calculates the number of whole units between the two specified partial datetimes.
* <p>
* The two partials must contain the same fields, for example you can specify
* two <code>LocalDate</code> objects.
*
* @param start the start partial date, validated to not be null
* @param end the end partial date, validated to not be null
* @param zeroInstance the zero instance constant, must not be null
* @return the period
* @throws IllegalArgumentException if the partials are null or invalid
*/
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
if (start == null || end == null) {
throw new IllegalArgumentException("ReadablePartial objects must not be null");
}
if (start.size() != end.size()) {
throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
}
for (int i = 0, isize = start.size(); i < isize; i++) {
if (start.getFieldType(i) != end.getFieldType(i)) {
throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
}
}
if (DateTimeUtils.isContiguous(start) == false) {
throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
}
Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
int[] values = chrono.get(zeroInstance, chrono.set(start, 0L), chrono.set(end, 0L));
return values[0];
}
示例2: equals
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Compares this ReadablePartial with another returning true if the chronology,
* field types and values are equal.
*
* @param partial an object to check against
* @return true if fields and values are equal
*/
public boolean equals(Object partial) {
if (this == partial) {
return true;
}
if (partial instanceof ReadablePartial == false) {
return false;
}
ReadablePartial other = (ReadablePartial) partial;
if (size() != other.size()) {
return false;
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) {
return false;
}
}
return FieldUtils.equals(getChronology(), other.getChronology());
}
示例3: compareTo
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Compares this partial with another returning an integer
* indicating the order.
* <p>
* The fields are compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
* <p>
* The specified object must be a partial instance whose field types
* match those of this partial.
* <p>
* NOTE: Prior to v2.0, the {@code Comparable} interface was only implemented
* in this class and not in the {@code ReadablePartial} interface.
*
* @param other an object to check against
* @return negative if this is less, zero if equal, positive if greater
* @throws ClassCastException if the partial is the wrong class
* or if it has field types that don't match
* @throws NullPointerException if the partial is null
* @since 1.1
*/
public int compareTo(ReadablePartial other) {
if (this == other) {
return 0;
}
if (size() != other.size()) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getFieldType(i) != other.getFieldType(i)) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
}
// fields are ordered largest first
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(i) > other.getValue(i)) {
return 1;
}
if (getValue(i) < other.getValue(i)) {
return -1;
}
}
return 0;
}
示例4: add
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(GJChronology.this).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return GJChronology.this.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
示例5: add
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
示例6: getMaximumValue
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
@Override
public int getMaximumValue(ReadablePartial partial, int[] values) {
int size = partial.size();
for (int i = 0; i < size; i++) {
if (partial.getFieldType(i) == DateTimeFieldType.monthOfYear()) {
int month = values[i];
return this.daysInMonth[month - 1];
}
}
return this.getMaximumValue();
}
示例7: getMaximumValue
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
public int getMaximumValue(ReadablePartial partial, int[] values) {
Chronology chrono = GJChronology.getInstanceUTC();
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
DateTimeField field = partial.getFieldType(i).getField(chrono);
if (values[i] <= field.getMaximumValue(instant)) {
instant = field.set(instant, values[i]);
}
}
return getMaximumValue(instant);
}
示例8: get
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Gets the values of a partial from an instant.
*
* @param partial the partial instant to use
* @param instant the instant to query
* @return the values of the partial extracted from the instant
*/
public int[] get(ReadablePartial partial, long instant) {
int size = partial.size();
int[] values = new int[size];
for (int i = 0; i < size; i++) {
values[i] = partial.getFieldType(i).getField(this).get(instant);
}
return values;
}
示例9: set
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Sets a value using the specified partial instant.
* <p>
* The value of this field (specified by the index) will be set.
* If the value is invalid, an exception if thrown.
* <p>
* If setting this field would make other fields invalid, then those fields
* may be changed. For example if the current date is the 31st January, and
* the month is set to February, the day would be invalid. Instead, the day
* would be changed to the closest value - the 28th/29th February as appropriate.
*
* @param partial the partial instant
* @param fieldIndex the index of this field in the instant
* @param values the values to update
* @param newValue the value to set, in the units of the field
* @return the updated values
* @throws IllegalArgumentException if the value is invalid
*/
public int[] set(ReadablePartial partial, int fieldIndex, int[] values, int newValue) {
FieldUtils.verifyValueBounds(this, newValue, getMinimumValue(partial, values), getMaximumValue(partial, values));
values[fieldIndex] = newValue;
// may need to adjust smaller fields
for (int i = fieldIndex + 1; i < partial.size(); i++) {
DateTimeField field = partial.getField(i);
if (values[i] > field.getMaximumValue(partial, values)) {
values[i] = field.getMaximumValue(partial, values);
}
if (values[i] < field.getMinimumValue(partial, values)) {
values[i] = field.getMinimumValue(partial, values);
}
}
return values;
}
示例10: getPartialValues
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Extracts the values of the partial from an object of this converter's type.
* The chrono parameter is a hint to the converter, should it require a
* chronology to aid in conversion.
*
* @param fieldSource a partial that provides access to the fields.
* This partial may be incomplete and only getFieldType(int) should be used
* @param object the object to convert
* @param chrono the chronology to use, which is the non-null result of getChronology()
* @return the array of field values that match the fieldSource, must be non-null valid
* @throws ClassCastException if the object is invalid
*/
public int[] getPartialValues(ReadablePartial fieldSource, Object object, Chronology chrono) {
ReadablePartial input = (ReadablePartial) object;
int size = fieldSource.size();
int[] values = new int[size];
for (int i = 0; i < size; i++) {
values[i] = input.get(fieldSource.getFieldType(i));
}
chrono.validate(fieldSource, values);
return values;
}
示例11: set
import org.joda.time.ReadablePartial; //导入方法依赖的package包/类
/**
* Sets the partial into the instant.
*
* @param partial the partial instant to use
* @param instant the instant to update
* @return the updated instant
*/
public long set(ReadablePartial partial, long instant) {
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(this).set(instant, partial.getValue(i));
}
return instant;
}