Class ASN1Time
-
- All Implemented Interfaces:
DataObject
,FastSerializable
,Serializable
public final class ASN1Time extends AbstractFieldsObject implements FastSerializable
Common representation for the ASN.1 types GeneralizedTime and UTCTime in APIs generated by the ASN.1 code generation framework.The API offered by this class is as if the type were specified in ASN.1 as follows.
ASN1Time ::= SEQUENCE { isUTCTime BOOLEAN DEFAULT FALSE, year INTEGER DEFAULT 0, month INTEGER DEFAULT 0, day INTEGER DEFAULT 0, hour INTEGER DEFAULT 0, minute INTEGER DEFAULT 0, second INTEGER DEFAULT 0, minuteDifferential INTEGER DEFAULT 0, milliSecond INTEGER DEFAULT 0 }
Default values are provided so that times of various precisions can be represented without needing to set values for irrelevant fields. Note that the isUTCTime field corresponds to the ASN.1 type being represented, not to whether the time is written textually in UTC - that's represented by minuteDifferential.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.opencloud.util.AbstractFieldsObject
FIELD_ABSENT, FIELD_UNINITIALISED
-
-
Constructor Summary
Constructors Constructor Description ASN1Time()
Constructs a new ASN1Time object with no fields set.ASN1Time(DataInput in)
Constructs a new ASN1Time object from data deserialized from a stream that was written bytoStream(DataOutput)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkFieldsSet()
Checks that all mandatory fields are present.ASN1Time
clone()
Constructs a copy of this object and everything reachable from it.static ASN1Time
copyOf(ASN1Time 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.boolean
equals(Object o)
Compares some other Object to this one for equality by value (not reference).static ASN1Time
fromCalendar(Calendar calendar)
Converts the given Calendar to a new object of this type.int
getDay()
Gets the value of the field Day.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 field Hour.boolean
getIsUTCTime()
Gets whether the time is a UTC time.int
getMilliSecond()
Gets the value of the field MilliSecond.int
getMinute()
Gets the value of the field Minute.int
getMinuteDifferential()
Gets the value of the field MinuteDifferential.int
getMonth()
Gets the value of the field Month.int
getSecond()
Gets the value of the field Second.int
getYear()
Gets the value of the field Year.boolean
hasDay()
Tests whether the field Day has a value.int
hashCode()
Returns a hash code value for this object.boolean
hasHour()
Tests whether the field Hour has a value.boolean
hasIsUTCTime()
Tests whether the field IsUTCTime has a value.boolean
hasMilliSecond()
Tests whether the field MilliSecond has a value.boolean
hasMinute()
Tests whether the field Minute has a value.boolean
hasMinuteDifferential()
Tests whether the field MinuteDifferential has a value.boolean
hasMonth()
Tests whether the field Month has a value.boolean
hasSecond()
Tests whether the field Second has a value.boolean
hasYear()
Tests whether the field Year has a value.int[]
intArrayValue()
Gets this time as an array of year,month,day,hour,minute,second,[any minute differential,]millisecond.ASN1Time
setDay(int value)
Sets the value of the field Day.ASN1Time
setDayPresent(boolean flag)
Sets the presence or absence of the field Day.ASN1Time
setHour(int value)
Sets the value of the field Hour.ASN1Time
setHourPresent(boolean flag)
Sets the presence or absence of the field Hour.ASN1Time
setIsUTCTime(boolean value)
Sets whether the time is a UTC time.ASN1Time
setIsUTCTimePresent(boolean flag)
Sets the presence or absence of the field IsUTCTime.ASN1Time
setMilliSecond(int value)
Sets the value of the field millisecond.ASN1Time
setMilliSecondPresent(boolean flag)
Sets the presence or absence of the field MilliSecond.ASN1Time
setMinute(int value)
Sets the value of the field Minute.ASN1Time
setMinuteDifferential(int value)
Sets the value of the field Minute differential.ASN1Time
setMinuteDifferentialPresent(boolean flag)
Sets the presence or absence of the field MinuteDifferential.ASN1Time
setMinutePresent(boolean flag)
Sets the presence or absence of the field Minute.ASN1Time
setMonth(int value)
Sets the value of the field Month.ASN1Time
setMonthPresent(boolean flag)
Sets the presence or absence of the field Month.ASN1Time
setSecond(int value)
Sets the value of the field Second.ASN1Time
setSecondPresent(boolean flag)
Sets the presence or absence of the field Second.ASN1Time
setValue(int[] components)
Sets this time according to an array of year,month,day,hour,minute,second,[any minute differential,]millisecond.ASN1Time
setYear(int value)
Sets the value of the field Year.ASN1Time
setYearPresent(boolean flag)
Sets the presence or absence of the field Year.Calendar
toCalendar()
Gets this time as a Calendar instanceDate
toDate()
Gets this time as a Date instancevoid
toStream(DataOutput out)
Serializes this object to a stream in a form suitable for reading byASN1Time(DataInput)
.String
toString()
Stringize this AbstractFieldsObject to ASN.1 value notation.-
Methods inherited from class com.opencloud.util.AbstractDataObject
checkModify, isReadOnly, setReadOnly
-
-
-
-
Constructor Detail
-
ASN1Time
public ASN1Time()
Constructs a new ASN1Time object with no fields set.
-
ASN1Time
public ASN1Time(DataInput in) throws IOException
Constructs a new ASN1Time object from data deserialized from a stream that was written bytoStream(DataOutput)
.- Parameters:
in
- the stream to read from- Throws:
EOFException
- if reading is pre-empted by end-of-fileIOException
- if the data cannot be read
-
-
Method Detail
-
toStream
public void toStream(DataOutput out) throws IOException
Serializes this object to a stream in a form suitable for reading byASN1Time(DataInput)
.- Specified by:
toStream
in interfaceFastSerializable
- Parameters:
out
- the stream to write to- Throws:
IOException
- if an I/O error occurs
-
hasIsUTCTime
public boolean hasIsUTCTime()
Tests whether the field IsUTCTime has a value.- Returns:
- whether the field has a value
-
setIsUTCTimePresent
public ASN1Time setIsUTCTimePresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field IsUTCTime.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasYear
public boolean hasYear()
Tests whether the field Year has a value.- Returns:
- whether the field has a value
-
setYearPresent
public ASN1Time setYearPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Year.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasMonth
public boolean hasMonth()
Tests whether the field Month has a value.- Returns:
- whether the field has a value
-
setMonthPresent
public ASN1Time setMonthPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Month.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasDay
public boolean hasDay()
Tests whether the field Day has a value.- Returns:
- whether the field has a value
-
setDayPresent
public ASN1Time setDayPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Day.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasHour
public boolean hasHour()
Tests whether the field Hour has a value.- Returns:
- whether the field has a value
-
setHourPresent
public ASN1Time setHourPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Hour.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasMinute
public boolean hasMinute()
Tests whether the field Minute has a value.- Returns:
- whether the field has a value
-
setMinutePresent
public ASN1Time setMinutePresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Minute.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasSecond
public boolean hasSecond()
Tests whether the field Second has a value.- Returns:
- whether the field has a value
-
setSecondPresent
public ASN1Time setSecondPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Second.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasMinuteDifferential
public boolean hasMinuteDifferential()
Tests whether the field MinuteDifferential has a value.- Returns:
- whether the field has a value
-
setMinuteDifferentialPresent
public ASN1Time setMinuteDifferentialPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field MinuteDifferential.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasMilliSecond
public boolean hasMilliSecond()
Tests whether the field MilliSecond has a value.- Returns:
- whether the field has a value
-
setMilliSecondPresent
public ASN1Time setMilliSecondPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field MilliSecond.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
checkFieldsSet
public void checkFieldsSet() throws EncodeException
Checks that all mandatory fields are present. This is a no-op, as all fields have default values.- Throws:
EncodeException
- if any mandatory field is not present
-
getIsUTCTime
public boolean getIsUTCTime()
Gets whether the time is a UTC time.- Returns:
- boolean representation of the field
-
getYear
public int getYear()
Gets the value of the field Year.- Returns:
- int representation of the field
-
getMonth
public int getMonth()
Gets the value of the field Month.- Returns:
- int representation of the field
-
getDay
public int getDay()
Gets the value of the field Day.- Returns:
- int representation of the field
-
getHour
public int getHour()
Gets the value of the field Hour.- Returns:
- int representation of the field
-
getMinute
public int getMinute()
Gets the value of the field Minute.- Returns:
- int representation of the field
-
getSecond
public int getSecond()
Gets the value of the field Second.- Returns:
- int representation of the field
-
getMinuteDifferential
public int getMinuteDifferential()
Gets the value of the field MinuteDifferential.- Returns:
- int representation of the field
-
getMilliSecond
public int getMilliSecond()
Gets the value of the field MilliSecond.- Returns:
- int representation of the field
-
setIsUTCTime
public ASN1Time setIsUTCTime(boolean value)
Sets whether the time is a UTC time.- Parameters:
value
- boolean- Returns:
- this
-
setYear
public ASN1Time setYear(int value)
Sets the value of the field Year.- Parameters:
value
- int representation of the field- Returns:
- this
-
setMonth
public ASN1Time setMonth(int value)
Sets the value of the field Month.- Parameters:
value
- int representation of the field- Returns:
- this
-
setDay
public ASN1Time setDay(int value)
Sets the value of the field Day.- Parameters:
value
- int representation of the field- Returns:
- this
-
setHour
public ASN1Time setHour(int value)
Sets the value of the field Hour.- Parameters:
value
- int representation of the field- Returns:
- this
-
setMinute
public ASN1Time setMinute(int value)
Sets the value of the field Minute.- Parameters:
value
- int representation of the field- Returns:
- this
-
setSecond
public ASN1Time setSecond(int value)
Sets the value of the field Second.- Parameters:
value
- int representation of the field- Returns:
- this
-
setMinuteDifferential
public ASN1Time setMinuteDifferential(int value)
Sets the value of the field Minute differential.- Parameters:
value
- int representation of the field- Returns:
- this
-
setMilliSecond
public ASN1Time setMilliSecond(int value)
Sets the value of the field millisecond.- Parameters:
value
- int representation of the field- Returns:
- this
-
copyOf
public static ASN1Time copyOf(ASN1Time 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.- Parameters:
from
- the object from which to copy- Returns:
- ASN1Time
-
clone
public ASN1Time clone()
Constructs a copy of this object and everything reachable from it.- Specified by:
clone
in interfaceDataObject
- Specified by:
clone
in classAbstractDataObject
- Returns:
- copy of object
-
getFieldAccessors
public static FieldAccessor[] getFieldAccessors()
Gets a new array of the accessors for fields of this type.- Returns:
- FieldAccessor[]
-
getFieldsMap
public Map<String,Object> getFieldsMap(boolean withAbsents)
Gets a Map from field-name to field-value for the fields of a sequence. For a field of primitive type, the field-value is boxed. For an absent optional field, the field-value is AbstractFieldsObject.FIELD_ABSENT. For an uninitialised mandatory field, the field-value is AbstractFieldsObject.FIELD_UNINITIALISED. For a field of String type, the encoded form is used if the String cannot be decoded. For a type that represents an OCTET STRING that cannot be decoded, a map from "encodedValue" to the byte array value is returned.- Specified by:
getFieldsMap
in classAbstractFieldsObject
- Parameters:
withAbsents
- whether to put absent optional fields into Map- Returns:
- Map from field-name to field-value
-
intArrayValue
public int[] intArrayValue()
Gets this time as an array of year,month,day,hour,minute,second,[any minute differential,]millisecond.- Returns:
- int array
-
setValue
public ASN1Time setValue(int[] components)
Sets this time according to an array of year,month,day,hour,minute,second,[any minute differential,]millisecond.- Parameters:
components
- int array- Returns:
- this
-
toCalendar
public Calendar toCalendar()
Gets this time as a Calendar instance- Returns:
- Calendar
-
toDate
public Date toDate()
Gets this time as a Date instance- Returns:
- Date
-
toString
public String toString()
Description copied from class:AbstractFieldsObject
Stringize this AbstractFieldsObject to ASN.1 value notation. If a SEQUENCE, then a list of comma-separated name/value pairs, surrounded by curly braces:{ field1Name field1Value, field2Name field2Value, ...., fieldNName fieldNValue }
If a CHOICE, then a labelled value:label : value.
Field values are stringized in a form that depends on their type:
- for byte[]:
'C0FFEE'H
(ASN.1 OCTET STRING hstring syntax) - for other arrays:
{ a, b, c, d }
(ASN.1 SEQUENCE OF syntax) - for all other types: their toString() representation
Absent optional fields are not included in the stringized form.
Uninitialised mandatory fields are shown as "-- UNINITIALISED --". This includes an uninitialised choice.
- Overrides:
toString
in classAbstractFieldsObject
- Returns:
- a string representation of this instance
- for byte[]:
-
hashCode
public int hashCode()
Description copied from class:AbstractFieldsObject
Returns a hash code value for this object.- Overrides:
hashCode
in classAbstractFieldsObject
- Returns:
- hash code
-
equals
public boolean equals(Object o)
Description copied from class:AbstractFieldsObject
Compares some other Object to this one for equality by value (not reference). The objects are considered equal iff they have the same field-values, regardless of whether the objects are of the same ASN.1 type.- Overrides:
equals
in classAbstractFieldsObject
- Returns:
- whether the given Object is an AbstractFieldsObject with the same field-values
-
-