Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2006 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.goda.time.convert;
 
AbstractConverter simplifies the process of implementing a converter.

Author(s):
Stephen Colebourne
Since:
1.0
 
 public abstract class AbstractConverter implements Converter {

    
Restricted constructor.
 
     protected AbstractConverter() {
         super();
     }
 
     //-----------------------------------------------------------------------
     
Extracts the millis from an object of this convertor's type.

This implementation returns the current time.

Parameters:
object the object to convert
chrono the chronology to use, which is always non-null
Returns:
the millisecond value
 
     public long getInstantMillis(Object objectChronology chrono) {
         return DateTimeUtils.currentTimeMillis();
     }
 
     //-----------------------------------------------------------------------
     
Extracts the chronology from an object of this convertor's type where the time zone is specified.

This implementation returns the ISO chronology.

Parameters:
object the object to convert
zone the specified zone to use, null means default zone
Returns:
the chronology, never null
 
     public Chronology getChronology(Object objectDateTimeZone zone) {
         return ISOChronology.getInstance(zone);
     }

    
Extracts the chronology from an object of this convertor's type where the chronology is specified.

This implementation returns the chronology specified, or the ISO chronology in the default zone if null passed in.

Parameters:
object the object to convert
chrono the chronology to use, null means ISO default
Returns:
the chronology, never null
 
     public Chronology getChronology(Object objectChronology chrono) {
         return DateTimeUtils.getChronology(chrono);
     }
 
     //-----------------------------------------------------------------------
     
Extracts the values of the partial from an object of this converter's type. The chrono parameter is a hint to the converter, should it require a chronology to aid in conversion.

This implementation calls getInstantMillis(java.lang.Object,org.goda.time.Chronology).

Parameters:
fieldSource a partial that provides access to the fields. This partial may be incomplete and only getFieldType(int) should be used
object the object to convert
chrono the chronology to use, which is the non-null result of getChronology()
Returns:
the array of field values that match the fieldSource, must be non-null valid
Throws:
java.lang.ClassCastException if the object is invalid
 
    public int[] getPartialValues(ReadablePartial fieldSourceObject objectChronology chrono) {
        long instant = getInstantMillis(objectchrono);
        return chrono.get(fieldSourceinstant);
    }

    
Extracts the values of the partial from an object of this converter's type. The chrono parameter is a hint to the converter, should it require a chronology to aid in conversion.

This implementation calls getPartialValues(org.goda.time.ReadablePartial,java.lang.Object,org.goda.time.Chronology).

Parameters:
fieldSource a partial that provides access to the fields. This partial may be incomplete and only getFieldType(int) should be used
object the object to convert
chrono the chronology to use, which is the non-null result of getChronology()
parser if converting from a String, the given parser is preferred
Returns:
the array of field values that match the fieldSource, must be non-null valid
Throws:
java.lang.ClassCastException if the object is invalid
Since:
1.3
    public int[] getPartialValues(ReadablePartial fieldSource,
            Object objectChronology chronoDateTimeFormatter parser) {
        return getPartialValues(fieldSourceobjectchrono);
    }
    //-----------------------------------------------------------------------
    
Selects a suitable period type for the given object.

Parameters:
object the object to examine
Returns:
the period type, never null
    public PeriodType getPeriodType(Object object) {
        return PeriodType.standard();
    }
    //-----------------------------------------------------------------------
    
Checks if the input is a ReadableInterval.

If it is, then the calling code should cast and copy the fields directly.

Parameters:
object the object to convert
chrono the chronology to use, may be null
Returns:
true if the input is a ReadableInterval
    public boolean isReadableInterval(Object objectChronology chrono) {
        return false;
    }
    //-----------------------------------------------------------------------
    
Gets a debugging string version of this converter.

Returns:
a debugging string
    public String toString() {
        return "Converter[" + (getSupportedType() == null ? "null" : getSupportedType().getName()) + "]";
    }
New to GrepCode? Check out our FAQ X