Package com.illumon.util.codec
Class LocalDateCodec
java.lang.Object
com.illumon.util.codec.LocalDateCodec
- All Implemented Interfaces:
ObjectCodec<LocalDate>,ObjectDecoder<LocalDate>
public class LocalDateCodec extends Object implements ObjectCodec<LocalDate>
LocalDate codec, with support for "full" and "compact" encodings.
The full (default) encoding is a 5-byte packed integer format that can represent the full range of dates that a
LocalDate object can hold (years -999,999,999 to 999,999,999).
The compact encoding is a 3-byte packed-integer. This format is constrained to represent dates in the range
0000-01-01 to 9999-01-01. This encoding covers the range supported by many SQL databases, so is often
a good candidate for imported data sets.
Both encodings are "nullable", indicated by setting the most significant byte to 0xFF (this can never represent a
valid value in the ranges specified for each encoding).
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocalDateCodec.Domain -
Field Summary
-
Constructor Summary
Constructors Constructor Description LocalDateCodec(String arguments) -
Method Summary
Modifier and Type Method Description LocalDatedecode(byte[] input, int offset, int length)Decode an object from an array of bytes.byte[]encode(LocalDate input)Encode the specified input as an array of bytes.intexpectedObjectWidth()What width byte array does this ObjectCodec expect to encode and decode?intgetPrecision()If applicable, the maximum encodable precision.intgetScale()If applicable, the maximum encodable scale.booleanisNullable()Does this codec support encoding of null values?
-
Constructor Details
-
Method Details
-
isNullable
public boolean isNullable()Description copied from interface:ObjectCodecDoes this codec support encoding of null values?- Specified by:
isNullablein interfaceObjectCodec<LocalDate>- Returns:
- if null values are supported
-
getPrecision
public int getPrecision()Description copied from interface:ObjectCodecIf applicable, the maximum encodable precision. If precision is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getPrecisionin interfaceObjectCodec<LocalDate>- Returns:
- the numeric precision supported by this codec
-
getScale
public int getScale()Description copied from interface:ObjectCodecIf applicable, the maximum encodable scale. If scale is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getScalein interfaceObjectCodec<LocalDate>- Returns:
- the numeric scale (digits after the decimal point) supported by this codec
-
encode
Description copied from interface:ObjectCodecEncode the specified input as an array of bytes. Note that it is up to the implementation how to encode null inputs. The use of a zero-length byte array (e.g.CollectionUtil.ZERO_LENGTH_BYTE_ARRAY) is strongly encouraged.- Specified by:
encodein interfaceObjectCodec<LocalDate>- Parameters:
input- The input object, possibly null- Returns:
- The output byte array
-
decode
Description copied from interface:ObjectDecoderDecode an object from an array of bytes.- Specified by:
decodein interfaceObjectDecoder<LocalDate>- Parameters:
input- The input byte array containing bytes to decodeoffset- The offset into the byte array to start decoding fromlength- The length of the byte array to decode from, starting at the offset- Returns:
- The output object, possibly null
-
expectedObjectWidth
public int expectedObjectWidth()Description copied from interface:ObjectDecoderWhat width byte array does this ObjectCodec expect to encode and decode?- Specified by:
expectedObjectWidthin interfaceObjectDecoder<LocalDate>- Returns:
- VARIABLE_WIDTH_SENTINEL if the codec must encode and decode variable width columns, otherwise the fixed size of byte array that must be decoded and encoded.
-