jp.bitmeister.asn1.type.builtin
Class BIT_STRING

java.lang.Object
  extended by jp.bitmeister.asn1.type.ASN1Type
      extended by jp.bitmeister.asn1.type.PrimitiveType<boolean[]>
          extended by jp.bitmeister.asn1.type.builtin.BIT_STRING
All Implemented Interfaces:
java.lang.Cloneable, Concatenatable<BIT_STRING>, SizeCountable

public class BIT_STRING
extends PrimitiveType<boolean[]>
implements Concatenatable<BIT_STRING>, SizeCountable

Represents ASN.1 'BIT STRING' type.

An instance of this class represents a 'BIT STRING' type data, and has an array of boolean value.

A sub-class of BIT_STRING can contain one or more public static final int fields which annotated as @ASN1NamedBit. Each of these fields represents an index number of a bit in a bitstring value.

Author:
WATANABE, Jun.
See Also:
ASN1NamedBit

Field Summary
 
Fields inherited from class jp.bitmeister.asn1.type.ASN1Type
stringBuilder
 
Constructor Summary
BIT_STRING()
          Instantiates an empty BIT_STRING.
BIT_STRING(boolean... array)
          Instantiates a BIT_STRING and initialize it with the array of boolean value.
BIT_STRING(int... indexes)
          Instantiates a BIT_STRING and sets true to bits which specified by the indexes.
BIT_STRING(StringItem item)
          Instantiates a BIT_STRING and initialize it with the StringItem.
 
Method Summary
<R,E extends java.lang.Throwable>
R
accept(ASN1Visitor<R,E> visitor)
          Accepts the ASN1Visitor and calls a visit method of the visitor.
 boolean bit(int index)
          Returns the value of a bit specified by the index number.
protected  boolean[] cloneValue()
          Creates and returns a copy of the value set to this data.
 void concatenate(BIT_STRING data)
          Appends the value of the data to the value of this instance.
 void contract()
          Contracts the boolean array of the value of this data to enough size to hold the last true bit.
 boolean hasNamedBits()
          Tests if the type has named bits definition.
 java.lang.String nameOfBit(int index)
          Returns the indentifier of the bit specified by the index number.
 void set(int... indexes)
          Sets true to bits specified by index numbers.
 void set(StringItem item)
          Sets the StringItem value to this data.
 int size()
          Returns the measured size of this instance.
 void unset(int... indexes)
          Sets false to bits specified by index numbers.
 boolean valueEquals(java.lang.Object other)
          Tests if the value of this ASN.1 data equals the value of the other ASN.1 data.
 
Methods inherited from class jp.bitmeister.asn1.type.PrimitiveType
clear, clone, hashCode, hasValue, set, value
 
Methods inherited from class jp.bitmeister.asn1.type.ASN1Type
equals, instantiate, matches, specification, toString, validate
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BIT_STRING

public BIT_STRING()
Instantiates an empty BIT_STRING.


BIT_STRING

public BIT_STRING(boolean... array)
Instantiates a BIT_STRING and initialize it with the array of boolean value.

Parameters:
array - The value to be assigned.

BIT_STRING

public BIT_STRING(StringItem item)
Instantiates a BIT_STRING and initialize it with the StringItem.

Parameters:
item - The value to be assigned.

BIT_STRING

public BIT_STRING(int... indexes)
Instantiates a BIT_STRING and sets true to bits which specified by the indexes.

Parameters:
indexes - Indexes of bits to be set true.
Method Detail

set

public void set(StringItem item)
Sets the StringItem value to this data.

Parameters:
item - The value to be set.

set

public void set(int... indexes)
Sets true to bits specified by index numbers. If the boolean array of the value of this data does not have enough size to hold the bit specified by the biggest index, it will be expanded automatically.

Parameters:
index - Indexes of bits to be set true.

unset

public void unset(int... indexes)
Sets false to bits specified by index numbers. If the boolean array of the value of this data does not have enough size to hold the bit specified by the biggest index, it will be expanded automatically.

Parameters:
index - Indexes of bits to be set false.

contract

public void contract()
Contracts the boolean array of the value of this data to enough size to hold the last true bit.


bit

public boolean bit(int index)
Returns the value of a bit specified by the index number.

Parameters:
index - The index number.
Returns:
The value of the bit.

hasNamedBits

public boolean hasNamedBits()
Tests if the type has named bits definition.

Returns:
true when the type has named bits.

nameOfBit

public java.lang.String nameOfBit(int index)
Returns the indentifier of the bit specified by the index number.

Parameters:
index - The index number of a bit.
Returns:
The identifier of the bit.

concatenate

public void concatenate(BIT_STRING data)
Description copied from interface: Concatenatable
Appends the value of the data to the value of this instance.

Specified by:
concatenate in interface Concatenatable<BIT_STRING>
Parameters:
data - The data that has the value to be appended. The ASN.1 type of the data shall be same as this instance.

size

public int size()
Description copied from interface: SizeCountable
Returns the measured size of this instance.

Specified by:
size in interface SizeCountable
Returns:
The size.

cloneValue

protected boolean[] cloneValue()
Description copied from class: PrimitiveType
Creates and returns a copy of the value set to this data.

Overrides:
cloneValue in class PrimitiveType<boolean[]>
Returns:
A copy of the value.

valueEquals

public boolean valueEquals(java.lang.Object other)
Description copied from class: ASN1Type
Tests if the value of this ASN.1 data equals the value of the other ASN.1 data. This method returns true when they have same value even if their types are different.

Overrides:
valueEquals in class PrimitiveType<boolean[]>
Parameters:
other - The ASN.1 data which to be compared.
Returns:
true when they have same value.

accept

public <R,E extends java.lang.Throwable> R accept(ASN1Visitor<R,E> visitor)
         throws E extends java.lang.Throwable
Description copied from class: ASN1Type
Accepts the ASN1Visitor and calls a visit method of the visitor.

Specified by:
accept in class ASN1Type
Parameters:
visitor - The visitor.
Returns:
Result.
Throws:
E - When an error occured in the visit method of the visitor.
E extends java.lang.Throwable