public final class TimeAndTimezone extends AbstractLazyEncodedByteArray implements FastSerializable
The API offered by this class is as if the type were defined in ASN.1 as follows.
TimeAndTimezone ::= SEQUENCE { year INTEGER (0..9999), month INTEGER (0..99), day INTEGER (0..99), hour INTEGER (0..99), minute INTEGER (0..99), second INTEGER (0..99), timezone INTEGER (-79..79) }The class takes care of encoding the field values into a byte-array and decoding field values from a byte-array, the encoded representation being as tabulated below.
Data Encoding - based on comment in ASN.1 module CAP-datatypes | ||||||||
---|---|---|---|---|---|---|---|---|
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
Octet 0 | Year century | Year millenium | ||||||
Octet 1 | Year units | Year decade | ||||||
Octet 2 | Month units | Month tens | ||||||
Octet 3 | Day units | Day tens | ||||||
Octet 4 | Hour units | Hours tens | ||||||
Octet 5 | Minute units | Minutes tens | ||||||
Octet 6 | Seconds units | Seconds tens | ||||||
Octet 7 | Timezone units | Sign | Timezone tens |
isDecoded
encoded
FIELD_ABSENT, FIELD_UNINITIALISED
Constructor and Description |
---|
TimeAndTimezone()
Constructs a new TimeAndTimezone object with no fields set.
|
TimeAndTimezone(byte[] data)
Constructs a new TimeAndTimezone object from network-encoded data.
|
TimeAndTimezone(byte[] data,
int start,
int len)
Constructs a new TimeAndTimezone object from part of network-encoded data.
|
TimeAndTimezone(Calendar calendar)
Constructs a new TimeAndTimezone object from the given calendar.
|
TimeAndTimezone(DataInput in)
Constructs a new TimeAndTimezone object from data deserialized from a stream that was written by
toStream(DataOutput) . |
TimeAndTimezone(int year,
int month,
int day,
int hour,
int minute,
int second,
int timezone)
Constructs a new TimeAndTimezone object from given values for all fields.
|
Modifier and Type | Method and Description |
---|---|
void |
checkFieldsSet()
Checks that all mandatory fields are present.
|
TimeAndTimezone |
clone()
Constructs a copy of this object and everything reachable from it.
|
static TimeAndTimezone |
copyOf(TimeAndTimezone from)
Creates a new object of this type, cloning the values of common fields from the given object of any subclass of the same base type.
|
protected void |
decode()
Computes the decoded form from the encoded form.
|
protected void |
encode()
Computes the encoded form from the decoded form.
|
protected boolean |
encodedIsInvalid()
Determines whether the encoded form is invalid.
|
static int |
getContainedLength(byte[] data,
int start,
int len)
Determines the length of the encoded value that commences at offset
start in the given data . |
int |
getDay()
Gets the value of the day of the month, in range [0,99] (but usually [1,31]).
|
byte[] |
getEncodedForm()
Gets the encoded form.
|
static FieldAccessor[] |
getFieldAccessors()
Gets a new array of the accessors for fields of this type.
|
Map<String,Object> |
getFieldsMap(boolean withAbsents)
Gets a Map from field-name to field-value for the fields of a sequence.
|
int |
getHour()
Gets the value of the hour, in range [0,99] (but usually [0,23]).
|
int |
getMinute()
Gets the value of the minute, in range [0,99] (but usually [0,59]).
|
int |
getMonth()
Gets the value of the month, in range [0,99] (but usually [1,12]).
|
int |
getSecond()
Gets the value of the second, in range [0,99] (but usually [0,59]).
|
int |
getTimezone()
Gets the value of the timezone, in range [-79,79], as a multiple of 15 minutes difference from GMT/UTC.
|
int |
getYear()
Gets the value of the year, in range [0,9999].
|
boolean |
hasDay()
Tests whether the field Day has a value.
|
boolean |
hasHour()
Tests whether the field Hour has a value.
|
boolean |
hasMinute()
Tests whether the field Minute has a value.
|
boolean |
hasMonth()
Tests whether the field Month has a value.
|
boolean |
hasSecond()
Tests whether the field Second has a value.
|
boolean |
hasTimezone()
Tests whether the field Timezone has a value.
|
boolean |
hasYear()
Tests whether the field Year has a value.
|
TimeAndTimezone |
setDay(int value)
Sets the value of the day of the month, in range [0,99] (but usually [1,31]).
|
TimeAndTimezone |
setDayPresent(boolean flag)
Sets the presence or absence of the field Day.
|
TimeAndTimezone |
setHour(int value)
Sets the value of the hour, in range [0,99] (but usually [0,23]).
|
TimeAndTimezone |
setHourPresent(boolean flag)
Sets the presence or absence of the field Hour.
|
TimeAndTimezone |
setMinute(int value)
Sets the value of the minute, in range [0,99] (but usually [0,59]).
|
TimeAndTimezone |
setMinutePresent(boolean flag)
Sets the presence or absence of the field Minute.
|
TimeAndTimezone |
setMonth(int value)
Sets the value of the month, in range [0,99] (but usually [1,12]).
|
TimeAndTimezone |
setMonthPresent(boolean flag)
Sets the presence or absence of the field Month.
|
TimeAndTimezone |
setSecond(int value)
Sets the value of the second, in range [0,99] (but usually [0,59]).
|
TimeAndTimezone |
setSecondPresent(boolean flag)
Sets the presence or absence of the field Second.
|
TimeAndTimezone |
setTimezone(int value)
Sets the value of the timezone, in range [-79,79], as a multiple of 15 minutes difference from GMT/UTC.
|
TimeAndTimezone |
setTimezonePresent(boolean flag)
Sets the presence or absence of the field Timezone.
|
TimeAndTimezone |
setYear(int value)
Sets the value of the year, in range [0,9999].
|
TimeAndTimezone |
setYearPresent(boolean flag)
Sets the presence or absence of the field Year.
|
Calendar |
toCalendar()
Gets a Calendar representing the time in this TimeAndTimezone.
|
String |
toDateFormat()
Gets a description of the Calendar returned by
toCalendar()
in DateFormat 's FULL format. |
void |
toStream(DataOutput out)
Serializes this object to a stream in a form suitable for reading by
TimeAndTimezone(DataInput) . |
checkDecode, checkModifyAndDecode
equals, hashCode, toString
checkModify, isReadOnly, setReadOnly
public TimeAndTimezone()
public TimeAndTimezone(byte[] data)
data
- network-encoded dataNullPointerException
- if data is nullpublic TimeAndTimezone(byte[] data, int start, int len)
start
and is len
bytes long.
The data is not decoded and might not be decodable.data
- network-encoded datastart
- starting offset of network-encoded data in byte arraylen
- default length if not predictableNullPointerException
- if data is nullIllegalArgumentException
- if len is negativepublic TimeAndTimezone(int year, int month, int day, int hour, int minute, int second, int timezone)
year
- the year, in range [0,9999]month
- the month, in range [0,99] (but usually [1,12])day
- the day of the month, in range [0,99] (but usually [1,31])hour
- the hour, in range [0,99] (but usually [0,23])minute
- the minute, in range [0,99] (but usually [0,59])second
- the second, in range [0,99] (but usually [0,59])timezone
- the timezone, in range [-79,79], as a multiple of 15 minutes difference from GMT/UTCpublic TimeAndTimezone(DataInput in) throws IOException
toStream(DataOutput)
.in
- the stream to read fromEOFException
- if reading is pre-empted by end-of-fileIOException
- if the data cannot be readpublic TimeAndTimezone(Calendar calendar)
calendar
- a time represented by a CalendarIllegalArgumentException
- if the Calendar is out of range (year before 0 or after 9999)public void toStream(DataOutput out) throws IOException
TimeAndTimezone(DataInput)
.toStream
in interface FastSerializable
out
- the stream to write toIOException
- if an I/O error occurspublic boolean hasYear() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setYearPresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasMonth() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setMonthPresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasDay() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setDayPresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasHour() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setHourPresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasMinute() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setMinutePresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasSecond() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setSecondPresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic boolean hasTimezone() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setTimezonePresent(boolean flag) throws IllegalStateException
flag
- whether the field should be marked as presentIllegalStateException
- if this instance has been marked as read-onlypublic void checkFieldsSet() throws EncodeException
checkFieldsSet
in class AbstractLazyEncodedDataObject<byte[]>
EncodeException
- if any mandatory field is not presentpublic int getYear() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getMonth() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getDay() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getHour() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getMinute() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getSecond() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic int getTimezone() throws DecodeException
DecodeException
- if encoded state cannot be decodedpublic TimeAndTimezone setYear(int value) throws IllegalStateException
value
- int representation of the year, in range [0,9999]IllegalStateException
public TimeAndTimezone setMonth(int value) throws IllegalStateException
value
- int representation of the month, in range [0,99] (but usually [1,12])IllegalStateException
public TimeAndTimezone setDay(int value) throws IllegalStateException
value
- int representation of the day of the month, in range [0,99] (but usually [1,31])IllegalStateException
public TimeAndTimezone setHour(int value) throws IllegalStateException
value
- int representation of the hour, in range [0,99] (but usually [0,23])IllegalStateException
public TimeAndTimezone setMinute(int value) throws IllegalStateException
value
- int representation of the minute, in range [0,99] (but usually [0,59])IllegalStateException
public TimeAndTimezone setSecond(int value) throws IllegalStateException
value
- int representation of the second, in range [0,99] (but usually [0,59])IllegalStateException
public TimeAndTimezone setTimezone(int value) throws IllegalStateException
value
- int representation of the timezone, in range [-79,79], as a multiple of 15 minutes difference from GMT/UTCIllegalStateException
public static TimeAndTimezone copyOf(TimeAndTimezone from)
from
- the object from which to copypublic TimeAndTimezone clone()
clone
in interface DataObject
clone
in class AbstractDataObject
public static FieldAccessor[] getFieldAccessors()
public Map<String,Object> getFieldsMap(boolean withAbsents)
getFieldsMap
in class AbstractFieldsObject
withAbsents
- whether to put absent optional fields into Mapprotected boolean encodedIsInvalid()
public byte[] getEncodedForm() throws EncodeException
EncodeException
- if encoding failspublic static int getContainedLength(byte[] data, int start, int len)
start
in the given data
.
The value is not fully decoded and might not be decodable.
Values of this type are of a fixed length, so that length
is returned if the data is long enough, otherwise 0 is returned.data
- network-encoded datastart
- index into data where value commenceslen
- length in data to be consideredpublic String toDateFormat()
toCalendar()
in DateFormat
's FULL format.
The exact output varies with Locale.
It shows the timestamp in the timezone of the encoded TimeAndTimezone,
hence FULL is needed to reveal that timezone.public Calendar toCalendar()
protected void encode() throws EncodeException
encode
in class AbstractLazyEncodedDataObject<byte[]>
EncodeException
- if address cannot be encodedprotected void decode()
decode
in class AbstractLazyEncodedDataObject<byte[]>
DecodeException
- if less or more than 8 octets to be decoded, or if the contained data is badly formatted