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 added back into the sequence of numbers.

This reverses the effect of SkipDateTimeField. This isn't very elegant.

SkipUndoDateTimeField is thread-safe and immutable.

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

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

    
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 reinserts zero.

Parameters:
chronology the chronoogy to use
field the field to skip zero on
 
     public SkipUndoDateTimeField(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 SkipUndoDateTimeField(Chronology chronologyDateTimeField fieldint skip) {
         super(field);
          = chronology;
         int min = super.getMinimumValue();
         if (min < skip) {
              = min + 1;
         } else if (min == skip + 1) {
              = skip;
         } 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 <= ) {
             value--;
         }
         return super.set(millisvalue);
     }
 
     public int getMinimumValue() {
         return ;
     }
 
     private Object readResolve() {
         return getType().getField();
    }
New to GrepCode? Check out our FAQ X