Skip to content

Commit

Permalink
Convert types to sealed classes where possible
Browse files Browse the repository at this point in the history
Convert DecimalType, TimeWithTimeZoneType, and TimestampWithTimeZoneType
to sealed classes
  • Loading branch information
dain committed Oct 11, 2022
1 parent 3cc0058 commit a6744ae
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import static io.trino.spi.type.TypeSignatureParameter.numericParameter;
import static java.lang.String.format;

public abstract class DecimalType
public abstract sealed class DecimalType
extends AbstractType
implements FixedWidthType
permits LongDecimalType, ShortDecimalType
{
public static final int DEFAULT_SCALE = 0;
public static final int DEFAULT_PRECISION = MAX_PRECISION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static java.lang.String.format;
import static java.lang.invoke.MethodHandles.lookup;

class LongTimeWithTimeZoneType
final class LongTimeWithTimeZoneType
extends TimeWithTimeZoneType
{
private static final TypeOperatorDeclaration TYPE_OPERATOR_DECLARATION = extractOperatorDeclaration(LongTimeWithTimeZoneType.class, lookup(), LongTimeWithTimeZone.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* in the first long and the fractional increment in the remaining integer, as a number of picoseconds
* additional to the epoch millisecond.
*/
class LongTimestampWithTimeZoneType
final class LongTimestampWithTimeZoneType
extends TimestampWithTimeZoneType
{
private static final TypeOperatorDeclaration TYPE_OPERATOR_DECLARATION = extractOperatorDeclaration(LongTimestampWithTimeZoneType.class, lookup(), LongTimestampWithTimeZone.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/**
* Encodes time with time zone up to p = 9.
*/
class ShortTimeWithTimeZoneType
final class ShortTimeWithTimeZoneType
extends TimeWithTimeZoneType
{
private static final TypeOperatorDeclaration TYPE_OPERATOR_DECLARATION = extractOperatorDeclaration(ShortTimeWithTimeZoneType.class, lookup(), long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* <p>
* The value is encoded as milliseconds from the 1970-01-01 00:00:00 epoch.
*/
class ShortTimestampWithTimeZoneType
final class ShortTimestampWithTimeZoneType
extends TimestampWithTimeZoneType
{
private static final TypeOperatorDeclaration TYPE_OPERATOR_DECLARATION = extractOperatorDeclaration(ShortTimestampWithTimeZoneType.class, lookup(), long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import static io.trino.spi.StandardErrorCode.NUMERIC_VALUE_OUT_OF_RANGE;
import static java.lang.String.format;

public abstract class TimeWithTimeZoneType
public abstract sealed class TimeWithTimeZoneType
extends AbstractType
implements FixedWidthType
permits LongTimeWithTimeZoneType, ShortTimeWithTimeZoneType
{
public static final int MAX_PRECISION = 12;
public static final int MAX_SHORT_PRECISION = 9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
* @see ShortTimestampWithTimeZoneType
* @see LongTimestampWithTimeZoneType
*/
public abstract class TimestampWithTimeZoneType
public abstract sealed class TimestampWithTimeZoneType
extends AbstractType
implements FixedWidthType
permits LongTimestampWithTimeZoneType, ShortTimestampWithTimeZoneType
{
public static final int MAX_PRECISION = 12;

Expand Down

0 comments on commit a6744ae

Please sign in to comment.