fromClass = conversion.getConvertedType();
switch (schema.getType()) {
- case RECORD:
- return conversion.toRecord(fromClass.cast(datum), schema, type);
- case ENUM:
- return conversion.toEnumSymbol(fromClass.cast(datum), schema, type);
- case ARRAY:
- return conversion.toArray(fromClass.cast(datum), schema, type);
- case MAP:
- return conversion.toMap(fromClass.cast(datum), schema, type);
- case FIXED:
- return conversion.toFixed(fromClass.cast(datum), schema, type);
- case STRING:
- return conversion.toCharSequence(fromClass.cast(datum), schema, type);
- case BYTES:
- return conversion.toBytes(fromClass.cast(datum), schema, type);
- case INT:
- return conversion.toInt(fromClass.cast(datum), schema, type);
- case LONG:
- return conversion.toLong(fromClass.cast(datum), schema, type);
- case FLOAT:
- return conversion.toFloat(fromClass.cast(datum), schema, type);
- case DOUBLE:
- return conversion.toDouble(fromClass.cast(datum), schema, type);
- case BOOLEAN:
- return conversion.toBoolean(fromClass.cast(datum), schema, type);
+ case RECORD:
+ return conversion.toRecord(fromClass.cast(datum), schema, type);
+ case ENUM:
+ return conversion.toEnumSymbol(fromClass.cast(datum), schema, type);
+ case ARRAY:
+ return conversion.toArray(fromClass.cast(datum), schema, type);
+ case MAP:
+ return conversion.toMap(fromClass.cast(datum), schema, type);
+ case FIXED:
+ return conversion.toFixed(fromClass.cast(datum), schema, type);
+ case STRING:
+ return conversion.toCharSequence(fromClass.cast(datum), schema, type);
+ case BYTES:
+ return conversion.toBytes(fromClass.cast(datum), schema, type);
+ case INT:
+ return conversion.toInt(fromClass.cast(datum), schema, type);
+ case LONG:
+ return conversion.toLong(fromClass.cast(datum), schema, type);
+ case FLOAT:
+ return conversion.toFloat(fromClass.cast(datum), schema, type);
+ case DOUBLE:
+ return conversion.toDouble(fromClass.cast(datum), schema, type);
+ case BOOLEAN:
+ return conversion.toBoolean(fromClass.cast(datum), schema, type);
}
return datum;
} catch (ClassCastException e) {
throw new AvroRuntimeException(
- "Cannot convert " + datum + ':' + datum.getClass().getSimpleName() + ": expected logical type", e);
+ "Cannot convert " + datum + ':' + datum.getClass().getSimpleName() + ": expected logical type", e);
}
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
index fe45cbe204e..4292756a2d2 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java
@@ -271,7 +271,9 @@ public void validate(Schema schema) {
}
}
- /** Duration represents a duration, consisting on months, days and milliseconds */
+ /**
+ * Duration represents a duration, consisting on months, days and milliseconds
+ */
public static class Duration extends LogicalType {
private Duration() {
super(DURATION);
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java b/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
index 2e4b05db6e8..0f656f2b4df 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
@@ -39,54 +39,71 @@
import static java.util.Objects.requireNonNull;
/**
- * A temporal amount to model an
- * {@link org.apache.avro.LogicalTypes.Duration Avro duration} (the logical type).
+ *
+ * A temporal amount to model an {@link org.apache.avro.LogicalTypes.Duration
+ * Avro duration} (the logical type).
*
*
- * It consists of a number of months, days and milliseconds, all modelled as an
- * unsigned integer.
+ *
+ * It consists of a number of months, days and milliseconds, all modelled as an
+ * unsigned integer.
+ *
*
- * Compared to {@link Period java.time.Period}, this class has a smaller range
- * ('only' supporting a little less than 358 million years), and cannot support negative time periods.
+ *
+ * Compared to {@link Period java.time.Period}, this class has a smaller range
+ * ('only' supporting a little less than 358 million years), and cannot support
+ * negative time periods.
+ *
*
- * Compared to {@link Duration java.time.Duration}, this class has less
- * precision (milliseconds compared to nanoseconds), cannot support negative durations, and has a much smaller range.
- * Where {@code java.time.Duration} supports fixed ranges up to about 68 years, {@code TimePeriod} can only handle about
- * 49 days.
+ *
+ * Compared to {@link Duration java.time.Duration}, this class has less
+ * precision (milliseconds compared to nanoseconds), cannot support negative
+ * durations, and has a much smaller range. Where {@code java.time.Duration}
+ * supports fixed ranges up to about 68 years, {@code TimePeriod} can only
+ * handle about 49 days.
+ *
*
- * Given the time span of what we do,
- * supporting a little less than 358 million years), and cannot support negative time periods.
+ *
+ * Given the time span of what we do,
+ *
+ * supporting a little less than 358 million years), and cannot support negative
+ * time periods.
+ *
*
- * Comparison with the regular {@code java.time} classes:
+ *
+ * Comparison with the regular {@code java.time} classes:
+ *
*
*
- *
- * |
- * TimePeriod |
- * {@link Period} |
- * {@link Duration} |
- *
- *
- * | Precision |
- * milliseconds |
- * days |
- * nanoseconds |
- *
- *
- * | Time range (approx.) |
- * 0 - 49 days |
- * unsupported |
- * -68 - 68 years |
- *
- *
- * | Date range (approx.) |
- * 0 to 370 million years |
- * -2.3 to 2.3 billion years |
- * unsupported |
- *
+ *
+ * |
+ * TimePeriod |
+ * {@link Period} |
+ * {@link Duration} |
+ *
+ *
+ * | Precision |
+ * milliseconds |
+ * days |
+ * nanoseconds |
+ *
+ *
+ * | Time range (approx.) |
+ * 0 - 49 days |
+ * unsupported |
+ * -68 - 68 years |
+ *
+ *
+ * | Date range (approx.) |
+ * 0 to 370 million years |
+ * -2.3 to 2.3 billion years |
+ * unsupported |
+ *
*
*
- * @see Avro 1.11 specification on duration
+ * @see Avro 1.11
+ * specification on duration
*/
public final class TimePeriod implements TemporalAmount, Serializable {
private static final long MAX_UNSIGNED_INT = 0xffffffffL;
@@ -106,7 +123,8 @@ public final class TimePeriod implements TemporalAmount, Serializable {
private final long millis;
/**
- * Create a TimePeriod from another TemporalAmount, such as a {@link Period} or a {@link Duration}.
+ * Create a TimePeriod from another TemporalAmount, such as a {@link Period} or
+ * a {@link Duration}.
*
* @param amount a temporal amount
* @return the corresponding TimePeriod
@@ -197,7 +215,8 @@ public static TimePeriod from(TemporalAmount amount) {
* @param days a number of days
* @param millis a number of milliseconds
* @return the corresponding TimePeriod
- * @throws ArithmeticException if any of the parameters does not fit an unsigned long (0..4294967296)
+ * @throws ArithmeticException if any of the parameters does not fit an unsigned
+ * long (0..4294967296)
*/
public static TimePeriod of(long months, long days, long millis) {
return new TimePeriod(unsignedInt(months), unsignedInt(days), unsignedInt(millis));
@@ -230,8 +249,7 @@ public Period toPeriod() {
int monthsAsInt = (int) (months % MONTHS_PER_YEAR);
int daysAsInt = (int) days;
if (days != daysAsInt) {
- throw new DateTimeException(
- "Too many days: a Period can contain at most " + Integer.MAX_VALUE + " days.");
+ throw new DateTimeException("Too many days: a Period can contain at most " + Integer.MAX_VALUE + " days.");
}
return Period.ofYears(yearsAsInt).withMonths(monthsAsInt).withDays(daysAsInt);
}
@@ -239,7 +257,8 @@ public Period toPeriod() {
}
/**
- * Determines if the TimePeriod is date based (i.e., if its milliseconds component is 0).
+ * Determines if the TimePeriod is date based (i.e., if its milliseconds
+ * component is 0).
*
* @return {@code true} iff the TimePeriod is date based
*/
@@ -248,7 +267,8 @@ public boolean isDateBased() {
}
/**
- * Determines if the TimePeriod is time based (i.e., if its months and days components are 0).
+ * Determines if the TimePeriod is time based (i.e., if its months and days
+ * components are 0).
*
* @return {@code true} iff the TimePeriod is time based
*/
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java b/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
index fae51c9bf7c..4476ac7db2c 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
@@ -64,13 +64,13 @@ void invalidLogicalTypeIgnored() {
void decimalWithNonByteArrayTypes() {
final LogicalType decimal = LogicalTypes.decimal(5, 2);
// test simple types
- Schema[] nonBytes = new Schema[]{Schema.createRecord("Record", null, null, false),
+ Schema[] nonBytes = new Schema[] { Schema.createRecord("Record", null, null, false),
Schema.createArray(Schema.create(Schema.Type.BYTES)), Schema.createMap(Schema.create(Schema.Type.BYTES)),
Schema.createEnum("Enum", null, null, Arrays.asList("a", "b")),
Schema.createUnion(Arrays.asList(Schema.create(Schema.Type.BYTES), Schema.createFixed("fixed", null, null, 4))),
Schema.create(Schema.Type.BOOLEAN), Schema.create(Schema.Type.INT), Schema.create(Schema.Type.LONG),
Schema.create(Schema.Type.FLOAT), Schema.create(Schema.Type.DOUBLE), Schema.create(Schema.Type.NULL),
- Schema.create(Schema.Type.STRING)};
+ Schema.create(Schema.Type.STRING) };
for (final Schema schema : nonBytes) {
assertThrows("Should reject type: " + schema.getType(), IllegalArgumentException.class,
"Logical type decimal must be backed by fixed or bytes", () -> {
@@ -337,11 +337,12 @@ public static void assertEqualsFalse(String message, Object o1, Object o2) {
*
* @param message A String message to describe this assertion
* @param expected An Exception class that the Runnable should throw
- * @param containedInMessage A String that should be contained by the thrown exception's message
+ * @param containedInMessage A String that should be contained by the thrown
+ * exception's message
* @param callable A Callable that is expected to throw the exception
*/
public static void assertThrows(String message, Class extends Exception> expected, String containedInMessage,
- Callable> callable) {
+ Callable> callable) {
try {
callable.call();
fail("No exception was thrown (" + message + "), expected: " + expected.getName());
diff --git a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
index 9cc3589c6fa..6df4a8af6a2 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/generic/TestGenericLogicalTypes.java
@@ -132,20 +132,22 @@ public void readWriteDuration() throws IOException {
Random rng = new Random();
TimePeriod d1 = TimePeriod.of(rng.nextInt(1000), rng.nextInt(1000), rng.nextInt(1000));
- ByteBuffer b1 = ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN)
- .putInt((int) d1.getMonths()).putInt((int) d1.getDays()).putInt((int) d1.getMillis());
+ ByteBuffer b1 = ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN).putInt((int) d1.getMonths())
+ .putInt((int) d1.getDays()).putInt((int) d1.getMillis());
GenericFixed f1 = new GenericData.Fixed(fixedSchema, b1.array());
TimePeriod d2 = TimePeriod.of(rng.nextInt(1000), rng.nextInt(1000), rng.nextInt(1000));
- ByteBuffer b2 = ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN)
- .putInt((int) d2.getMonths()).putInt((int) d2.getDays()).putInt((int) d2.getMillis());
+ ByteBuffer b2 = ByteBuffer.allocate(12).order(ByteOrder.LITTLE_ENDIAN).putInt((int) d2.getMonths())
+ .putInt((int) d2.getDays()).putInt((int) d2.getMillis());
GenericFixed f2 = new GenericData.Fixed(fixedSchema, b2.array());
File test = write(fixedSchema, f1, f2);
- assertEquals(Arrays.asList(d1, d2), read(GENERIC.createDatumReader(durationSchema), test), "Should convert fixed bytes to durations");
+ assertEquals(Arrays.asList(d1, d2), read(GENERIC.createDatumReader(durationSchema), test),
+ "Should convert fixed bytes to durations");
test = write(GENERIC, durationSchema, d2, d1);
- assertEquals(Arrays.asList(f2, f1), read(GenericData.get().createDatumReader(fixedSchema), test), "Should convert durations to fixed bytes");
+ assertEquals(Arrays.asList(f2, f1), read(GenericData.get().createDatumReader(fixedSchema), test),
+ "Should convert durations to fixed bytes");
}
@Test
diff --git a/lang/java/avro/src/test/java/org/apache/avro/util/TimePeriodTest.java b/lang/java/avro/src/test/java/org/apache/avro/util/TimePeriodTest.java
index eac67652c7f..cd9809be414 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/util/TimePeriodTest.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/util/TimePeriodTest.java
@@ -61,7 +61,7 @@ void validateConstruction() {
assertSame(timePeriod, TimePeriod.from(timePeriod));
assertComponents(12, 34, 56, timePeriod);
- assertComponents(14, 3, 0, TimePeriod.from(IsoChronology.INSTANCE.period(1,2,3)));
+ assertComponents(14, 3, 0, TimePeriod.from(IsoChronology.INSTANCE.period(1, 2, 3)));
assertComponents(36_000, 0, 0, TimePeriod.from(TimeAmount.of(ChronoUnit.MILLENNIA, 3)));
assertComponents(3_600, 0, 0, TimePeriod.from(TimeAmount.of(ChronoUnit.CENTURIES, 3)));
@@ -84,9 +84,10 @@ void validateConstruction() {
// Micros and nanos must be a multiple of milliseconds
assertThrows(DateTimeException.class, () -> TimePeriod.from(TimeAmount.of(ChronoUnit.MICROS, 3)));
assertThrows(DateTimeException.class, () -> TimePeriod.from(TimeAmount.of(ChronoUnit.NANOS, 3)));
- // Unsupported cases (null, non-ISO chronology, unknown temporal unit, non-ChronoUnit)
+ // Unsupported cases (null, non-ISO chronology, unknown temporal unit,
+ // non-ChronoUnit)
assertThrows(NullPointerException.class, () -> TimePeriod.from(null));
- assertThrows(DateTimeException.class, () -> TimePeriod.from(JapaneseChronology.INSTANCE.period(1,2,3)));
+ assertThrows(DateTimeException.class, () -> TimePeriod.from(JapaneseChronology.INSTANCE.period(1, 2, 3)));
assertThrows(UnsupportedTemporalTypeException.class, () -> TimePeriod.from(TimeAmount.of(ChronoUnit.ERAS, 1)));
assertThrows(UnsupportedTemporalTypeException.class, () -> TimePeriod.from(TimeAmount.of(DummyUnit.INSTANCE, 3)));
// Arguments are long, but must fit an unsigned long
@@ -96,7 +97,7 @@ void validateConstruction() {
// Odd one out: querying an unsupported temporal unit
// (assertComponents handles all valid cases)
- assertThrows(UnsupportedTemporalTypeException.class, () -> TimePeriod.of(1,1,1).get(ERAS));
+ assertThrows(UnsupportedTemporalTypeException.class, () -> TimePeriod.of(1, 1, 1).get(ERAS));
}
@Test
@@ -181,13 +182,13 @@ void checkEqualityTests() {
TimePeriod timePeriod3 = TimePeriod.of(1, 9, 9);
TimePeriod timePeriod4 = TimePeriod.of(1, 2, 9);
- //noinspection EqualsWithItself
+ // noinspection EqualsWithItself
assertEquals(timePeriod1a, timePeriod1a);
assertEquals(timePeriod1a, timePeriod1b);
assertEquals(timePeriod1a.hashCode(), timePeriod1b.hashCode());
assertNotEquals(timePeriod1a, null);
- //noinspection AssertBetweenInconvertibleTypes
+ // noinspection AssertBetweenInconvertibleTypes
assertNotEquals(timePeriod1a, "not equal");
assertNotEquals(timePeriod1a, timePeriod2);
assertNotEquals(timePeriod1a.hashCode(), timePeriod2.hashCode());
@@ -199,20 +200,20 @@ void checkEqualityTests() {
@Test
void checkStringRepresentation() {
- assertEquals("P0", TimePeriod.of(0,0,0).toString());
- assertEquals("P1Y", TimePeriod.of(12,0,0).toString());
- assertEquals("P2M", TimePeriod.of(2,0,0).toString());
- assertEquals("P3", TimePeriod.of(0,3,0).toString());
- assertEquals("P1Y2M3", TimePeriod.of(14,3,0).toString());
- assertEquals("PT04", TimePeriod.of(0,0, 14400000).toString());
- assertEquals("PT00:05", TimePeriod.of(0,0, 300000).toString());
- assertEquals("PT00:00:06", TimePeriod.of(0,0, 6000).toString());
- assertEquals("PT00:00:00.007", TimePeriod.of(0,0, 7).toString());
- assertEquals("P1Y2M3T04:05:06.007", TimePeriod.of(14,3, 14706007).toString());
+ assertEquals("P0", TimePeriod.of(0, 0, 0).toString());
+ assertEquals("P1Y", TimePeriod.of(12, 0, 0).toString());
+ assertEquals("P2M", TimePeriod.of(2, 0, 0).toString());
+ assertEquals("P3", TimePeriod.of(0, 3, 0).toString());
+ assertEquals("P1Y2M3", TimePeriod.of(14, 3, 0).toString());
+ assertEquals("PT04", TimePeriod.of(0, 0, 14400000).toString());
+ assertEquals("PT00:05", TimePeriod.of(0, 0, 300000).toString());
+ assertEquals("PT00:00:06", TimePeriod.of(0, 0, 6000).toString());
+ assertEquals("PT00:00:00.007", TimePeriod.of(0, 0, 7).toString());
+ assertEquals("P1Y2M3T04:05:06.007", TimePeriod.of(14, 3, 14706007).toString());
// Days and millis will never overflow to months/days, to respect differences
// in months and days (daylight saving).
- assertEquals("P123T1193:02:47.295", TimePeriod.of(0,123, 4294967295L).toString());
+ assertEquals("P123T1193:02:47.295", TimePeriod.of(0, 123, 4294967295L).toString());
}
private void assertComponents(long months, long days, long millis, TimePeriod timePeriod) {
@@ -271,6 +272,7 @@ public Temporal subtractFrom(Temporal temporal) {
private static class DummyUnit implements TemporalUnit {
private static final DummyUnit INSTANCE = new DummyUnit();
+
@Override
public Duration getDuration() {
return null;
From cd08aec842a4d31765c4bf017463d430ff54e046 Mon Sep 17 00:00:00 2001
From: Oscar Westra van Holthe - Kind
Date: Mon, 25 Sep 2023 16:58:41 +0200
Subject: [PATCH 5/5] AVRO-2123: Javadoc cleanup
---
.../src/main/java/org/apache/avro/util/TimePeriod.java | 7 -------
1 file changed, 7 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java b/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
index 0f656f2b4df..a1f7fa4e8b5 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/TimePeriod.java
@@ -64,13 +64,6 @@
*
*
*
- * Given the time span of what we do,
- *
- * supporting a little less than 358 million years), and cannot support negative
- * time periods.
- *
- *
- *
* Comparison with the regular {@code java.time} classes:
*
*