Class StringIndicators
-
- All Implemented Interfaces:
DataObject
,FastSerializable
,Serializable
public final class StringIndicators extends AbstractLazyEncodedByteArray implements FastSerializable
Class StringIndicators represents the encoded form of a String field.The API offered by this class is as if the type were specified in ASN.1 as follows.
StringIndicators ::= SEQUENCE { odd BOOLEAN OPTIONAL, numSemiOctets INTEGER OPTIONAL }
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 - made up by OpenCloud 8 7 6 5 4 3 2 1 Octet 1 Spare Odd Octet 2 NumSemiOctets - See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.opencloud.slee.resources.cgin.AbstractLazyEncodedDataObject
isDecoded
-
Fields inherited from class com.opencloud.slee.resources.cgin.AbstractEncodedDataObject
encoded
-
Fields inherited from class com.opencloud.util.AbstractFieldsObject
FIELD_ABSENT, FIELD_UNINITIALISED
-
-
Constructor Summary
Constructors Constructor Description StringIndicators()
Constructs a new StringIndicators object with no fields set.StringIndicators(byte[] data)
Constructs a new StringIndicators object from network-encoded data.StringIndicators(byte[] data, int start, int len)
Constructs a new StringIndicators object from part of network-encoded data.StringIndicators(DataInput in)
Constructs a new StringIndicators 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.StringIndicators
clone()
Constructs a copy of this object and everything reachable from it.static StringIndicators
copyOf(StringIndicators from)
Creates a new object of this type, initialising its field values from those of the given object.protected void
decode()
Computes the decoded form of the state from the encoded form.protected void
encode()
Computes the encoded form of the state 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 offsetstart
in the givendata
.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.int
getNumSemiOctets()
Gets the value of the numSemiOctets indicator.boolean
getOdd()
Gets the value of the odd indicator.boolean
hasNumSemiOctets()
Tests whether the field NumSemiOctets has a value.boolean
hasOdd()
Tests whether the field Odd has a value.StringIndicators
setNumSemiOctets(int value)
Sets the value of the numSemiOctets indicator.StringIndicators
setNumSemiOctetsPresent(boolean flag)
Sets the presence or absence of the field NumSemiOctets.StringIndicators
setOdd(boolean value)
Sets the value of the odd indicator.StringIndicators
setOddPresent(boolean flag)
Sets the presence or absence of the field Odd.void
toStream(DataOutput out)
Serializes this object to a stream in a form suitable for reading byStringIndicators(DataInput)
.-
Methods inherited from class com.opencloud.slee.resources.cgin.AbstractLazyEncodedDataObject
checkDecode, checkModifyAndDecode
-
Methods inherited from class com.opencloud.util.AbstractFieldsObject
equals, hashCode, toString
-
Methods inherited from class com.opencloud.util.AbstractDataObject
checkModify, isReadOnly, setReadOnly
-
-
-
-
Constructor Detail
-
StringIndicators
public StringIndicators()
Constructs a new StringIndicators object with no fields set.
-
StringIndicators
public StringIndicators(byte[] data)
Constructs a new StringIndicators object from network-encoded data. The data is not decoded and might not be decodable.- Parameters:
data
- network-encoded data- Throws:
NullPointerException
- if data is null
-
StringIndicators
public StringIndicators(byte[] data, int start, int len)
Constructs a new StringIndicators object from part of network-encoded data. The part starts at indexstart
and islen
bytes long. The data is not decoded and might not be decodable.- Parameters:
data
- network-encoded datastart
- starting offset of network-encoded data in byte arraylen
- default length if not predictable- Throws:
NullPointerException
- if data is nullIllegalArgumentException
- if len is negative
-
StringIndicators
public StringIndicators(DataInput in) throws IOException
Constructs a new StringIndicators 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 byStringIndicators(DataInput)
.- Specified by:
toStream
in interfaceFastSerializable
- Parameters:
out
- the stream to write to- Throws:
IOException
- if an I/O error occurs
-
hasOdd
public boolean hasOdd() throws DecodeException
Tests whether the field Odd has a value.- Returns:
- whether the field has a value
- Throws:
DecodeException
- if encoded state cannot be decoded
-
setOddPresent
public StringIndicators setOddPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field Odd.- Parameters:
flag
- whether the field should be marked as present- Returns:
- this
- Throws:
IllegalStateException
- if this instance has been marked as read-only
-
hasNumSemiOctets
public boolean hasNumSemiOctets() throws DecodeException
Tests whether the field NumSemiOctets has a value.- Returns:
- whether the field has a value
- Throws:
DecodeException
- if encoded state cannot be decoded
-
setNumSemiOctetsPresent
public StringIndicators setNumSemiOctetsPresent(boolean flag) throws IllegalStateException
Sets the presence or absence of the field NumSemiOctets.- 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. Should be called immediately before all calls to encode().- Specified by:
checkFieldsSet
in classAbstractLazyEncodedDataObject<byte[]>
- Throws:
EncodeException
- if any mandatory field is not present
-
getOdd
public boolean getOdd() throws DecodeException
Gets the value of the odd indicator.- Returns:
- boolean representation of the odd indicator
- Throws:
DecodeException
- if encoded state cannot be decoded
-
getNumSemiOctets
public int getNumSemiOctets() throws DecodeException
Gets the value of the numSemiOctets indicator.- Returns:
- int representation of the numSemiOctets indicator
- Throws:
DecodeException
- if encoded state cannot be decoded
-
setOdd
public StringIndicators setOdd(boolean value) throws IllegalStateException
Sets the value of the odd indicator.- Parameters:
value
- boolean representation of the odd indicator- Returns:
- this
- Throws:
IllegalStateException
-
setNumSemiOctets
public StringIndicators setNumSemiOctets(int value) throws IllegalStateException
Sets the value of the numSemiOctets indicator.- Parameters:
value
- int representation of the numSemiOctets indicator- Returns:
- this
- Throws:
IllegalStateException
-
clone
public StringIndicators 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
-
copyOf
public static StringIndicators copyOf(StringIndicators from)
Creates a new object of this type, initialising its field values from those of the given object.- Parameters:
from
- the object from which to copy- Returns:
- new StringIndicators
-
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 a field of primitive type, the field-value is boxed. For a field of String type, the field-value is lax-decoded if a StringCodec is known, otherwise the encoded form is used. For an absent optional field, a mapping to AbstractFieldsObject.FIELD_ABSENT is included if requested. For an uninitialised mandatory field, a mapping to AbstractFieldsObject.FIELD_UNINITIALISED is included. If state cannot be decoded, returns a Map from "encodedValue" to byte[].- Specified by:
getFieldsMap
in classAbstractFieldsObject
- Parameters:
withAbsents
- whether to put unknown fields into Map- Returns:
- Map from field-name to field-value
-
encodedIsInvalid
protected boolean encodedIsInvalid()
Determines whether the encoded form is invalid.- Returns:
- boolean
-
getEncodedForm
public byte[] getEncodedForm() throws EncodeException
Gets the encoded form.- Returns:
- encoded form
- Throws:
EncodeException
- if encoding fails
-
getContainedLength
public static int getContainedLength(byte[] data, int start, int len)
Determines the length of the encoded value that commences at offsetstart
in the givendata
. 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.- Parameters:
data
- network-encoded datastart
- index into data where value commenceslen
- length in data to be considered- Returns:
- 2, or 0 if encoded value is not long enough
-
encode
protected void encode()
Description copied from class:AbstractLazyEncodedDataObject
Computes the encoded form of the state from the decoded form. Should check that individual field values are within appropriate ranges, and different fields have mutually consistent values, but needn't repeat the checks done by checkFieldsSet(). The computed encoded form should equal that from which the decoded form could have been calculated using decode(), i.e. encode o decode = id.- Specified by:
encode
in classAbstractLazyEncodedDataObject<byte[]>
-
decode
protected void decode()
Description copied from class:AbstractLazyEncodedDataObject
Computes the decoded form of the state from the encoded form. The computed decoded form should equal that from which the encoded form could have been calculated using encode(), i.e. decode o encode = id. If a field cannot be decoded without further information, such as a DigitCodec to be used for decoding a digit string, then the encoded form of that field should be copied and kept for decoding by that field's getter, which will be given the further information. The caller should setisDecoded
to true.- Specified by:
decode
in classAbstractLazyEncodedDataObject<byte[]>
-
-