Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2009 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;
 
 
Duration field class representing a field with a fixed unit length of one millisecond.

MillisDurationField is thread-safe and immutable.

Author(s):
Brian S O'Neill
Since:
1.0
 
 public final class MillisDurationField extends DurationField implements Serializable {

    
Serialization lock.
 
     private static final long serialVersionUID = 2656707858124633367L;

    
Singleton instance.
 
     public static final DurationField INSTANCE = new MillisDurationField();

    
Restricted constructor.
 
     private MillisDurationField() {
         super();
     }
     
     //------------------------------------------------------------------------
     public DurationFieldType getType() {
         return DurationFieldType.millis();
     }
 
     public String getName() {
         return "millis";
     }

    
Returns true as this field is supported.

Returns:
true always
 
     public boolean isSupported() {
         return true;
     }

    
Returns true as this field is precise.

Returns:
true always
 
     public final boolean isPrecise() {
         return true;
     }

    
Returns the amount of milliseconds per unit value of this field.

Returns:
one always
 
     public final long getUnitMillis() {
         return 1;
     }
 
     //------------------------------------------------------------------------
     public int getValue(long duration) {
         return FieldUtils.safeToInt(duration);
     }
 
     public long getValueAsLong(long duration) {
         return duration;
     }
 
     public int getValue(long durationlong instant) {
         return FieldUtils.safeToInt(duration);
     }
 
     public long getValueAsLong(long durationlong instant) {
         return duration;
     }
 
    public long getMillis(int value) {
        return value;
    }
    public long getMillis(long value) {
        return value;
    }
    public long getMillis(int valuelong instant) {
        return value;
    }
    public long getMillis(long valuelong instant) {
        return value;
    }
    public long add(long instantint value) {
        return FieldUtils.safeAdd(instantvalue);
    }
    public long add(long instantlong value) {
        return FieldUtils.safeAdd(instantvalue);
    }
    public int getDifference(long minuendInstantlong subtrahendInstant) {
        return FieldUtils.safeToInt(FieldUtils.safeSubtract(minuendInstantsubtrahendInstant));
    }
    public long getDifferenceAsLong(long minuendInstantlong subtrahendInstant) {
        return FieldUtils.safeSubtract(minuendInstantsubtrahendInstant);
    }
    //------------------------------------------------------------------------
    public int compareTo(DurationField otherField) {
        long otherMillis = otherField.getUnitMillis();
        long thisMillis = getUnitMillis();
        // cannot do (thisMillis - otherMillis) as can overflow
        if (thisMillis == otherMillis) {
            return 0;
        }
        if (thisMillis < otherMillis) {
            return -1;
        } else {
            return 1;
        }
    }
    public boolean equals(Object obj) {
        if (obj instanceof MillisDurationField) {
            return getUnitMillis() == ((MillisDurationFieldobj).getUnitMillis();
        }
        return false;
    }
    public int hashCode() {
        return (intgetUnitMillis();
    }

    
Get a suitable debug string.

Returns:
debug string
    public String toString() {
        return "DurationField[millis]";
    }

    
Deserialize to the singleton.
    private Object readResolve() {
        return ;
    }
New to GrepCode? Check out our FAQ X