Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2005 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
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  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;
 
 
Abstract Chronology that enables chronologies to be assembled from a container of fields.

AssembledChronology is thread-safe and immutable.

Author(s):
Brian S O'Neill
Since:
1.0
 
 public abstract class AssembledChronology extends BaseChronology {
 
     private static final long serialVersionUID = -6728465968995518215L;
 
     private final Chronology iBase;
     private final Object iParam;
 
     private transient DurationField iMillis;
     private transient DurationField iSeconds;
     private transient DurationField iMinutes;
     private transient DurationField iHours;
     private transient DurationField iHalfdays;
 
     private transient DurationField iDays;
     private transient DurationField iWeeks;
     private transient DurationField iWeekyears;
     private transient DurationField iMonths;
     private transient DurationField iYears;
     private transient DurationField iCenturies;
     private transient DurationField iEras;
 
     private transient DateTimeField iMillisOfSecond;
     private transient DateTimeField iMillisOfDay;
     private transient DateTimeField iSecondOfMinute;
     private transient DateTimeField iSecondOfDay;
     private transient DateTimeField iMinuteOfHour;
     private transient DateTimeField iMinuteOfDay;
     private transient DateTimeField iHourOfDay;
     private transient DateTimeField iClockhourOfDay;
     private transient DateTimeField iHourOfHalfday;
     private transient DateTimeField iClockhourOfHalfday;
     private transient DateTimeField iHalfdayOfDay;
 
     private transient DateTimeField iDayOfWeek;
     private transient DateTimeField iDayOfMonth;
     private transient DateTimeField iDayOfYear;
     private transient DateTimeField iWeekOfWeekyear;
     private transient DateTimeField iWeekyear;
     private transient DateTimeField iWeekyearOfCentury;
     private transient DateTimeField iMonthOfYear;
     private transient DateTimeField iYear;
     private transient DateTimeField iYearOfEra;
     private transient DateTimeField iYearOfCentury;
     private transient DateTimeField iCenturyOfEra;
     private transient DateTimeField iEra;
 
     // Bit set determines which base fields are used
     // bit 1 set: hourOfDay, minuteOfHour, secondOfMinute, and millisOfSecond fields
     // bit 2 set: millisOfDayField
     // bit 3 set: year, monthOfYear, and dayOfMonth fields
     private transient int iBaseFlags;

    
Constructor calls the assemble method, enabling subclasses to define its supported fields. If a base chronology is supplied, the field set initially contains references to each base chronology field.

Other methods in this class will delegate to the base chronology, if it can be determined that the base chronology will produce the same results as AbstractChronology.

Parameters:
base optional base chronology to copy initial fields from
param optional param object avalable for assemble method
 
     protected AssembledChronology(Chronology baseObject param) {
         = base;
         = param;
        setFields();
    }
    public DateTimeZone getZone() {
        Chronology base;
        if ((base = ) != null) {
            return base.getZone();
        }
        return null;
    }
    public long getDateTimeMillis(int yearint monthOfYearint dayOfMonth,
                                  int millisOfDay)
        throws IllegalArgumentException
    {
        Chronology base;
        if ((base = ) != null && ( & 6) == 6) {
            // Only call specialized implementation if applicable fields are the same.
            return base.getDateTimeMillis(yearmonthOfYeardayOfMonthmillisOfDay);
        }
        return super.getDateTimeMillis(yearmonthOfYeardayOfMonthmillisOfDay);
    }
    public long getDateTimeMillis(int yearint monthOfYearint dayOfMonth,
                                  int hourOfDayint minuteOfHour,
                                  int secondOfMinuteint millisOfSecond)
        throws IllegalArgumentException
    {
        Chronology base;
        if ((base = ) != null && ( & 5) == 5) {
            // Only call specialized implementation if applicable fields are the same.
            return base.getDateTimeMillis(yearmonthOfYeardayOfMonth,
                                          hourOfDayminuteOfHoursecondOfMinutemillisOfSecond);
        }
        return super.getDateTimeMillis(yearmonthOfYeardayOfMonth,
                                       hourOfDayminuteOfHoursecondOfMinutemillisOfSecond);
    }
    public long getDateTimeMillis(long instant,
                                  int hourOfDayint minuteOfHour,
                                  int secondOfMinuteint millisOfSecond)
        throws IllegalArgumentException
    {
        Chronology base;
        if ((base = ) != null && ( & 1) == 1) {
            // Only call specialized implementation if applicable fields are the same.
            return base.getDateTimeMillis
                (instanthourOfDayminuteOfHoursecondOfMinutemillisOfSecond);
        }
        return super.getDateTimeMillis
            (instanthourOfDayminuteOfHoursecondOfMinutemillisOfSecond);
    }
    public final DurationField millis() {
        return ;
    }
    public final DateTimeField millisOfSecond() {
        return ;
    }
    public final DateTimeField millisOfDay() {
        return ;
    }
    public final DurationField seconds() {
        return ;
    }
    public final DateTimeField secondOfMinute() {
        return ;
    }
    public final DateTimeField secondOfDay() {
        return ;
    }
    public final DurationField minutes() {
        return ;
    }
    public final DateTimeField minuteOfHour() {
        return ;
    }
    public final DateTimeField minuteOfDay() {
        return ;
    }
    public final DurationField hours() {
        return ;
    }
    public final DateTimeField hourOfDay() {
        return ;
    }
    public final DateTimeField clockhourOfDay() {
        return ;
    }
    public final DurationField halfdays() {
        return ;
    }
    public final DateTimeField hourOfHalfday() {
        return ;
    }
    public final DateTimeField clockhourOfHalfday() {
        return ;
    }
    public final DateTimeField halfdayOfDay() {
        return ;
    }
    public final DurationField days() {
        return ;
    }
    public final DateTimeField dayOfWeek() {
        return ;
    }
    public final DateTimeField dayOfMonth() {
        return ;
    }
    public final DateTimeField dayOfYear() {
        return ;
    }
    public final DurationField weeks() {
        return ;
    }
    public final DateTimeField weekOfWeekyear() {
        return ;
    }
    public final DurationField weekyears() {
        return ;
    }
    public final DateTimeField weekyear() {
        return ;
    }
    public final DateTimeField weekyearOfCentury() {
        return ;
    }
    public final DurationField months() {
        return ;
    }
    public final DateTimeField monthOfYear() {
        return ;
    }
    public final DurationField years() {
        return ;
    }
    public final DateTimeField year() {
        return ;
    }
    public final DateTimeField yearOfEra() {
        return ;
    }
    public final DateTimeField yearOfCentury() {
        return ;
    }
    public final DurationField centuries() {
        return ;
    }
    public final DateTimeField centuryOfEra() {
        return ;
    }
    public final DurationField eras() {
        return ;
    }
    public final DateTimeField era() {
        return ;
    }

    
Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields. All unset fields default to unsupported instances.

Parameters:
fields container of fields
    protected abstract void assemble(Fields fields);

    
Returns the same base chronology as passed into the constructor.
    protected final Chronology getBase() {
        return ;
    }

    
Returns the same param object as passed into the constructor.
    protected final Object getParam() {
        return ;
    }
    private void setFields() {
        Fields fields = new Fields();
        if ( != null) {
            fields.copyFieldsFrom();
        }
        assemble(fields);
        {
            DurationField f;
                = (f = fields.millis)    != null ? f : super.millis();
               = (f = fields.seconds)   != null ? f : super.seconds();
               = (f = fields.minutes)   != null ? f : super.minutes();
                 = (f = fields.hours)     != null ? f : super.hours();
              = (f = fields.halfdays)  != null ? f : super.halfdays();
                  = (f = fields.days)      != null ? f : super.days();
                 = (f = fields.weeks)     != null ? f : super.weeks();
             = (f = fields.weekyears) != null ? f : super.weekyears();
                = (f = fields.months)    != null ? f : super.months();
                 = (f = fields.years)     != null ? f : super.years();
             = (f = fields.centuries) != null ? f : super.centuries();
                  = (f = fields.eras)      != null ? f : super.eras();
        }
        {
            DateTimeField f;
                 = (f = fields.millisOfSecond)     != null ? f : super.millisOfSecond();
                    = (f = fields.millisOfDay)        != null ? f : super.millisOfDay();
                 = (f = fields.secondOfMinute)     != null ? f : super.secondOfMinute();
                    = (f = fields.secondOfDay)        != null ? f : super.secondOfDay();
                   = (f = fields.minuteOfHour)       != null ? f : super.minuteOfHour();
                    = (f = fields.minuteOfDay)        != null ? f : super.minuteOfDay();
                      = (f = fields.hourOfDay)          != null ? f : super.hourOfDay();
                 = (f = fields.clockhourOfDay)     != null ? f : super.clockhourOfDay();
                  = (f = fields.hourOfHalfday)      != null ? f : super.hourOfHalfday();
             = (f = fields.clockhourOfHalfday) != null ? f : super.clockhourOfHalfday();
                   = (f = fields.halfdayOfDay)       != null ? f : super.halfdayOfDay();
                      = (f = fields.dayOfWeek)          != null ? f : super.dayOfWeek();
                     = (f = fields.dayOfMonth)         != null ? f : super.dayOfMonth();
                      = (f = fields.dayOfYear)          != null ? f : super.dayOfYear();
                 = (f = fields.weekOfWeekyear)     != null ? f : super.weekOfWeekyear();
                       = (f = fields.weekyear)           != null ? f : super.weekyear();
              = (f = fields.weekyearOfCentury)  != null ? f : super.weekyearOfCentury();
                    = (f = fields.monthOfYear)        != null ? f : super.monthOfYear();
                           = (f = fields.year)               != null ? f : super.year();
                      = (f = fields.yearOfEra)          != null ? f : super.yearOfEra();
                  = (f = fields.yearOfCentury)      != null ? f : super.yearOfCentury();
                   = (f = fields.centuryOfEra)       != null ? f : super.centuryOfEra();
                            = (f = fields.era)                != null ? f : super.era();
        }
        int flags;
        if ( == null) {
            flags = 0;
        } else {
            flags = 
                ((      == .hourOfDay()      &&
                     == .minuteOfHour()   &&
                   == .secondOfMinute() &&
                   == .millisOfSecond()   ) ? 1 : 0) |
                (( == .millisOfDay()) ? 2 : 0) |
                ((        == .year()        &&
                   == .monthOfYear() &&
                    == .dayOfMonth()    ) ? 4 : 0);
        }
         = flags;
    }
    private void readObject(ObjectInputStream inthrows IOExceptionClassNotFoundException {
        in.defaultReadObject();
        setFields();
    }

    
A container of fields used for assembling a chronology.
    public static final class Fields {
        public DurationField millis;
        public DurationField seconds;
        public DurationField minutes;
        public DurationField hours;
        public DurationField halfdays;
    
        public DurationField days;
        public DurationField weeks;
        public DurationField weekyears;
        public DurationField months;
        public DurationField years;
        public DurationField centuries;
        public DurationField eras;
    
        public DateTimeField millisOfSecond;
        public DateTimeField millisOfDay;
        public DateTimeField secondOfMinute;
        public DateTimeField secondOfDay;
        public DateTimeField minuteOfHour;
        public DateTimeField minuteOfDay;
        public DateTimeField hourOfDay;
        public DateTimeField clockhourOfDay;
        public DateTimeField hourOfHalfday;
        public DateTimeField clockhourOfHalfday;
        public DateTimeField halfdayOfDay;
    
        public DateTimeField dayOfWeek;
        public DateTimeField dayOfMonth;
        public DateTimeField dayOfYear;
        public DateTimeField weekOfWeekyear;
        public DateTimeField weekyear;
        public DateTimeField weekyearOfCentury;
        public DateTimeField monthOfYear;
        public DateTimeField year;
        public DateTimeField yearOfEra;
        public DateTimeField yearOfCentury;
        public DateTimeField centuryOfEra;
        public DateTimeField era;
        Fields() {
        }

        
Copy the supported fields from a chronology into this container.
        public void copyFieldsFrom(Chronology chrono) {
            {
                DurationField f;
                if (isSupported(f = chrono.millis())) {
                     = f;
                }
                if (isSupported(f = chrono.seconds())) {
                     = f;
                }
                if (isSupported(f = chrono.minutes())) {
                     = f;
                }
                if (isSupported(f = chrono.hours())) {
                     = f;
                }
                if (isSupported(f = chrono.halfdays())) {
                     = f;
                }
                if (isSupported(f = chrono.days())) {
                     = f;
                }
                if (isSupported(f = chrono.weeks())) {
                     = f;
                }
                if (isSupported(f = chrono.weekyears())) {
                     = f;
                }
                if (isSupported(f = chrono.months())) {
                     = f;
                }
                if (isSupported(f = chrono.years())) {
                     = f;
                }
                if (isSupported(f = chrono.centuries())) {
                     = f;
                }
                if (isSupported(f = chrono.eras())) {
                     = f;
                }
            }
            {
                DateTimeField f;
                if (isSupported(f = chrono.millisOfSecond())) {
                     = f;
                }
                if (isSupported(f = chrono.millisOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.secondOfMinute())) {
                     = f;
                }
                if (isSupported(f = chrono.secondOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.minuteOfHour())) {
                     = f;
                }
                if (isSupported(f = chrono.minuteOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.hourOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.clockhourOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.hourOfHalfday())) {
                     = f;
                }
                if (isSupported(f = chrono.clockhourOfHalfday())) {
                     = f;
                }
                if (isSupported(f = chrono.halfdayOfDay())) {
                     = f;
                }
                if (isSupported(f = chrono.dayOfWeek())) {
                     = f;
                }
                if (isSupported(f = chrono.dayOfMonth())) {
                     = f;
                }
                if (isSupported(f = chrono.dayOfYear())) {
                     = f;
                }
                if (isSupported(f = chrono.weekOfWeekyear())) {
                     = f;
                }
                if (isSupported(f = chrono.weekyear())) {
                     = f;
                }
                if (isSupported(f = chrono.weekyearOfCentury())) {
                     = f;
                }
                if (isSupported(f = chrono.monthOfYear())) {
                     = f;
                }
                if (isSupported(f = chrono.year())) {
                     = f;
                }
                if (isSupported(f = chrono.yearOfEra())) {
                     = f;
                }
                if (isSupported(f = chrono.yearOfCentury())) {
                     = f;
                }
                if (isSupported(f = chrono.centuryOfEra())) {
                     = f;
                }
                if (isSupported(f = chrono.era())) {
                     = f;
                }
            }
        }
        private static boolean isSupported(DurationField field) {
            return field == null ? false : field.isSupported();
        }
        private static boolean isSupported(DateTimeField field) {
            return field == null ? false : field.isSupported();
        }
    }
New to GrepCode? Check out our FAQ X