/** * Sets the values of all fields. * <p> * 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. * * @param values the array of values */ protected void setValues(int[] values) { getChronology().validate(this, values); System.arraycopy(values, 0, iValues, 0, iValues.length); }
/** * Sets the values of all fields. * <p> * 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. * * @param values the array of values */ protected void setValues(int[] values) { getChronology().validate(this, values); System.arraycopy(values, 0, iValues, 0, iValues.length); }
/** * Constructs a Partial with the specified field and value. * <p> * The constructor uses the specified chronology. * * @param type the single type to create the partial from, not null * @param value the value to store * @param chronology the chronology, null means ISO * @throws IllegalArgumentException if the type or value is invalid */ public Partial(DateTimeFieldType type, int value, Chronology chronology) { super(); chronology = DateTimeUtils.getChronology(chronology).withUTC(); iChronology = chronology; if (type == null) { throw new IllegalArgumentException("The field type must not be null"); } iTypes = new DateTimeFieldType[] {type}; iValues = new int[] {value}; chronology.validate(this, iValues); }
/** * Constructs a Partial with the specified field and value. * <p> * The constructor uses the specified chronology. * * @param type the single type to create the partial from, not null * @param value the value to store * @param chronology the chronology, null means ISO * @throws IllegalArgumentException if the type or value is invalid */ public Partial(DateTimeFieldType type, int value, Chronology chronology) { super(); chronology = DateTimeUtils.getChronology(chronology).withUTC(); iChronology = chronology; if (type == null) { throw new IllegalArgumentException("The field type must not be null"); } iTypes = new DateTimeFieldType[] {type}; iValues = new int[] {value}; chronology.validate(this, iValues); }
/** * Constructs a partial with specified time field values and chronology. * <p> * 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). * <p> * The array of values is assigned (not cloned) to the new instance. * * @param values the new set of values * @param chronology the chronology, null means ISOChronology in the default zone * @throws IllegalArgumentException if the values are invalid */ protected BasePartial(int[] values, Chronology chronology) { super(); chronology = DateTimeUtils.getChronology(chronology); iChronology = chronology.withUTC(); chronology.validate(this, values); iValues = values; }
/** * Gets a copy of this date with the specified field removed. * <p> * If this partial did not previously support the field, no error occurs. * * @param fieldType the field type to remove, may be null * @return 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(iTypes, 0, newTypes, 0, index); System.arraycopy(iTypes, index + 1, newTypes, index, newTypes.length - index); System.arraycopy(iValues, 0, newValues, 0, index); System.arraycopy(iValues, index + 1, newValues, index, newValues.length - index); Partial newPartial = new Partial(iChronology, newTypes, newValues); iChronology.validate(newPartial, newValues); return newPartial; } return this; }
/** * Constructs a partial with specified time field values and chronology. * <p> * 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). * <p> * The array of values is assigned (not cloned) to the new instance. * * @param values the new set of values * @param chronology the chronology, null means ISOChronology in the default zone * @throws IllegalArgumentException if the values are invalid */ protected BasePartial(int[] values, Chronology chronology) { super(); chronology = DateTimeUtils.getChronology(chronology); iChronology = chronology.withUTC(); chronology.validate(this, values); iValues = values; }
/** * Gets a copy of this date with the specified field removed. * <p> * If this partial did not previously support the field, no error occurs. * * @param fieldType the field type to remove, may be null * @return 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(iTypes, 0, newTypes, 0, index); System.arraycopy(iTypes, index + 1, newTypes, index, newTypes.length - index); System.arraycopy(iValues, 0, newValues, 0, index); System.arraycopy(iValues, index + 1, newValues, index, newValues.length - index); Partial newPartial = new Partial(iChronology, newTypes, newValues); iChronology.validate(newPartial, newValues); return newPartial; } return this; }
/** * 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. * * @param fieldSource a partial that provides access to the fields. * This partial may be incomplete and only getFieldType(int) should be used * @param object the object to convert * @param chrono the chronology to use, which is the non-null result of getChronology() * @return the array of field values that match the fieldSource, must be non-null valid * @throws ClassCastException if the object is invalid */ public int[] getPartialValues(ReadablePartial fieldSource, Object object, Chronology chrono) { ReadablePartial input = (ReadablePartial) object; int size = fieldSource.size(); int[] values = new int[size]; for (int i = 0; i < size; i++) { values[i] = input.get(fieldSource.getFieldType(i)); } chrono.validate(fieldSource, values); return values; }
/** * 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. * * @param fieldSource a partial that provides access to the fields. * This partial may be incomplete and only getFieldType(int) should be used * @param object the object to convert * @param chrono the chronology to use, which is the non-null result of getChronology() * @return the array of field values that match the fieldSource, must be non-null valid * @throws ClassCastException if the object is invalid */ public int[] getPartialValues(ReadablePartial fieldSource, Object object, Chronology chrono) { ReadablePartial input = (ReadablePartial) object; int size = fieldSource.size(); int[] values = new int[size]; for (int i = 0; i < size; i++) { values[i] = input.get(fieldSource.getFieldType(i)); } chrono.validate(fieldSource, values); return values; }
/** * Creates a new Partial instance with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as Partial * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws 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, iTypes, iValues); newChronology.validate(newPartial, iValues); return newPartial; } }
/** * Creates a new Partial instance with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as Partial * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws 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, iTypes, iValues); newChronology.validate(newPartial, iValues); return newPartial; } }
/** * Returns a copy of this time with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as TimeOfDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws IllegalArgumentException if the values are invalid for the new chronology */ public TimeOfDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { TimeOfDay newTimeOfDay = new TimeOfDay(this, newChronology); newChronology.validate(newTimeOfDay, getValues()); return newTimeOfDay; } }
/** * Returns a copy of this month-day with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as MonthDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this month-day with a different chronology, never null * @throws IllegalArgumentException if the values are invalid for the new chronology */ public MonthDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { MonthDay newMonthDay = new MonthDay(this, newChronology); newChronology.validate(newMonthDay, getValues()); return newMonthDay; } }
/** * Returns a copy of this date with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as YearMonthDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws IllegalArgumentException if the values are invalid for the new chronology */ public YearMonthDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { YearMonthDay newYearMonthDay = new YearMonthDay(this, newChronology); newChronology.validate(newYearMonthDay, getValues()); return newYearMonthDay; } }
/** * Returns a copy of this year-month with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as YearMonth * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this year-month with a different chronology, never null * @throws IllegalArgumentException if the values are invalid for the new chronology */ public YearMonth withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { YearMonth newYearMonth = new YearMonth(this, newChronology); newChronology.validate(newYearMonth, getValues()); return newYearMonth; } }
/** * Returns a copy of this month-day with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as MonthDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this month-day with a different chronology, never null * @throws IllegalArgumentException if the values are invalid for the new chronology */ public MonthDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { MonthDay newMonthDay = new MonthDay(this, newChronology); newChronology.validate(newMonthDay, getValues()); return newMonthDay; } }
/** * Returns a copy of this date with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as YearMonthDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws IllegalArgumentException if the values are invalid for the new chronology */ public YearMonthDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { YearMonthDay newYearMonthDay = new YearMonthDay(this, newChronology); newChronology.validate(newYearMonthDay, getValues()); return newYearMonthDay; } }
/** * Returns a copy of this time with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as TimeOfDay * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this datetime with a different chronology * @throws IllegalArgumentException if the values are invalid for the new chronology */ public TimeOfDay withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { TimeOfDay newTimeOfDay = new TimeOfDay(this, newChronology); newChronology.validate(newTimeOfDay, getValues()); return newTimeOfDay; } }
/** * Returns a copy of this year-month with the specified chronology. * This instance is immutable and unaffected by this method call. * <p> * This method retains the values of the fields, thus the result will * typically refer to a different instant. * <p> * The time zone of the specified chronology is ignored, as YearMonth * operates without a time zone. * * @param newChronology the new chronology, null means ISO * @return a copy of this year-month with a different chronology, never null * @throws IllegalArgumentException if the values are invalid for the new chronology */ public YearMonth withChronologyRetainFields(Chronology newChronology) { newChronology = DateTimeUtils.getChronology(newChronology); newChronology = newChronology.withUTC(); if (newChronology == getChronology()) { return this; } else { YearMonth newYearMonth = new YearMonth(this, newChronology); newChronology.validate(newYearMonth, getValues()); return newYearMonth; } }