|
HOME | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ireasoning.protocol.snmp.SnmpOctetString com.ireasoning.protocol.snmp.SnmpBits
This class represents SMIv2 BITS
data type.
The SMIv2 BITS construct is mapped to the string-value selection type
of the SimpleSyntax choice. A BITS value is encoded as an OCTET
STRING, in which all the named bits in (the definition of) the
bitstring, commencing with the first bit and proceeding to the last
bit, are placed in bits 8 (high order bit) to 1 (low order bit) of
the first octet, followed by bits 8 to 1 of each subsequent octet in
turn, followed by as many bits as are needed of the final subsequent
octet, commencing with bit 8. Remaining bits, if any, of the final
octet are set to zero on generation and ignored on receipt.
Usage example:
SnmpBits bits = null; bits = new SnmpBits(2); bits.setValue("100011101"); //assert(p1, p2) method throws a runtime exception if p1 and p2 are not equal assert(bits.toString(), "{0, 4, 5, 6, 8}");//"1000111010000000" bits.setValue(new byte[]{(byte)1, (byte)1, (byte)0, (byte)1, (byte)1, (byte)0, (byte)1, (byte)1, (byte)1}); assert(bits.toString(), "{0, 1, 3, 4, 6, 7, 8}");//"1101101110000000" bits.set(2); bits.set(5); assert(bits.toString(), "{0, 1, 2, 3, 4, 5, 6, 7, 8}");//"1111111110000000" bits = new SnmpBits(); bits.setValue("80"); assert(bits.toString(), "{0}");//only first bit is set bits.clear();//reset all bits bits.setValue("1ABCDF2"); assert(bits.toString(), "{3, 4, 6, 8, 10, 11, 12, 13, 16, 17, 19, 20, 21, 22, 23, 26}");//"1A BC DF 20" bits.setValue(new byte[]{(byte)221, (byte)1, (byte)110, (byte)111, (byte)81, (byte)0, (byte)12, (byte)11, (byte)8}); assert(bits.toString(), "{0, 1, 3, 4, 5, 7, 15, 17, 18, 20, 21, 22, 25, 26, 28, 29, 30, 31, 33, 35, 39, 52, 53, 60, 62, 63, 68}");//"DD 01 6E 6F 51 00 0C 0B 08" bits.set(2); bits.set(12); assert(bits.toString(), "{0, 1, 2, 3, 4, 5, 7, 12, 15, 17, 18, 20, 21, 22, 25, 26, 28, 29, 30, 31, 33, 35, 39, 52, 53, 60, 62, 63, 68}");// "FD 09 6E 6F 51 00 0C 0B 08"
Field Summary | |
protected int |
_radix
Either 2 or 16 |
Fields inherited from interface com.ireasoning.protocol.snmp.SnmpDataType |
BITS, BITSTRING, COUNTER32, COUNTER64, END_OF_MIB_VIEW, END_OF_MIB_VIEW_OBJECT, GAUGE32, INTEGER, IPADDRESS, NO_SUCH_INSTANCE, NO_SUCH_INSTANCE_OBJECT, NO_SUCH_OBJECT, NO_SUCH_OBJECT_OBJECT, NULL, OCTETSTRING, OID, OPAQUE, PDU, SEQUENCE, SEQUENCEOF, serialVersionUID, TIMETICKS, UNSIGNED32, VARBIND |
Fields inherited from interface com.ireasoning.protocol.Msg |
ERROR_TYPE |
Constructor Summary | |
SnmpBits()
Default constructor, use radix 16 |
|
SnmpBits(int radix)
Constructor |
|
SnmpBits(SnmpBits o)
Makes a copy of passed in SnmpBits object |
Method Summary | |
void |
and(SnmpBits set)
Performs a logical AND of this target bit set with the argument bit set. |
void |
andNot(SnmpBits set)
Clears all of the bits in this SnmpBits whose corresponding
bit is set in the specified SnmpBits . |
int |
cardinality()
Returns the number of bits set to true in this SnmpBits . |
void |
clear()
Sets all of the bits in this SnmpBits to false . |
void |
clear(int bitIndex)
Sets the bit specified by the index to false . |
void |
clear(int fromIndex,
int toIndex)
Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to false . |
SnmpDataType |
copy()
Makes a copy of itself |
int |
encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder)
For internal use |
boolean |
equals(Object obj)
Compares this object against the specified object. |
void |
flip(int bitIndex)
Sets the bit at the specified index to to the complement of its current value. |
void |
flip(int fromIndex,
int toIndex)
Sets each bit from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the complement of its current value. |
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index. |
int |
getType()
Returns SnmpDataType.BITS (whichs is equals to SnmpDataType.OCTETSTRING) |
String |
getTypeString()
Returns "BITS" |
byte[] |
getValue()
Returns byte array representation of this object |
int |
hashCode()
Returns a hash code value for this bit set. |
boolean |
isEmpty()
Returns true if this SnmpBits contains no bits that are set
to true . |
static void |
main(String[] args)
|
void |
or(SnmpBits set)
Performs a logical OR of this bit set with the bit set argument. |
void |
set(int bitIndex)
Sets the bit at the specified index to true . |
void |
set(int bitIndex,
boolean value)
Sets the bit at the specified index to the specified value. |
void |
set(int fromIndex,
int toIndex)
Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to true . |
void |
set(int fromIndex,
int toIndex,
boolean value)
Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the specified value. |
void |
setFixedLength(int length)
Sets the fixed length. |
void |
setValue(byte[] v)
Sets a new value. |
void |
setValue(String str)
Sets a new value. |
void |
setValue(String str,
boolean useMathSetNotation)
Sets a new value |
String |
toString()
Returns a string representation. |
void |
xor(SnmpBits set)
Performs a logical XOR of this bit set with the bit set argument. |
Methods inherited from class com.ireasoning.protocol.snmp.SnmpOctetString |
convertPhysAddress, getBytes, getLength, toHexString, toPrintableString, toString, toString2 |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int _radix
Constructor Detail |
public SnmpBits()
public SnmpBits(int radix)
radix
- either 2 or 16public SnmpBits(SnmpBits o)
Method Detail |
public int getType()
getType
in interface SnmpDataType
getType
in class SnmpOctetString
public String getTypeString()
getTypeString
in interface SnmpDataType
getTypeString
in class SnmpOctetString
public byte[] getValue()
getValue
in class SnmpOctetString
public void setValue(byte[] v)
Examples:
If radix is 16:
if passed byte array is {0x80}, only the first bit is set, so toString() of this object should be
{0}. If passed byte array is {0x80, 0x80}, the 1st and the 8th bits are set, the string format of this object
is {0, 8}
setValue
in class SnmpOctetString
public void setValue(String str, boolean useMathSetNotation)
str
- new value in String formatuseMathSetNotation
- if true, the passed str
uses mathematical
notation for a set of integers, that is, something like {1, 3, 8}. Otherwise, see
setValue(String str)setValue(String str)
public void setValue(String str)
For example:
SnmpBits bits = new SnmpBits(); bits.setValue("80"); assert(bits.toString(), "{0}");//only first bit is set bits.clear();//reset all bits.setValue("1ABCDF2"); assert(bits.toString(), "{3, 4, 6, 8, 10, 11, 12, 13, 16, 17, 19, 20, 21, 22, 23, 26}");//"1A BC DF 20"
setValue(String str, boolean useMathSetNotation)
public String toString()
SnmpBits
contains a bit in the set
state, the decimal representation of that index is included in
the result. Such indices are listed in order from lowest to
highest, separated by ", " (a comma and a space) and
surrounded by braces, resulting in the usual mathematical
notation for a set of integers.
Overrides the toString
method of Object
.
Example:
SnmpBits drPepper = new SnmpBits();Now
drPepper.toString()
returns "{}
".
drPepper.set(2);Now
drPepper.toString()
returns "{2}
".
drPepper.set(4); drPepper.set(10);Now
drPepper.toString()
returns "{2, 4, 10}
".
toString
in class SnmpOctetString
public SnmpDataType copy()
SnmpDataType
copy
in interface SnmpDataType
copy
in class SnmpOctetString
public int encode(com.ireasoning.protocol.snmp.SnmpEncoder encoder) throws SnmpEncodingException
SnmpDataType
encode
in interface SnmpDataType
encode
in class SnmpOctetString
SnmpEncodingException
public void flip(int bitIndex)
bitIndex
- the index of the bit to flip.
IndexOutOfBoundsException
- if the specified index is negative.public void flip(int fromIndex, int toIndex)
fromIndex
- index of the first bit to flip.toIndex
- index after the last bit to flip.
IndexOutOfBoundsException
- if fromIndex is negative,
or toIndex is negative, or fromIndex is
larger than toIndex.public void set(int bitIndex)
true
.
bitIndex
- a bit index.
IndexOutOfBoundsException
- if the specified index is negative.public void set(int bitIndex, boolean value)
bitIndex
- a bit index.value
- a boolean value to set.
IndexOutOfBoundsException
- if the specified index is negative.public void set(int fromIndex, int toIndex)
true
.
fromIndex
- index of the first bit to be set.toIndex
- index after the last bit to be set.
IndexOutOfBoundsException
- if fromIndex is negative,
or toIndex is negative, or fromIndex is
larger than toIndex.public void set(int fromIndex, int toIndex, boolean value)
fromIndex
- index of the first bit to be set.toIndex
- index after the last bit to be setvalue
- value to set the selected bits to
IndexOutOfBoundsException
- if fromIndex is negative,
or toIndex is negative, or fromIndex is
larger than toIndex.public void clear(int bitIndex)
false
.
bitIndex
- the index of the bit to be cleared.
IndexOutOfBoundsException
- if the specified index is negative.public void clear(int fromIndex, int toIndex)
false
.
fromIndex
- index of the first bit to be cleared.toIndex
- index after the last bit to be cleared.
IndexOutOfBoundsException
- if fromIndex is negative,
or toIndex is negative, or fromIndex is
larger than toIndex.public void clear()
false
.
public boolean get(int bitIndex)
true
if the bit with the index bitIndex
is currently set in this SnmpBits
; otherwise, the result
is false
.
bitIndex
- the bit index.
IndexOutOfBoundsException
- if the specified index is negative.public boolean isEmpty()
SnmpBits
contains no bits that are set
to true
.
SnmpBits
is empty.public int cardinality()
SnmpBits
.
SnmpBits
.public void and(SnmpBits set)
true
if and only if it both initially
had the value true
and the corresponding bit in the
bit set argument also had the value true
.
set
- a bit set.public void or(SnmpBits set)
true
if and only if it either already had the
value true
or the corresponding bit in the bit set
argument has the value true
.
set
- a bit set.public void xor(SnmpBits set)
true
if and only if one of the following
statements holds:
true
, and the
corresponding bit in the argument has the value false
.
false
, and the
corresponding bit in the argument has the value true
.
set
- a bit set.public void andNot(SnmpBits set)
SnmpBits
whose corresponding
bit is set in the specified SnmpBits
.
set
- the SnmpBits
with which to mask this
SnmpBits
.public int hashCode()
SnmpBits
. The algorithm used to compute it may
be described as follows.
Suppose the bits in the SnmpBits
were to be stored
in an array of long
integers called, say,
bits
, in such a manner that bit k
is
set in the SnmpBits
(for nonnegative values of
k
) if and only if the expression
((k>>6) < bits.length) && ((bits[k>>6] & (1L << (bit & 0x3F))) != 0)is true. Then the following definition of the
hashCode
method would be a correct implementation of the actual algorithm:
public int hashCode() { long h = 1234; for (int i = bits.length; --i >= 0; ) { h ^= bits[i] * (i + 1); } return (int)((h >> 32) ^ h); }Note that the hash code values change if the set of bits is altered.
Overrides the hashCode
method of Object
.
hashCode
in interface SnmpDataType
hashCode
in class SnmpOctetString
public boolean equals(Object obj)
true
if and only if the argument is
not null
and is a Bitset
object that has
exactly the same set of bits set to true
as this bit
set. That is, for every nonnegative int
index k
,
((SnmpBits)obj).get(k) == this.get(k)must be true. The current sizes of the two bit sets are not compared.
Overrides the equals
method of Object
.
equals
in interface SnmpDataType
equals
in class SnmpOctetString
obj
- the object to compare with.
true
if the objects are the same;
false
otherwise.public void setFixedLength(int length)
For example,
bits = new SnmpBits(2); bits.setValue("00000000"); bits.setFixedLength(8);Then bits.getValue() will return a byte array with 8 elements instead of 0.
length
- the number of bitspublic static void main(String[] args)
|
HOME | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |