use of org.joda.time.ReadablePartial in project joda-time by JodaOrg.
the class TestConverterManager method testGetPartialConverterBadMultipleMatches.
public void testGetPartialConverterBadMultipleMatches() {
PartialConverter c = new PartialConverter() {
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
return null;
}
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
return null;
}
public Chronology getChronology(Object object, DateTimeZone zone) {
return null;
}
public Chronology getChronology(Object object, Chronology chrono) {
return null;
}
public Class getSupportedType() {
return Serializable.class;
}
};
try {
ConverterManager.getInstance().addPartialConverter(c);
try {
ConverterManager.getInstance().getPartialConverter(new DateTime());
fail();
} catch (IllegalStateException ex) {
// Serializable and ReadablePartial both match, so cannot pick
}
} finally {
ConverterManager.getInstance().removePartialConverter(c);
}
assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
use of org.joda.time.ReadablePartial in project joda-time by JodaOrg.
the class TestConverterManager method testGetPartialConverterOKMultipleMatches.
public void testGetPartialConverterOKMultipleMatches() {
PartialConverter c = new PartialConverter() {
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
return null;
}
public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
return null;
}
public Chronology getChronology(Object object, DateTimeZone zone) {
return null;
}
public Chronology getChronology(Object object, Chronology chrono) {
return null;
}
public Class getSupportedType() {
return ReadableDateTime.class;
}
};
try {
ConverterManager.getInstance().addPartialConverter(c);
PartialConverter ok = ConverterManager.getInstance().getPartialConverter(new DateTime());
// ReadableDateTime and ReadablePartial both match, but RI discarded as less specific
assertEquals(ReadableDateTime.class, ok.getSupportedType());
} finally {
ConverterManager.getInstance().removePartialConverter(c);
}
assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
use of org.joda.time.ReadablePartial in project joda-time by JodaOrg.
the class ReadablePartialConverter method getPartialValues.
/**
* 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;
}
Aggregations