public static ConverterManager getInstance() { if (INSTANCE == null) { INSTANCE = new ConverterManager(); } return INSTANCE; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public DurationConverter removeDurationConverter(DurationConverter converter) throws SecurityException { checkAlterDurationConverters(); if (converter == null) { return null; } DurationConverter[] removed = new DurationConverter[1]; iDurationConverters = iDurationConverters.remove(converter, removed); return removed[0]; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public InstantConverter removeInstantConverter(InstantConverter converter) throws SecurityException { checkAlterInstantConverters(); if (converter == null) { return null; } InstantConverter[] removed = new InstantConverter[1]; iInstantConverters = iInstantConverters.remove(converter, removed); return removed[0]; }
/** * Creates a duration from the specified object using the * {@link org.joda.time.convert.ConverterManager ConverterManager}. * * @param duration duration to convert * @throws IllegalArgumentException if duration is invalid */ protected BaseDuration(Object duration) { super(); DurationConverter converter = ConverterManager.getInstance().getDurationConverter(duration); iMillis = converter.getDurationMillis(duration); }
/** * Constructs an instance from an Object that represents a datetime. * <p> * The recognised object types are defined in {@link ConverterManager} and * include String, Calendar and Date. * * @param instant the datetime object, null means now * @throws IllegalArgumentException if the instant is invalid */ public Instant(Object instant) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); iMillis = converter.getInstantMillis(instant, ISOChronology.getInstanceUTC()); }
/** * Constructs a partial from an Object that represents a time, using the * specified chronology. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadableInstant, String, Calendar and Date. * <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). * * @param instant the datetime object * @param chronology the chronology, null means use converter * @throws IllegalArgumentException if the date is invalid */ protected BasePartial(Object instant, Chronology chronology) { super(); PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant); chronology = converter.getChronology(instant, chronology); chronology = DateTimeUtils.getChronology(chronology); iChronology = chronology.withUTC(); iValues = converter.getPartialValues(this, instant, chronology); }
/** * Constructs a time interval converting or copying from another object * that describes an interval. * * @param interval the time interval to copy * @param chrono the chronology to use, null means let converter decide * @throws IllegalArgumentException if the interval is invalid */ protected BaseInterval(Object interval, Chronology chrono) { super(); IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval); if (converter.isReadableInterval(interval, chrono)) { ReadableInterval input = (ReadableInterval) interval; iChronology = (chrono != null ? chrono : input.getChronology()); iStartMillis = input.getStartMillis(); iEndMillis = input.getEndMillis(); } else if (this instanceof ReadWritableInterval) { converter.setInto((ReadWritableInterval) this, interval, chrono); } else { MutableInterval mi = new MutableInterval(); converter.setInto(mi, interval, chrono); iChronology = mi.getChronology(); iStartMillis = mi.getStartMillis(); iEndMillis = mi.getEndMillis(); } checkInterval(iStartMillis, iEndMillis); }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public IntervalConverter removeIntervalConverter(IntervalConverter converter) throws SecurityException { checkAlterIntervalConverters(); if (converter == null) { return null; } IntervalConverter[] removed = new IntervalConverter[1]; iIntervalConverters = iIntervalConverters.remove(converter, removed); return removed[0]; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public PeriodConverter removePeriodConverter(PeriodConverter converter) throws SecurityException { checkAlterPeriodConverters(); if (converter == null) { return null; } PeriodConverter[] removed = new PeriodConverter[1]; iPeriodConverters = iPeriodConverters.remove(converter, removed); return removed[0]; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public PartialConverter removePartialConverter(PartialConverter converter) throws SecurityException { checkAlterPartialConverters(); if (converter == null) { return null; } PartialConverter[] removed = new PartialConverter[1]; iPartialConverters = iPartialConverters.remove(converter, removed); return removed[0]; }
/** * Creates a new period based on another using the {@link ConverterManager}. * * @param period the period to convert * @param type which set of fields this period supports, null means use type from object * @param chrono the chronology to use, null means ISO default * @throws IllegalArgumentException if period is invalid * @throws IllegalArgumentException if an unsupported field's value is non-zero */ protected BasePeriod(Object period, PeriodType type, Chronology chrono) { super(); PeriodConverter converter = ConverterManager.getInstance().getPeriodConverter(period); type = (type == null ? converter.getPeriodType(period) : type); type = checkPeriodType(type); iType = type; if (this instanceof ReadWritablePeriod) { iValues = new int[size()]; chrono = DateTimeUtils.getChronology(chrono); converter.setInto((ReadWritablePeriod) this, period, chrono); } else { iValues = new MutablePeriod(period, type, chrono).getValues(); } }
/** * Creates a duration from the specified object using the * {@link org.joda.time.convert.ConverterManager ConverterManager}. * * @param duration duration to convert * @throws IllegalArgumentException if duration is invalid */ protected BaseDuration(Object duration) { super(); DurationConverter converter = ConverterManager.getInstance().getDurationConverter(duration); iMillis = converter.getDurationMillis(duration); }
/** * Constructs an instance from an Object that represents a datetime. * <p> * The recognised object types are defined in {@link ConverterManager} and * include String, Calendar and Date. * * @param instant the datetime object, null means now * @throws IllegalArgumentException if the instant is invalid */ public Instant(Object instant) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); iMillis = converter.getInstantMillis(instant, ISOChronology.getInstanceUTC()); }
/** * Constructs a time interval converting or copying from another object * that describes an interval. * * @param interval the time interval to copy * @param chrono the chronology to use, null means let converter decide * @throws IllegalArgumentException if the interval is invalid */ protected BaseInterval(Object interval, Chronology chrono) { super(); IntervalConverter converter = ConverterManager.getInstance().getIntervalConverter(interval); if (converter.isReadableInterval(interval, chrono)) { ReadableInterval input = (ReadableInterval) interval; iChronology = (chrono != null ? chrono : input.getChronology()); iStartMillis = input.getStartMillis(); iEndMillis = input.getEndMillis(); } else if (this instanceof ReadWritableInterval) { converter.setInto((ReadWritableInterval) this, interval, chrono); } else { MutableInterval mi = new MutableInterval(); converter.setInto(mi, interval, chrono); iChronology = mi.getChronology(); iStartMillis = mi.getStartMillis(); iEndMillis = mi.getEndMillis(); } checkInterval(iStartMillis, iEndMillis); }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public IntervalConverter removeIntervalConverter(IntervalConverter converter) throws SecurityException { checkAlterIntervalConverters(); if (converter == null) { return null; } IntervalConverter[] removed = new IntervalConverter[1]; iIntervalConverters = iIntervalConverters.remove(converter, removed); return removed[0]; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public PeriodConverter removePeriodConverter(PeriodConverter converter) throws SecurityException { checkAlterPeriodConverters(); if (converter == null) { return null; } PeriodConverter[] removed = new PeriodConverter[1]; iPeriodConverters = iPeriodConverters.remove(converter, removed); return removed[0]; }
/** * Removes a converter from the set of converters. If the converter was * not in the set, no changes are made. * * @param converter the converter to remove, null ignored * @return replaced converter, or null */ public PartialConverter removePartialConverter(PartialConverter converter) throws SecurityException { checkAlterPartialConverters(); if (converter == null) { return null; } PartialConverter[] removed = new PartialConverter[1]; iPartialConverters = iPartialConverters.remove(converter, removed); return removed[0]; }
/** * Constructs an instance from an Object that represents a datetime, * using the specified chronology. * <p> * If the chronology is null, ISO in the default time zone is used. * Once the constructor is completed, the zone is no longer used. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadablePartial, ReadableInstant, String, Calendar and Date. * The String formats are described by {@link ISODateTimeFormat#localTimeParser()}. * The default String converter ignores the zone and only parses the field values. * * @param instant the datetime object * @param chronology the chronology * @throws IllegalArgumentException if the instant is invalid */ public LocalTime(Object instant, Chronology chronology) { PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant); chronology = converter.getChronology(instant, chronology); chronology = DateTimeUtils.getChronology(chronology); iChronology = chronology.withUTC(); int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localTimeParser()); iLocalMillis = iChronology.getDateTimeMillis(0L, values[0], values[1], values[2], values[3]); }
/** * Creates a duration from the specified object using the * {@link org.joda.time.convert.ConverterManager ConverterManager}. * * @param duration duration to convert * @throws IllegalArgumentException if duration is invalid */ protected BaseDuration(Object duration) { super(); DurationConverter converter = ConverterManager.getInstance().getDurationConverter(duration); iMillis = converter.getDurationMillis(duration); }
/** * Constructs an instance from an Object that represents a datetime, * using the specified chronology. * <p> * If the chronology is null, ISO in the default time zone is used. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadableInstant, String, Calendar and Date. * * @param instant the datetime object * @param chronology the chronology * @throws IllegalArgumentException if the instant is invalid */ public BaseDateTime(Object instant, Chronology chronology) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); iChronology = checkChronology(converter.getChronology(instant, chronology)); iMillis = checkInstant(converter.getInstantMillis(instant, chronology), iChronology); adjustForMinMax(); }