Java Code Examples for org.joda.time.ReadablePartial#get()

The following examples show how to use org.joda.time.ReadablePartial#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DayOfMonthOfFixedYearDateTimeField.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int getMaximumValue(ReadablePartial partial) {
  if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
    int month = partial.get(DateTimeFieldType.monthOfYear());
    return this.daysInMonth[month - 1]; // Months are 1-based
  }
  return this.getMaximumValue();
}
 
Example 2
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 3
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 4
Source File: AbstractPartialFieldProperty.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compare this field to the same field on another partial instant.
 * <p>
 * The comparison is based on the value of the same field type, irrespective
 * of any difference in chronology. Thus, if this property represents the
 * hourOfDay field, then the hourOfDay field of the other partial will be queried
 * whether in the same chronology or not.
 * 
 * @param partial  the partial to compare to
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws IllegalArgumentException if the instant is null
 * @throws IllegalArgumentException if the field of this property cannot be queried
 *  on the specified instant
 */
public int compareTo(ReadablePartial partial) {
    if (partial == null) {
        throw new IllegalArgumentException("The instant must not be null");
    }
    int thisValue = get();
    int otherValue = partial.get(getFieldType());
    if (thisValue < otherValue) {
        return -1;
    } else if (thisValue > otherValue) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 5
Source File: AbstractReadableInstantFieldProperty.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compare this field to the same field on another partial instant.
 * <p>
 * The comparison is based on the value of the same field type, irrespective
 * of any difference in chronology. Thus, if this property represents the
 * hourOfDay field, then the hourOfDay field of the other partial will be queried
 * whether in the same chronology or not.
 * 
 * @param partial  the partial to compare to
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws IllegalArgumentException if the partial is null
 * @throws IllegalArgumentException if the partial doesn't support this field
 */
public int compareTo(ReadablePartial partial) {
    if (partial == null) {
        throw new IllegalArgumentException("The partial must not be null");
    }
    int thisValue = get();
    int otherValue = partial.get(getFieldType());
    if (thisValue < otherValue) {
        return -1;
    } else if (thisValue > otherValue) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 6
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 7
Source File: AbstractPartialFieldProperty.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compare this field to the same field on another partial instant.
 * <p>
 * The comparison is based on the value of the same field type, irrespective
 * of any difference in chronology. Thus, if this property represents the
 * hourOfDay field, then the hourOfDay field of the other partial will be queried
 * whether in the same chronology or not.
 * 
 * @param partial  the partial to compare to
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws IllegalArgumentException if the instant is null
 * @throws IllegalArgumentException if the field of this property cannot be queried
 *  on the specified instant
 */
public int compareTo(ReadablePartial partial) {
    if (partial == null) {
        throw new IllegalArgumentException("The instant must not be null");
    }
    int thisValue = get();
    int otherValue = partial.get(getFieldType());
    if (thisValue < otherValue) {
        return -1;
    } else if (thisValue > otherValue) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 8
Source File: AbstractReadableInstantFieldProperty.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compare this field to the same field on another partial instant.
 * <p>
 * The comparison is based on the value of the same field type, irrespective
 * of any difference in chronology. Thus, if this property represents the
 * hourOfDay field, then the hourOfDay field of the other partial will be queried
 * whether in the same chronology or not.
 * 
 * @param partial  the partial to compare to
 * @return negative value if this is less, 0 if equal, or positive value if greater
 * @throws IllegalArgumentException if the partial is null
 * @throws IllegalArgumentException if the partial doesn't support this field
 */
public int compareTo(ReadablePartial partial) {
    if (partial == null) {
        throw new IllegalArgumentException("The partial must not be null");
    }
    int thisValue = get();
    int otherValue = partial.get(getFieldType());
    if (thisValue < otherValue) {
        return -1;
    } else if (thisValue > otherValue) {
        return 1;
    } else {
        return 0;
    }
}
 
Example 9
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 10
Source File: Joda.java    From crate with Apache License 2.0 5 votes vote down vote up
private long getDateTimeMillis(ReadablePartial partial) {
    int year = partial.get(DateTimeFieldType.year());
    int monthOfYear = partial.get(DateTimeFieldType.monthOfYear());
    int dayOfMonth = partial.get(DateTimeFieldType.dayOfMonth());
    int hourOfDay = partial.get(DateTimeFieldType.hourOfDay());
    int minuteOfHour = partial.get(DateTimeFieldType.minuteOfHour());
    int secondOfMinute = partial.get(DateTimeFieldType.secondOfMinute());
    int millisOfSecond = partial.get(DateTimeFieldType.millisOfSecond());
    return partial.getChronology().getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
 
Example 11
Source File: ReadablePartialConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: ReadablePartialConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
}