| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (

This example Java source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

datetimefield, decorateddatetimefield, durationfield, instance, isoyearoferadatetimefield, object, override, suppresswarnings

The Java example source code

 *  Copyright 2001-2013 Stephen Colebourne
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
package org.joda.time.chrono;

import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
import org.joda.time.field.DecoratedDateTimeField;
import org.joda.time.field.FieldUtils;

 * This field is not publicy exposed by ISOChronology, but rather it is used to
 * build the yearOfCentury and centuryOfEra fields. It merely drops the sign of
 * the year.
 * @author Brian S O'Neill
 * @see GJYearOfEraDateTimeField
 * @since 1.0
class ISOYearOfEraDateTimeField extends DecoratedDateTimeField {

    private static final long serialVersionUID = 7037524068969447317L;

     * Singleton instance
    static final DateTimeField INSTANCE = new ISOYearOfEraDateTimeField();

     * Restricted constructor.
    private ISOYearOfEraDateTimeField() {
        super(GregorianChronology.getInstanceUTC().year(), DateTimeFieldType.yearOfEra());

    public DurationField getRangeDurationField() {
        return GregorianChronology.getInstanceUTC().eras();

    public int get(long instant) {
        int year = getWrappedField().get(instant);
        return year < 0 ? -year : year;

    public long add(long instant, int years) {
        return getWrappedField().add(instant, years);

    public long add(long instant, long years) {
        return getWrappedField().add(instant, years);

    public long addWrapField(long instant, int years) {
        return getWrappedField().addWrapField(instant, years);

    public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) {
        return getWrappedField().addWrapField(instant, fieldIndex, values, years);

    public int getDifference(long minuendInstant, long subtrahendInstant) {
        return getWrappedField().getDifference(minuendInstant, subtrahendInstant);

    public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
        return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant);

    public long set(long instant, int year) {
        FieldUtils.verifyValueBounds(this, year, 0, getMaximumValue());
        if (getWrappedField().get(instant) < 0) {
            year = -year;
        return super.set(instant, year);

    public int getMinimumValue() {
        return 0;

    public int getMaximumValue() {
        return getWrappedField().getMaximumValue();

    public long roundFloor(long instant) {
        return getWrappedField().roundFloor(instant);

    public long roundCeiling(long instant) {
        return getWrappedField().roundCeiling(instant);

    public long remainder(long instant) {
        return getWrappedField().remainder(instant);

     * Serialization singleton
    private Object readResolve() {
        return INSTANCE;

Other Java examples (source code examples)

Here is a short list of links related to this Java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.