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;
 
 import java.util.List;
 
Partial is an immutable partial datetime supporting any set of datetime fields.

A Partial instance can be used to hold any combination of fields. The instance does not contain a time zone, so any datetime is local.

A Partial can be matched against an instant using isMatch(org.joda.time.ReadableInstant). This method compares each field on this partial with those of the instant and determines if the partial matches the instant. Given this definition, an empty Partial instance represents any datetime and always matches.

Calculations on Partial are performed using a Chronology. This chronology is set to be in the UTC time zone for all calculations.

Each individual field can be queried in two ways:

  • get(DateTimeFieldType.monthOfYear())
  • property(DateTimeFieldType.monthOfYear()).get()
The second technique also provides access to other useful methods on the field:
  • numeric value - monthOfYear().get()
  • text value - monthOfYear().getAsText()
  • short text value - monthOfYear().getAsShortText()
  • maximum/minimum values - monthOfYear().getMaximumValue()
  • add/subtract - monthOfYear().addToCopy()
  • set - monthOfYear().setCopy()

Partial is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.

Author(s):
Stephen Colebourne
Since:
1.1
 
 public final class Partial
         extends AbstractPartial
         implements ReadablePartialSerializable {

    
Serialization version
 
     private static final long serialVersionUID = 12324121189002L;

    
The chronology in use.
 
     private final Chronology iChronology;
    
The set of field types.
 
     private final DateTimeFieldType[] iTypes;
    
The values of each field in this partial.
 
     private final int[] iValues;
    
The formatter to use, [0] may miss some fields, [1] doesn't miss any fields.
 
     private transient DateTimeFormatter[] iFormatter;
 
     // Constructors
     //-----------------------------------------------------------------------
     
Constructs a Partial with no fields or values, which can be considered to represent any date.

This is most useful when constructing partials, for example:

 Partial p = new Partial()
     .with(DateTimeFieldType.dayOfWeek(), 5)
     .with(DateTimeFieldType.hourOfDay(), 12)
     .with(DateTimeFieldType.minuteOfHour(), 20);
 
Note that, although this is a clean way to write code, it is fairly inefficient internally.

The constructor uses the default ISO chronology.

    public Partial() {
        this((Chronologynull);
    }

    
Constructs a Partial with no fields or values, which can be considered to represent any date.

This is most useful when constructing partials, for example:

 Partial p = new Partial(chrono)
     .with(DateTimeFieldType.dayOfWeek(), 5)
     .with(DateTimeFieldType.hourOfDay(), 12)
     .with(DateTimeFieldType.minuteOfHour(), 20);
 
Note that, although this is a clean way to write code, it is fairly inefficient internally.

Parameters:
chrono the chronology, null means ISO
    public Partial(Chronology chrono) {
        super();
         = DateTimeUtils.getChronology(chrono).withUTC();
         = new DateTimeFieldType[0];
         = new int[0];
    }

    
Constructs a Partial with the specified field and value.

The constructor uses the default ISO chronology.

Parameters:
type the single type to create the partial from, not null
value the value to store
Throws:
java.lang.IllegalArgumentException if the type or value is invalid
    public Partial(DateTimeFieldType typeint value) {
        this(typevaluenull);
    }

    
Constructs a Partial with the specified field and value.

The constructor uses the specified chronology.

Parameters:
type the single type to create the partial from, not null
value the value to store
chronology the chronology, null means ISO
Throws:
java.lang.IllegalArgumentException if the type or value is invalid
    public Partial(DateTimeFieldType typeint valueChronology chronology) {
        super();
        chronology = DateTimeUtils.getChronology(chronology).withUTC();
         = chronology;
        if (type == null) {
            throw new IllegalArgumentException("The field type must not be null");
        }
         = new DateTimeFieldType[] {type};
         = new int[] {value};
        chronology.validate(this);
    }

    
Constructs a Partial with the specified fields and values. The fields must be specified in the order largest to smallest.

The constructor uses the specified chronology.

Parameters:
types the types to create the partial from, not null
values the values to store, not null
Throws:
java.lang.IllegalArgumentException if the types or values are invalid
    public Partial(DateTimeFieldType[] typesint[] values) {
        this(typesvaluesnull);
    }

    
Constructs a Partial with the specified fields and values. The fields must be specified in the order largest to smallest.

The constructor uses the specified chronology.

Parameters:
types the types to create the partial from, not null
values the values to store, not null
chronology the chronology, null means ISO
Throws:
java.lang.IllegalArgumentException if the types or values are invalid
    public Partial(DateTimeFieldType[] typesint[] valuesChronology chronology) {
        super();
        chronology = DateTimeUtils.getChronology(chronology).withUTC();
         = chronology;
        if (types == null) {
            throw new IllegalArgumentException("Types array must not be null");
        }
        if (values == null) {
            throw new IllegalArgumentException("Values array must not be null");
        }
        if (values.length != types.length) {
            throw new IllegalArgumentException("Values array must be the same length as the types array");
        }
        if (types.length == 0) {
             = types;
             = values;
            return;
        }
        for (int i = 0; i < types.lengthi++) {
            if (types[i] == null) {
                throw new IllegalArgumentException("Types array must not contain null: index " + i);
            }
        }
        DurationField lastUnitField = null;
        for (int i = 0; i < types.lengthi++) {
            DateTimeFieldType loopType = types[i];
            DurationField loopUnitField = loopType.getDurationType().getField();
            if (i > 0) {
                int compare = lastUnitField.compareTo(loopUnitField);
                if (compare < 0 || (compare != 0 && loopUnitField.isSupported() == false)) {
                    throw new IllegalArgumentException("Types array must be in order largest-smallest: " +
                            types[i - 1].getName() + " < " + loopType.getName());
                } else if (compare == 0) {
                    if (types[i - 1].getRangeDurationType() == null) {
                        if (loopType.getRangeDurationType() == null) {
                            throw new IllegalArgumentException("Types array must not contain duplicate: " + loopType.getName());
                        }
                    } else {
                        if (loopType.getRangeDurationType() == null) {
                            throw new IllegalArgumentException("Types array must be in order largest-smallest: " +
                                    types[i - 1].getName() + " < " + loopType.getName());
                        }
                        DurationField lastRangeField = types[i - 1].getRangeDurationType().getField();
                        DurationField loopRangeField = loopType.getRangeDurationType().getField();
                        if (lastRangeField.compareTo(loopRangeField) < 0) {
                            throw new IllegalArgumentException("Types array must be in order largest-smallest: " +
                                    types[i - 1].getName() + " < " + loopType.getName());
                        }
                        if (lastRangeField.compareTo(loopRangeField) == 0) {
                            throw new IllegalArgumentException("Types array must not contain duplicate: " + loopType.getName());
                        }
                    }
                }
            }
            lastUnitField = loopUnitField;
        }
        
         = (DateTimeFieldType[]) types.clone();
        chronology.validate(thisvalues);
         = (int[]) values.clone();
    }

    
Constructs a Partial by copying all the fields and types from another partial.

This is most useful when copying from a YearMonthDay or TimeOfDay.

    public Partial(ReadablePartial partial) {
        super();
        if (partial == null) {
            throw new IllegalArgumentException("The partial must not be null");
        }
         = DateTimeUtils.getChronology(partial.getChronology()).withUTC();
         = new DateTimeFieldType[partial.size()];
         = new int[partial.size()];
        for (int i = 0; i < partial.size(); i++) {
            [i] = partial.getFieldType(i);
            [i] = partial.getValue(i);
        }
    }

    
Constructs a Partial with the specified values. This constructor assigns and performs no validation.

Parameters:
partial the partial to copy
values the values to store
Throws:
java.lang.IllegalArgumentException if the types or values are invalid
    Partial(Partial partialint[] values) {
        super();
         = partial.iChronology;
         = partial.iTypes;
         = values;
    }

    
Constructs a Partial with the specified chronology, fields and values. This constructor assigns and performs no validation.

Parameters:
chronology the chronology
types the types to create the partial from
values the values to store
Throws:
java.lang.IllegalArgumentException if the types or values are invalid
    Partial(Chronology chronologyDateTimeFieldType[] typesint[] values) {
        super();
         = chronology;
         = types;
         = values;
    }
    //-----------------------------------------------------------------------
    
Gets the number of fields in this partial.

Returns:
the field count
    public int size() {
        return .;
    }

    
Gets the chronology of the partial which is never null.

The 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 ;
    }

    
Gets the field for a specific index in the chronology specified.

Parameters:
index the index to retrieve
chrono the chronology to use
Returns:
the field
Throws:
java.lang.IndexOutOfBoundsException if the index is invalid
    protected DateTimeField getField(int indexChronology chrono) {
        return [index].getField(chrono);
    }

    
Gets the field type at the specified index.

Parameters:
index the index to retrieve
Returns:
the field at the specified index
Throws:
java.lang.IndexOutOfBoundsException if the index is invalid
    public DateTimeFieldType getFieldType(int index) {
        return [index];
    }

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

The fields are returned largest to smallest.

Returns:
the array of field types (cloned), largest to smallest
    public DateTimeFieldType[] getFieldTypes() {
        return (DateTimeFieldType[]) .clone();
    }
    //-----------------------------------------------------------------------
    
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. Each value corresponds to the same array index as getFieldTypes()

Returns:
the current values of each field (cloned), largest to smallest
    public int[] getValues() {
        return (int[]) .clone();
    }
    //-----------------------------------------------------------------------
    
Creates a new Partial instance with the specified chronology. This instance is immutable and unaffected by this method call.

This method retains the values of the fields, thus the result will typically refer to a different instant.

The time zone of the specified chronology is ignored, as Partial operates without a time zone.

Parameters:
newChronology the new chronology, null means ISO
Returns:
a copy of this datetime with a different chronology
Throws:
java.lang.IllegalArgumentException if the values are invalid for the new chronology
    public Partial withChronologyRetainFields(Chronology newChronology) {
        newChronology = DateTimeUtils.getChronology(newChronology);
        newChronology = newChronology.withUTC();
        if (newChronology == getChronology()) {
            return this;
        } else {
            Partial newPartial = new Partial(newChronology);
            newChronology.validate(newPartial);
            return newPartial;
        }
    }
    //-----------------------------------------------------------------------
    
Gets a copy of this date with the specified field set to a new value.

If this partial did not previously support the field, the new one will. Contrast this behaviour with withField(org.joda.time.DateTimeFieldType,int).

For example, if the field type is dayOfMonth then the day would be changed/added in the returned instance.

Parameters:
fieldType the field type to set, not null
value the value to set
Returns:
a copy of this instance with the field set
Throws:
java.lang.IllegalArgumentException if the value is null or invalid
    public Partial with(DateTimeFieldType fieldTypeint value) {
        if (fieldType == null) {
            throw new IllegalArgumentException("The field type must not be null");
        }
        int index = indexOf(fieldType);
        if (index == -1) {
            DateTimeFieldType[] newTypes = new DateTimeFieldType[. + 1];
            int[] newValues = new int[newTypes.length];
            
            // find correct insertion point to keep largest-smallest order
            int i = 0;
            DurationField unitField = fieldType.getDurationType().getField();
            if (unitField.isSupported()) {
                for (; i < .i++) {
                    DateTimeFieldType loopType = [i];
                    DurationField loopUnitField = loopType.getDurationType().getField();
                    if (loopUnitField.isSupported()) {
                        int compare = unitField.compareTo(loopUnitField);
                        if (compare > 0) {
                            break;
                        } else if (compare == 0) {
                            DurationField rangeField = fieldType.getRangeDurationType().getField();
                            DurationField loopRangeField = loopType.getRangeDurationType().getField();
                            if (rangeField.compareTo(loopRangeField) > 0) {
                                break;
                            }
                        }
                    }
                }
            }
            System.arraycopy(, 0, newTypes, 0, i);
            System.arraycopy(, 0, newValues, 0, i);
            newTypes[i] = fieldType;
            newValues[i] = value;
            System.arraycopy(inewTypesi + 1, newTypes.length - i - 1);
            System.arraycopy(inewValuesi + 1, newValues.length - i - 1);
            
            Partial newPartial = new Partial(newTypesnewValues);
            .validate(newPartialnewValues);
            return newPartial;
        }
        if (value == getValue(index)) {
            return this;
        }
        int[] newValues = getValues();
        newValues = getField(index).set(thisindexnewValuesvalue);
        return new Partial(thisnewValues);
    }

    
Gets a copy of this date with the specified field removed.

If this partial did not previously support the field, no error occurs.

Parameters:
fieldType the field type to remove, may be null
Returns:
a copy of this instance with the field removed
    public Partial without(DateTimeFieldType fieldType) {
        int index = indexOf(fieldType);
        if (index != -1) {
            DateTimeFieldType[] newTypes = new DateTimeFieldType[size() - 1];
            int[] newValues = new int[size() - 1];
            System.arraycopy(, 0, newTypes, 0, index);
            System.arraycopy(index + 1, newTypesindexnewTypes.length - index);
            System.arraycopy(, 0, newValues, 0, index);
            System.arraycopy(index + 1, newValuesindexnewValues.length - index);
            Partial newPartial = new Partial(newTypesnewValues);
            .validate(newPartialnewValues);
            return newPartial;
        }
        return this;
    }
    //-----------------------------------------------------------------------
    
Gets a copy of this Partial with the specified field set to a new value.

If this partial does not support the field, an exception is thrown. Contrast this behaviour with with(org.joda.time.DateTimeFieldType,int).

For example, if the field type is dayOfMonth then the day would be changed in the returned instance if supported.

Parameters:
fieldType the field type to set, not null
value the value to set
Returns:
a copy of this instance with the field set
Throws:
java.lang.IllegalArgumentException if the value is null or invalid
    public Partial withField(DateTimeFieldType fieldTypeint value) {
        int index = indexOfSupported(fieldType);
        if (value == getValue(index)) {
            return this;
        }
        int[] newValues = getValues();
        newValues = getField(index).set(thisindexnewValuesvalue);
        return new Partial(thisnewValues);
    }

    
Gets a copy of this Partial with the value of the specified field increased. If this partial does not support the field, an exception is thrown.

If the addition is zero, then this is returned. The addition will overflow into larger fields (eg. minute to hour). However, it will not wrap around if the top maximum is reached.

Parameters:
fieldType the field type to add to, not null
amount the amount to add
Returns:
a copy of this instance with the field updated
Throws:
java.lang.IllegalArgumentException if the value is null or invalid
java.lang.ArithmeticException if the new datetime exceeds the capacity
    public Partial withFieldAdded(DurationFieldType fieldTypeint amount) {
        int index = indexOfSupported(fieldType);
        if (amount == 0) {
            return this;
        }
        int[] newValues = getValues();
        newValues = getField(index).add(thisindexnewValuesamount);
        return new Partial(thisnewValues);
    }

    
Gets a copy of this Partial with the value of the specified field increased. If this partial does not support the field, an exception is thrown.

If the addition is zero, then this is returned. The addition will overflow into larger fields (eg. minute to hour). If the maximum is reached, the addition will wra.

Parameters:
fieldType the field type to add to, not null
amount the amount to add
Returns:
a copy of this instance with the field updated
Throws:
java.lang.IllegalArgumentException if the value is null or invalid
java.lang.ArithmeticException if the new datetime exceeds the capacity
    public Partial withFieldAddWrapped(DurationFieldType fieldTypeint amount) {
        int index = indexOfSupported(fieldType);
        if (amount == 0) {
            return this;
        }
        int[] newValues = getValues();
        newValues = getField(index).addWrapPartial(thisindexnewValuesamount);
        return new Partial(thisnewValues);
    }

    
Gets a copy of this Partial with the specified period added.

If the addition is zero, then this is returned. Fields in the period that aren't present in the partial are ignored.

This method is typically used to add multiple copies of complex period instances. Adding one field is best achieved using the method withFieldAdded(org.joda.time.DurationFieldType,int).

Parameters:
period the period to add to this one, null means zero
scalar the amount of times to add, such as -1 to subtract once
Returns:
a copy of this instance with the period added
Throws:
java.lang.ArithmeticException if the new datetime exceeds the capacity
    public Partial withPeriodAdded(ReadablePeriod periodint scalar) {
        if (period == null || scalar == 0) {
            return this;
        }
        int[] newValues = getValues();
        for (int i = 0; i < period.size(); i++) {
            DurationFieldType fieldType = period.getFieldType(i);
            int index = indexOf(fieldType);
            if (index >= 0) {
                newValues = getField(index).add(thisindexnewValues,
                        FieldUtils.safeMultiply(period.getValue(i), scalar));
            }
        }
        return new Partial(thisnewValues);
    }

    
Gets a copy of this instance with the specified period added.

If the amount is zero or null, then this is returned.

Parameters:
period the duration to add to this one, null means zero
Returns:
a copy of this instance with the period added
Throws:
java.lang.ArithmeticException if the new datetime exceeds the capacity of a long
    public Partial plus(ReadablePeriod period) {
        return withPeriodAdded(period, 1);
    }

    
Gets a copy of this instance with the specified period take away.

If the amount is zero or null, then this is returned.

Parameters:
period the period to reduce this instant by
Returns:
a copy of this instance with the period taken away
Throws:
java.lang.ArithmeticException if the new datetime exceeds the capacity of a long
    public Partial minus(ReadablePeriod period) {
        return withPeriodAdded(period, -1);
    }
    //-----------------------------------------------------------------------
    
Gets the property object for the specified type, which contains many useful methods for getting and manipulating the partial.

See also ReadablePartial.get(org.joda.time.DateTimeFieldType).

Parameters:
type the field type to get the property for, not null
Returns:
the property object
Throws:
java.lang.IllegalArgumentException if the field is null or unsupported
    public Property property(DateTimeFieldType type) {
        return new Property(thisindexOfSupported(type));
    }
    //-----------------------------------------------------------------------
    
Does this partial match the specified instant.

A match occurs when all the fields of this partial are the same as the corresponding fields on the specified instant.

Parameters:
instant an instant to check against, null means now in default zone
Returns:
true if this partial matches the specified instant
    public boolean isMatch(ReadableInstant instant) {
        long millis = DateTimeUtils.getInstantMillis(instant);
        Chronology chrono = DateTimeUtils.getInstantChronology(instant);
        for (int i = 0; i < .i++) {
            int value = [i].getField(chrono).get(millis);
            if (value != [i]) {
                return false;
            }
        }
        return true;
    }

    
Does this partial match the specified partial.

A match occurs when all the fields of this partial are the same as the corresponding fields on the specified partial.

Parameters:
partial a partial to check against, must not be null
Returns:
true if this partial matches the specified partial
Throws:
java.lang.IllegalArgumentException if the partial is null
java.lang.IllegalArgumentException if the fields of the two partials do not match
Since:
1.5
    public boolean isMatch(ReadablePartial partial) {
        if (partial == null) {
            throw new IllegalArgumentException("The partial must not be null");
        }
        for (int i = 0; i < .i++) {
            int value = partial.get([i]);
            if (value != [i]) {
                return false;
            }
        }
        return true;
    }
    //-----------------------------------------------------------------------
    
Gets a formatter suitable for the fields in this partial.

If there is no appropriate ISO format, null is returned. This method may return a formatter that does not display all the fields of the partial. This might occur when you have overlapping fields, such as dayOfWeek and dayOfMonth.

Returns:
a formatter suitable for the fields in this partial, null if none is suitable
    public DateTimeFormatter getFormatter() {
        DateTimeFormatter[] f = ;
        if (f == null) {
            if (size() == 0) {
                return null;
            }
            f = new DateTimeFormatter[2];
            try {
                List<DateTimeFieldTypelist = new ArrayList<DateTimeFieldType>(Arrays.asList());
                f[0] = ISODateTimeFormat.forFields(listtruefalse);
                if (list.size() == 0) {
                    f[1] = f[0];
                }
            } catch (IllegalArgumentException ex) {
                // ignore
            }
             = f;
        }
        return f[0];
    }
    //-----------------------------------------------------------------------
    
Output the date in an appropriate ISO8601 format.

This method will output the partial in one of two ways. If getFormatter()

If there is no appropriate ISO format a dump of the fields is output via toStringList().

Returns:
ISO8601 formatted string
    public String toString() {
        DateTimeFormatter[] f = ;
        if (f == null) {
            getFormatter();
            f = ;
            if (f == null) {
                return toStringList();
            }
        }
        DateTimeFormatter f1 = f[1];
        if (f1 == null) {
            return toStringList();
        }
        return f1.print(this);
    }

    
Gets a string version of the partial that lists all the fields.

This method exists to provide a better debugging toString than the standard toString. This method lists all the fields and their values in a style similar to the collections framework.

Returns:
a toString format that lists all the fields
    public String toStringList() {
        int size = size();
        StringBuffer buf = new StringBuffer(20 * size);
        buf.append('[');
        for (int i = 0; i < sizei++) {
            if (i > 0) {
                buf.append(',').append(' ');
            }
            buf.append([i].getName());
            buf.append('=');
            buf.append([i]);
        }
        buf.append(']');
        return buf.toString();
    }

    
Output the date using the specified format pattern. Unsupported fields will appear as special unicode characters.

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. Unsupported fields will appear as special unicode characters.

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 locale) {
        if (pattern == null) {
            return toString();
        }
        return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this);
    }
    //-----------------------------------------------------------------------
    
The property class for Partial.

This class binds a Partial to a DateTimeField.

Author(s):
Stephen Colebourne
Since:
1.1
    public static class Property extends AbstractPartialFieldProperty implements Serializable {

        
Serialization version
        private static final long serialVersionUID = 53278362873888L;

        
The partial
        private final Partial iPartial;
        
The field index
        private final int iFieldIndex;

        
Constructs a property.

Parameters:
partial the partial instance
fieldIndex the index in the partial
        Property(Partial partialint fieldIndex) {
            super();
             = partial;
             = fieldIndex;
        }

        
Gets the field that this property uses.

Returns:
the field
        public DateTimeField getField() {
            return .getField();
        }

        
Gets the partial that this property belongs to.

Returns:
the partial
        protected ReadablePartial getReadablePartial() {
            return ;
        }

        
Gets the partial that this property belongs to.

Returns:
the partial
        public Partial getPartial() {
            return ;
        }

        
Gets the value of this field.

Returns:
the field value
        public int get() {
            return .getValue();
        }
        //-----------------------------------------------------------------------
        
Adds to the value of this field in a copy of this Partial.

The value will be added to this field. If the value is too large to be added solely to this field then it will affect larger fields. Smaller fields are unaffected.

If the result would be too large, beyond the maximum year, then an IllegalArgumentException is thrown.

The Partial attached to this property is unchanged by this call. Instead, a new instance is returned.

Parameters:
valueToAdd the value to add to the field in the copy
Returns:
a copy of the Partial with the field value changed
Throws:
java.lang.IllegalArgumentException if the value isn't valid
        public Partial addToCopy(int valueToAdd) {
            int[] newValues = .getValues();
            newValues = getField().add(newValuesvalueToAdd);
            return new Partial(newValues);
        }

        
Adds to the value of this field in a copy of this Partial wrapping within this field if the maximum value is reached.

The value will be added to this field. If the value is too large to be added solely to this field then it wraps within this field. Other fields are unaffected.

For example, 2004-12-20 addWrapField one month returns 2004-01-20.

The Partial attached to this property is unchanged by this call. Instead, a new instance is returned.

Parameters:
valueToAdd the value to add to the field in the copy
Returns:
a copy of the Partial with the field value changed
Throws:
java.lang.IllegalArgumentException if the value isn't valid
        public Partial addWrapFieldToCopy(int valueToAdd) {
            int[] newValues = .getValues();
            newValues = getField().addWrapField(newValuesvalueToAdd);
            return new Partial(newValues);
        }
        //-----------------------------------------------------------------------
        
Sets this field in a copy of the Partial.

The Partial attached to this property is unchanged by this call. Instead, a new instance is returned.

Parameters:
value the value to set the field in the copy to
Returns:
a copy of the Partial with the field value changed
Throws:
java.lang.IllegalArgumentException if the value isn't valid
        public Partial setCopy(int value) {
            int[] newValues = .getValues();
            newValues = getField().set(newValuesvalue);
            return new Partial(newValues);
        }

        
Sets this field in a copy of the Partial to a parsed text value.

The Partial attached to this property is unchanged by this call. Instead, a new instance is returned.

Parameters:
text the text value to set
locale optional locale to use for selecting a text symbol
Returns:
a copy of the Partial with the field value changed
Throws:
java.lang.IllegalArgumentException if the text value isn't valid
        public Partial setCopy(String textLocale locale) {
            int[] newValues = .getValues();
            newValues = getField().set(newValuestextlocale);
            return new Partial(newValues);
        }

        
Sets this field in a copy of the Partial to a parsed text value.

The Partial attached to this property is unchanged by this call. Instead, a new instance is returned.

Parameters:
text the text value to set
Returns:
a copy of the Partial with the field value changed
Throws:
java.lang.IllegalArgumentException if the text value isn't valid
        public Partial setCopy(String text) {
            return setCopy(textnull);
        }
        //-----------------------------------------------------------------------
        
Returns a new Partial with this field set to the maximum value for this field.

The Partial attached to this property is unchanged by this call.

Returns:
a copy of the Partial with this field set to its maximum
Since:
1.2
        public Partial withMaximumValue() {
            return setCopy(getMaximumValue());
        }

        
Returns a new Partial with this field set to the minimum value for this field.

The Partial attached to this property is unchanged by this call.

Returns:
a copy of the Partial with this field set to its minimum
Since:
1.2
        public Partial withMinimumValue() {
            return setCopy(getMinimumValue());
        }
    }
New to GrepCode? Check out our FAQ X