public class BitField
extends java.util.BitSet
The main purpose of this class is to provide Java representation of the
Bit Field
attribute type.
Modifier and Type | Field and Description |
---|---|
private int |
width
The "real" width of the bit field.
|
Constructor and Description |
---|
BitField(int width)
Construct a BitField of specified width with all bits set
to
false . |
Modifier and Type | Method and Description |
---|---|
void |
and(java.util.BitSet set)
Performs a logical AND of this bit field with the argument bit set.
|
void |
andNot(java.util.BitSet set)
Clears all of the bits whose corresponding bit is set in the specified
BitSet.
|
private void |
checkBitSet(java.util.BitSet set)
Check specified BitSet is narrow enough to be used for operation.
|
private void |
checkIndex(int index)
Check specified index to fit into range.
|
void |
clear(int index)
Set specified bit into
false . |
void |
clear(int from,
int to)
Set specified range of bits into
false . |
void |
flip(int index)
Set specified bit into opposite value.
|
void |
flip(int from,
int to)
Set specified range of bits into opposite value.
|
boolean |
get(int index)
Get value of the specified bit.
|
void |
or(java.util.BitSet set)
Performs a logical OR of this bit field with the argument bit set.
|
void |
set(int index)
Set specified bit into
true . |
void |
set(int index,
boolean val)
Set specified bit into specified value.
|
void |
set(int from,
int to)
Set specified range of bits into
true . |
void |
set(int from,
int to,
boolean val)
Set specified range of bits into specified value.
|
int |
size()
Return a field width as specified in the constructor.
|
java.lang.String |
toString()
Convert bit field into string representation.
|
static BitField |
valueOf(java.lang.String str)
Parse
String like 00011000 and create an instance of
BitField . |
void |
xor(java.util.BitSet set)
Performs a logical XOR of this bit field with the argument bit set.
|
public BitField(int width)
false
.width
- Number of bits in field, indexed from 0
to
width-1
.java.lang.NegativeArraySizeException
- if the specified width is negative.public static BitField valueOf(java.lang.String str)
String
like 00011000 and create an instance of
BitField
.str
- Source string.BitField
instance or null
if
source string does not contain properly formatted bit field.public void and(java.util.BitSet set)
and
in class java.util.BitSet
set
- A bit set to perform operation with.java.lang.IndexOutOfBoundsException
- if the specified set is too wide.public void andNot(java.util.BitSet set)
andNot
in class java.util.BitSet
set
- A bit set to perform operation with.java.lang.IndexOutOfBoundsException
- if the specified set is too wide.public void clear(int index)
false
.clear
in class java.util.BitSet
index
- The index of the bit to clear.java.lang.IndexOutOfBoundsException
- if the specified index is negative
or exceeds BitField width.public void clear(int from, int to)
false
.clear
in class java.util.BitSet
from
- The index of the first bit in range.to
- The index of the last bit in range.java.lang.IndexOutOfBoundsException
- if the specified range does not fit
into BitField width.public void flip(int index)
flip
in class java.util.BitSet
index
- The index of the bit to change.java.lang.IndexOutOfBoundsException
- if the specified index is negative
or exceeds BitField width.public void flip(int from, int to)
flip
in class java.util.BitSet
from
- The index of the first bit in range.to
- The index of the last bit in range.java.lang.IndexOutOfBoundsException
- if the specified range does not fit
into BitField width.public boolean get(int index)
get
in class java.util.BitSet
index
- The index of the bit to get.true
if specified bit is set.java.lang.IndexOutOfBoundsException
- if the specified index is negative or exceeds BitField width.public void or(java.util.BitSet set)
or
in class java.util.BitSet
set
- A bit set to perform operation with.java.lang.IndexOutOfBoundsException
- if the specified set is too wide.public void set(int index)
true
.set
in class java.util.BitSet
index
- The index of the bit to set.java.lang.IndexOutOfBoundsException
- if the specified index is negative
or exceeds BitField width.public void set(int index, boolean val)
set
in class java.util.BitSet
index
- The index of the bit to setval
- New bit value.java.lang.IndexOutOfBoundsException
- if the specified index is negative
or exceeds BitField width.public void set(int from, int to)
true
.set
in class java.util.BitSet
from
- The index of the first bit in range.to
- The index of the last bit in range.java.lang.IndexOutOfBoundsException
- if the specified range does not fit
into BitField width.public void set(int from, int to, boolean val)
set
in class java.util.BitSet
from
- The index of the first bit in range.to
- The index of the last bit in range.val
- New value for the bits in range.java.lang.IndexOutOfBoundsException
- if the specified range does not fit
into BitField width.public int size()
size
in class java.util.BitSet
public java.lang.String toString()
toString
in class java.util.BitSet
String
on '0's and '1's which represent state of
the bit field.public void xor(java.util.BitSet set)
xor
in class java.util.BitSet
set
- A bit set to perform operation with.java.lang.IndexOutOfBoundsException
- if the specified set is too wide.private void checkBitSet(java.util.BitSet set)
set
- BitSet instance to check.java.lang.IndexOutOfBoundsException
- if specified bit set is too wide.private void checkIndex(int index)
index
- index to check.java.lang.IndexOutOfBoundsException
- if index does not fit into range.