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;
 
A placeholder implementation to use when a duration field is not supported.

UnsupportedDurationField is thread-safe and immutable.

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

    
Serialization lock.
 
     private static final long serialVersionUID = -6390301302770925357L;

    
The cache of unsupported duration field instances
 
     private static HashMap cCache;

    
Gets an instance of UnsupportedDurationField for a specific named field. The returned instance is cached.

Parameters:
type the type to obtain
Returns:
the instance
 
     public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) {
         UnsupportedDurationField field;
         if ( == null) {
              = new HashMap(7);
             field = null;
         } else {
             field = (UnsupportedDurationField.get(type);
         }
         if (field == null) {
             field = new UnsupportedDurationField(type);
             .put(typefield);
         }
         return field;
     }

    
The name of the field
 
     private final DurationFieldType iType;

    
Constructor.

Parameters:
type the type to use
 
     private UnsupportedDurationField(DurationFieldType type) {
          = type;
     }
 
     //-----------------------------------------------------------------------
     // Design note: Simple Accessors return a suitable value, but methods
     // intended to perform calculations throw an UnsupportedOperationException.
 
     public final DurationFieldType getType() {
         return ;
     }
 
     public String getName() {
         return .getName();
     }

    
This field is not supported.

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

    
This field is precise.

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

    
Always throws UnsupportedOperationException

    public int getValue(long duration) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getValueAsLong(long duration) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getValue(long durationlong instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getValueAsLong(long durationlong instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getMillis(int value) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getMillis(long value) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getMillis(int valuelong instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getMillis(long valuelong instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long add(long instantint value) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long add(long instantlong value) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getDifference(long minuendInstantlong subtrahendInstant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long getDifferenceAsLong(long minuendInstantlong subtrahendInstant) {
        throw unsupported();
    }

    
Always returns zero.

Returns:
zero always
    public long getUnitMillis() {
        return 0;
    }

    
Always returns zero, indicating that sort order is not relevent.

Returns:
zero always
    public int compareTo(Object durationField) {
        return 0;
    }
    //------------------------------------------------------------------------
    
Compares this duration field to another.

Parameters:
obj the object to compare to
Returns:
true if equal
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj instanceof UnsupportedDurationField) {
            UnsupportedDurationField other = (UnsupportedDurationFieldobj;
            if (other.getName() == null) {
                return (getName() == null);
            }
            return (other.getName().equals(getName()));
        }
        return false;
    }

    
Gets a suitable hashcode.

Returns:
the hashcode
    public int hashCode() {
        return getName().hashCode();
    }

    
Get a suitable debug string.

Returns:
debug string
    public String toString() {
        return "UnsupportedDurationField[" + getName() + ']';
    }

    
Ensure proper singleton serialization
    private Object readResolve() {
        return getInstance();
    }
        return new UnsupportedOperationException( + " field is unsupported");
    }
New to GrepCode? Check out our FAQ X