Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2011 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.base;
 
 
BasePartial is an abstract implementation of ReadablePartial that stores data in array and Chronology fields.

This class should generally not be used directly by API users. The org.joda.time.ReadablePartial interface should be used when different kinds of partial objects are to be referenced.

BasePartial subclasses may be mutable and not thread-safe.

Author(s):
Stephen Colebourne
Since:
1.0
 
 public abstract class BasePartial
         extends AbstractPartial
         implements ReadablePartialSerializable {

    
Serialization version
 
     private static final long serialVersionUID = 2353678632973660L;

    
The chronology in use
 
     private final Chronology iChronology;
    
The values of each field in this partial
 
     private final int[] iValues;
 
     //-----------------------------------------------------------------------
     
Constructs a partial with the current time, using ISOChronology in the default zone to extract the fields.

The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

 
     protected BasePartial() {
         this(DateTimeUtils.currentTimeMillis(), null);
     }

    
Constructs a partial with the current time, using the specified chronology and zone to extract the fields.

The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

Parameters:
chronology the chronology, null means ISOChronology in the default zone
 
     protected BasePartial(Chronology chronology) {
         this(DateTimeUtils.currentTimeMillis(), chronology);
     }

    
Constructs a partial extracting the partial fields from the specified milliseconds using the ISOChronology in the default zone.

The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
 
     protected BasePartial(long instant) {
         this(instantnull);
     }

    
Constructs a partial extracting the partial fields from the specified milliseconds using the chronology provided.

The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
chronology the chronology, null means ISOChronology in the default zone
    protected BasePartial(long instantChronology chronology) {
        super();
        chronology = DateTimeUtils.getChronology(chronology);
         = chronology.withUTC();
         = chronology.get(thisinstant);
    }

    
Constructs a partial from an Object that represents a time, using the specified chronology.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

Parameters:
instant the datetime object
chronology the chronology, null means use converter
Throws:
java.lang.IllegalArgumentException if the date is invalid
    protected BasePartial(Object instantChronology chronology) {
        super();
        PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
        chronology = converter.getChronology(instantchronology);
        chronology = DateTimeUtils.getChronology(chronology);
         = chronology.withUTC();
         = converter.getPartialValues(thisinstantchronology);
    }

    
Constructs a partial from an Object that represents a time, using the specified chronology.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

Parameters:
instant the datetime object
chronology the chronology, null means use converter
parser if converting from a String, the given parser is preferred
Throws:
java.lang.IllegalArgumentException if the date is invalid
Since:
1.3
    protected BasePartial(Object instantChronology chronologyDateTimeFormatter parser) {
        super();
        PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
        chronology = converter.getChronology(instantchronology);
        chronology = DateTimeUtils.getChronology(chronology);
         = chronology.withUTC();
         = converter.getPartialValues(thisinstantchronologyparser);
    }

    
Constructs a partial with specified time field values and chronology.

The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).

The array of values is assigned (not cloned) to the new instance.

Parameters:
values the new set of values
chronology the chronology, null means ISOChronology in the default zone
Throws:
java.lang.IllegalArgumentException if the values are invalid
    protected BasePartial(int[] valuesChronology chronology) {
        super();
        chronology = DateTimeUtils.getChronology(chronology);
         = chronology.withUTC();
        chronology.validate(thisvalues);
         = values;
    }

    
Private constructor to be used by subclasses only which performs no validation.

Data is assigned (not cloned) to the new instance.

Parameters:
base the base partial
values the new set of values, not cloned, null means use base
    protected BasePartial(BasePartial baseint[] values) {
        super();
         = base.iChronology;
         = values;
    }

    
Private constructor to be used by subclasses only which performs no validation.

Data is assigned (not cloned) to the new instance. This should not be used by mutable subclasses.

Parameters:
base the base partial
chrono the chronology to use, null means use base
    protected BasePartial(BasePartial baseChronology chrono) {
        super();
         = chrono.withUTC();
         = base.iValues;
    }
    //-----------------------------------------------------------------------
    
Gets the value of the field at the specifed index.

Parameters:
index the index
Returns:
the value
Throws:
java.lang.IndexOutOfBoundsException if the index is invalid
    public int getValue(int index) {
        return [index];
    }

    
Gets an array of the value of each of the fields that this partial supports.

The fields are returned largest to smallest, for example Hour, Minute, Second. Each value corresponds to the same array index as getFields()

Returns:
the current values of each field (cloned), largest to smallest
    public int[] getValues() {
        return (int[]) .clone();
    }

    
Gets the chronology of the partial which is never null.

The org.joda.time.Chronology is the calculation engine behind the partial and provides conversion and validation of the fields in a particular calendar system.

Returns:
the chronology, never null
    public Chronology getChronology() {
        return ;
    }
    //-----------------------------------------------------------------------
    
Sets the value of the field at the specified index.

In version 2.0 and later, this method copies the array into the original. This is because the instance variable has been changed to be final to satisfy the Java Memory Model. This only impacts subclasses that are mutable.

Parameters:
index the index
value the value to set
Throws:
java.lang.IndexOutOfBoundsException if the index is invalid
    protected void setValue(int indexint value) {
        DateTimeField field = getField(index);
        int[] values = field.set(thisindexvalue);
        System.arraycopy(values, 0, , 0, .);
    }

    
Sets the values of all fields.

In version 2.0 and later, this method copies the array into the original. This is because the instance variable has been changed to be final to satisfy the Java Memory Model. This only impacts subclasses that are mutable.

Parameters:
values the array of values
    protected void setValues(int[] values) {
        getChronology().validate(thisvalues);
        System.arraycopy(values, 0, , 0, .);
    }
    //-----------------------------------------------------------------------
    
Output the date using the specified format pattern.

Parameters:
pattern the pattern specification, null means use toString
See also:
org.joda.time.format.DateTimeFormat
    public String toString(String pattern) {
        if (pattern == null) {
            return toString();
        }
        return DateTimeFormat.forPattern(pattern).print(this);
    }

    
Output the date using the specified format pattern.

Parameters:
pattern the pattern specification, null means use toString
locale Locale to use, null means default
See also:
org.joda.time.format.DateTimeFormat
    public String toString(String patternLocale localethrows IllegalArgumentException {
        if (pattern == null) {
            return toString();
        }
        return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this);
    }
New to GrepCode? Check out our FAQ X