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

UnsupportedDateTimeField is thread-safe and immutable.

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

    
Serialilzation version
 
     private static final long serialVersionUID = -1934618396111902255L;

    
The cache of unsupported datetime field instances
 
     private static HashMap<DateTimeFieldTypeUnsupportedDateTimeFieldcCache;

    
Gets an instance of UnsupportedDateTimeField for a specific named field. Names should be of standard format, such as 'monthOfYear' or 'hourOfDay'. The returned instance is cached.

Parameters:
type the type to obtain
Returns:
the instance
Throws:
java.lang.IllegalArgumentException if durationField is null
 
     public static synchronized UnsupportedDateTimeField getInstance(
             DateTimeFieldType typeDurationField durationField) {
 
         UnsupportedDateTimeField field;
         if ( == null) {
              = new HashMap<DateTimeFieldTypeUnsupportedDateTimeField>(7);
             field = null;
         } else {
             field = .get(type);
             if (field != null && field.getDurationField() != durationField) {
                 field = null;
             }
         }
         if (field == null) {
             field = new UnsupportedDateTimeField(typedurationField);
             .put(typefield);
         }
         return field;
     }

    
The field type
 
     private final DateTimeFieldType iType;
    
The duration of the datetime field
 
     private final DurationField iDurationField;

    
Constructor.

Parameters:
type the field type
durationField the duration to use
 
     private UnsupportedDateTimeField(DateTimeFieldType typeDurationField durationField) {
         if (type == null || durationField == null) {
             throw new IllegalArgumentException();
         }
          = type;
          = durationField;
     }
 
     //-----------------------------------------------------------------------
     // Design note: Simple accessors return a suitable value, but methods
     // intended to perform calculations throw an UnsupportedOperationException.
 
     public DateTimeFieldType getType() {
         return ;
     }
 
     public String getName() {
         return .getName();
    }

    
This field is not supported.

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

    
This field is not lenient.

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

    
Always throws UnsupportedOperationException

    public int get(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsText(long instantLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsText(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsText(ReadablePartial partialint fieldValueLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsText(ReadablePartial partialLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsText(int fieldValueLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsShortText(long instantLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsShortText(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsShortText(ReadablePartial partialint fieldValueLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsShortText(ReadablePartial partialLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public String getAsShortText(int fieldValueLocale locale) {
        throw unsupported();
    }

    
Delegates to the duration field.

Throws:
java.lang.UnsupportedOperationException if the duration is unsupported
    public long add(long instantint value) {
        return getDurationField().add(instantvalue);
    }

    
Delegates to the duration field.

Throws:
java.lang.UnsupportedOperationException if the duration is unsupported
    public long add(long instantlong value) {
        return getDurationField().add(instantvalue);
    }

    
Always throws UnsupportedOperationException

    public int[] add(ReadablePartial instantint fieldIndexint[] valuesint valueToAdd) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int[] addWrapPartial(ReadablePartial instantint fieldIndexint[] valuesint valueToAdd) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

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

    
Always throws UnsupportedOperationException

    public int[] addWrapField(ReadablePartial instantint fieldIndexint[] valuesint valueToAdd) {
        throw unsupported();
    }

    
Delegates to the duration field.

Throws:
java.lang.UnsupportedOperationException if the duration is unsupported
    public int getDifference(long minuendInstantlong subtrahendInstant) {
        return getDurationField().getDifference(minuendInstantsubtrahendInstant);
    }

    
Delegates to the duration field.

Throws:
java.lang.UnsupportedOperationException if the duration is unsupported
    public long getDifferenceAsLong(long minuendInstantlong subtrahendInstant) {
        return getDurationField().getDifferenceAsLong(minuendInstantsubtrahendInstant);
    }

    
Always throws UnsupportedOperationException

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

    
Always throws UnsupportedOperationException

    public int[] set(ReadablePartial instantint fieldIndexint[] valuesint newValue) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long set(long instantString textLocale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long set(long instantString text) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int[] set(ReadablePartial instantint fieldIndexint[] valuesString textLocale locale) {
        throw unsupported();
    }

    
Even though this DateTimeField is unsupported, the duration field might be supported.

Returns:
a possibly supported DurationField
    public DurationField getDurationField() {
        return ;
    }

    
Always returns null.

Returns:
null always
        return null;
    }

    
Always throws UnsupportedOperationException

    public boolean isLeap(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getLeapAmount(long instant) {
        throw unsupported();
    }

    
Always returns null.

Returns:
null always
        return null;
    }

    
Always throws UnsupportedOperationException

    public int getMinimumValue() {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMinimumValue(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMinimumValue(ReadablePartial instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMinimumValue(ReadablePartial instantint[] values) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumValue() {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumValue(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumValue(ReadablePartial instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumValue(ReadablePartial instantint[] values) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumTextLength(Locale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public int getMaximumShortTextLength(Locale locale) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long roundFloor(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long roundCeiling(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long roundHalfFloor(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long roundHalfCeiling(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long roundHalfEven(long instant) {
        throw unsupported();
    }

    
Always throws UnsupportedOperationException

    public long remainder(long instant) {
        throw unsupported();
    }
    //------------------------------------------------------------------------
    
Get a suitable debug string.

Returns:
debug string
    public String toString() {
        return "UnsupportedDateTimeField";
    }

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