super(); iInstantConverters = new ConverterSet(new Converter[] { ReadableInstantConverter.INSTANCE, StringConverter.INSTANCE, }); iPartialConverters = new ConverterSet(new Converter[] { ReadablePartialConverter.INSTANCE, ReadableInstantConverter.INSTANCE, }); iDurationConverters = new ConverterSet(new Converter[] { ReadableDurationConverter.INSTANCE, ReadableIntervalConverter.INSTANCE, }); iPeriodConverters = new ConverterSet(new Converter[] { ReadableDurationConverter.INSTANCE, ReadablePeriodConverter.INSTANCE, iIntervalConverters = new ConverterSet(new Converter[] { ReadableIntervalConverter.INSTANCE, StringConverter.INSTANCE,
/** * Adds a converter to the set of converters. If a matching converter is * already in the set, the given converter replaces it. If the converter is * exactly the same as one already in the set, no changes are made. * <p> * The order in which converters are added is not relevant. The best * converter is selected by examining the object hierarchy. * * @param converter the converter to add, null ignored * @return replaced converter, or null */ public DurationConverter addDurationConverter(DurationConverter converter) throws SecurityException { checkAlterDurationConverters(); if (converter == null) { return null; } DurationConverter[] removed = new DurationConverter[1]; iDurationConverters = iDurationConverters.add(converter, removed); return removed[0]; }
/** * Gets a copy of the list of converters. * * @return the converters, a copy of the real data, never null */ public PeriodConverter[] getPeriodConverters() { ConverterSet set = iPeriodConverters; PeriodConverter[] converters = new PeriodConverter[set.size()]; set.copyInto(converters); return converters; }
/** * Returns a copy of this set, with the given converter removed. If the * converter was not in the set, the original set is returned. * * @param converter converter to remove, must not be null * @param removed if not null, element 0 is set to the removed converter * @throws NullPointerException if converter is null */ ConverterSet remove(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { if (converter.equals(converters[i])) { return remove(i, removed); } } // Not found. if (removed != null) { removed[0] = null; } return this; }
/** * Gets the best converter for the object specified. * * @param object the object to convert * @return the converter to use * @throws IllegalArgumentException if no suitable converter * @throws IllegalStateException if multiple converters match the type * equally well */ public InstantConverter getInstantConverter(Object object) { InstantConverter converter = (InstantConverter)iInstantConverters.select(object == null ? null : object.getClass()); if (converter != null) { return converter; } throw new IllegalArgumentException("No instant converter found for type: " + (object == null ? "null" : object.getClass().getName())); }
/** * Gets a debug representation of the object. */ public String toString() { return "ConverterManager[" + iInstantConverters.size() + " instant," + iPartialConverters.size() + " partial," + iDurationConverters.size() + " duration," + iPeriodConverters.size() + " period," + iIntervalConverters.size() + " interval]"; }
Converter converter = selectSlow(this, type); e = new Entry(type, converter);
/** * Returns a copy of this set, with the given converter removed. If the * converter was not in the set, the original set is returned. * * @param converter converter to remove, must not be null * @param removed if not null, element 0 is set to the removed converter * @throws NullPointerException if converter is null */ ConverterSet remove(Converter converter, Converter[] removed) { Converter[] converters = iConverters; int length = converters.length; for (int i=0; i<length; i++) { if (converter.equals(converters[i])) { return remove(i, removed); } } // Not found. if (removed != null) { removed[0] = null; } return this; }
/** * Gets the best converter for the object specified. * * @param object the object to convert * @return the converter to use * @throws IllegalArgumentException if no suitable converter * @throws IllegalStateException if multiple converters match the type * equally well */ public PeriodConverter getPeriodConverter(Object object) { PeriodConverter converter = (PeriodConverter)iPeriodConverters.select(object == null ? null : object.getClass()); if (converter != null) { return converter; } throw new IllegalArgumentException("No period converter found for type: " + (object == null ? "null" : object.getClass().getName())); }
/** * Gets a debug representation of the object. */ public String toString() { return "ConverterManager[" + iInstantConverters.size() + " instant," + iPartialConverters.size() + " partial," + iDurationConverters.size() + " duration," + iPeriodConverters.size() + " period," + iIntervalConverters.size() + " interval]"; }
Converter converter = selectSlow(this, type); e = new Entry(type, converter);
/** * Gets a copy of the set of converters. * * @return the converters, a copy of the real data, never null */ public InstantConverter[] getInstantConverters() { ConverterSet set = iInstantConverters; InstantConverter[] converters = new InstantConverter[set.size()]; set.copyInto(converters); return converters; }
/** * 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]; }
/** * Adds a converter to the set of converters. If a matching converter is * already in the set, the given converter replaces it. If the converter is * exactly the same as one already in the set, no changes are made. * <p> * The order in which converters are added is not relevant. The best * converter is selected by examining the object hierarchy. * * @param converter the converter to add, null ignored * @return replaced converter, or null */ public InstantConverter addInstantConverter(InstantConverter converter) throws SecurityException { checkAlterInstantConverters(); if (converter == null) { return null; } InstantConverter[] removed = new InstantConverter[1]; iInstantConverters = iInstantConverters.add(converter, removed); return removed[0]; }
super(); iInstantConverters = new ConverterSet(new Converter[] { ReadableInstantConverter.INSTANCE, StringConverter.INSTANCE, }); iPartialConverters = new ConverterSet(new Converter[] { ReadablePartialConverter.INSTANCE, ReadableInstantConverter.INSTANCE, }); iDurationConverters = new ConverterSet(new Converter[] { ReadableDurationConverter.INSTANCE, ReadableIntervalConverter.INSTANCE, }); iPeriodConverters = new ConverterSet(new Converter[] { ReadableDurationConverter.INSTANCE, ReadablePeriodConverter.INSTANCE, iIntervalConverters = new ConverterSet(new Converter[] { ReadableIntervalConverter.INSTANCE, StringConverter.INSTANCE,
/** * Gets the best converter for the object specified. * * @param object the object to convert * @return the converter to use * @throws IllegalArgumentException if no suitable converter * @throws IllegalStateException if multiple converters match the type * equally well */ public IntervalConverter getIntervalConverter(Object object) { IntervalConverter converter = (IntervalConverter)iIntervalConverters.select(object == null ? null : object.getClass()); if (converter != null) { return converter; } throw new IllegalArgumentException("No interval converter found for type: " + (object == null ? "null" : object.getClass().getName())); }
/** * Gets a debug representation of the object. */ public String toString() { return "ConverterManager[" + iInstantConverters.size() + " instant," + iPartialConverters.size() + " partial," + iDurationConverters.size() + " duration," + iPeriodConverters.size() + " period," + iIntervalConverters.size() + " interval]"; }
Converter converter = selectSlow(this, type); e = new Entry(type, converter);
/** * Gets a copy of the list of converters. * * @return the converters, a copy of the real data, never null */ public DurationConverter[] getDurationConverters() { ConverterSet set = iDurationConverters; DurationConverter[] converters = new DurationConverter[set.size()]; set.copyInto(converters); return converters; }
/** * 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]; }