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;
 
Wraps another Chronology, ensuring all the fields are lenient.

LenientChronology is thread-safe and immutable.

Author(s):
Brian S O'Neill
Since:
1.0
See also:
org.joda.time.field.LenientDateTimeField
StrictChronology
 
 public final class LenientChronology extends AssembledChronology {

    
Serialization lock
 
     private static final long serialVersionUID = -3148237568046877177L;

    
Create a LenientChronology for any chronology.

Parameters:
base the chronology to wrap
Throws:
java.lang.IllegalArgumentException if chronology is null
 
     public static LenientChronology getInstance(Chronology base) {
         if (base == null) {
             throw new IllegalArgumentException("Must supply a chronology");
         }
         return new LenientChronology(base);
     }
 
     private transient Chronology iWithUTC;

    
Create a LenientChronology for any chronology.

Parameters:
base the chronology to wrap
 
     private LenientChronology(Chronology base) {
         super(basenull);
     }
 
     public Chronology withUTC() {
         if ( == null) {
             if (getZone() == .) {
                  = this;
             } else {
                  = LenientChronology.getInstance(getBase().withUTC());
             }
         }
         return ;
     }
 
     public Chronology withZone(DateTimeZone zone) {
         if (zone == null) {
             zone = DateTimeZone.getDefault();
         }
         if (zone == .) {
             return withUTC();
         }
         if (zone == getZone()) {
             return this;
         }
         return LenientChronology.getInstance(getBase().withZone(zone));
     }
 
     protected void assemble(Fields fields) {
         fields.year = convertField(fields.year);
         fields.yearOfEra = convertField(fields.yearOfEra);
         fields.yearOfCentury = convertField(fields.yearOfCentury);
         fields.centuryOfEra = convertField(fields.centuryOfEra);
         fields.era = convertField(fields.era);
         fields.dayOfWeek = convertField(fields.dayOfWeek);
         fields.dayOfMonth = convertField(fields.dayOfMonth);
         fields.dayOfYear = convertField(fields.dayOfYear);
         fields.monthOfYear = convertField(fields.monthOfYear);
         fields.weekOfWeekyear = convertField(fields.weekOfWeekyear);
         fields.weekyear = convertField(fields.weekyear);
         fields.weekyearOfCentury = convertField(fields.weekyearOfCentury);
 
        fields.millisOfSecond = convertField(fields.millisOfSecond);
        fields.millisOfDay = convertField(fields.millisOfDay);
        fields.secondOfMinute = convertField(fields.secondOfMinute);
        fields.secondOfDay = convertField(fields.secondOfDay);
        fields.minuteOfHour = convertField(fields.minuteOfHour);
        fields.minuteOfDay = convertField(fields.minuteOfDay);
        fields.hourOfDay = convertField(fields.hourOfDay);
        fields.hourOfHalfday = convertField(fields.hourOfHalfday);
        fields.clockhourOfDay = convertField(fields.clockhourOfDay);
        fields.clockhourOfHalfday = convertField(fields.clockhourOfHalfday);
        fields.halfdayOfDay = convertField(fields.halfdayOfDay);
    }
    private final DateTimeField convertField(DateTimeField field) {
        return LenientDateTimeField.getInstance(fieldgetBase());
    }
    //-----------------------------------------------------------------------
    
A lenient chronology is only equal to a lenient chronology with the same base chronology.

Parameters:
obj the object to compare to
Returns:
true if equal
Since:
1.4
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof LenientChronology == false) {
            return false;
        }
        LenientChronology chrono = (LenientChronologyobj;
        return getBase().equals(chrono.getBase());
    }

    
A suitable hashcode for the chronology.

Returns:
the hashcode
Since:
1.4
    public int hashCode() {
        return 236548278 + getBase().hashCode() * 7;
    }

    
A debugging string for the chronology.

Returns:
the debugging string
    public String toString() {
        return "LenientChronology[" + getBase().toString() + ']';
    }
New to GrepCode? Check out our FAQ X