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.field;
 
Wraps another field such that a certain value is skipped.

This is most useful for years where you want to skip zero, so the sequence runs ...,2,1,-1,-2,...

SkipDateTimeField is thread-safe and immutable.

Author(s):
Brian S O'Neill
Stephen Colebourne
Since:
1.0
 
 public final class SkipDateTimeField extends DelegatedDateTimeField {

    
Serialization version.
 
     private static final long serialVersionUID = -8869148464118507846L;

    
The chronology to wrap.
 
     private final Chronology iChronology;
    
The value to skip.
 
     private final int iSkip;
    
The calculated minimum value.
 
     private transient int iMinValue;

    
Constructor that skips zero.

Parameters:
chronology the chronoogy to use
field the field to skip zero on
 
     public SkipDateTimeField(Chronology chronologyDateTimeField field) {
         this(chronologyfield, 0);
     }

    
Constructor.

Parameters:
chronology the chronoogy to use
field the field to skip zero on
skip the value to skip
 
     public SkipDateTimeField(Chronology chronologyDateTimeField fieldint skip) {
         super(field);
          = chronology;
         int min = super.getMinimumValue();
         if (min < skip) {
              = min - 1;
         } else if (min == skip) {
              = skip + 1;
         } else {
              = min;
         }
          = skip;
     }
 
     //-----------------------------------------------------------------------
     public int get(long millis) {
         int value = super.get(millis);
         if (value <= ) {
             value--;
         }
         return value;
     }
 
     public long set(long millisint value) {
         FieldUtils.verifyValueBounds(thisvaluegetMaximumValue());
         if (value <= ) {
             if (value == ) {
                 throw new IllegalFieldValueException
                     (DateTimeFieldType.year(), Integer.valueOf(value), nullnull);
             }
             value++;
         }
         return super.set(millisvalue);
     }
 
     public int getMinimumValue() {
        return ;
    }
    private Object readResolve() {
        return getType().getField();
    }
New to GrepCode? Check out our FAQ X