Extension SDK 10.1.2

oracle.ide.util
Class BitField

java.lang.Object
  extended byoracle.ide.util.BitField

public class BitField
extends java.lang.Object

Utility class for manipulating a set of bit flags in an integer bit mask.


Constructor Summary
BitField()
          Creates a new BitField.
BitField(int bits)
          Creates a new BitField whose initial bits are defined by the specified bit mask.
 
Method Summary
 void clear(int bitIndex)
          Deprecated. Replace with {#unset(int)}.
 int get(int bitIndex)
          Returns the value of this BitField after masking all bits except the specified bit.
 int getField()
          Returns the full bit mask for this BitField.
 int getSize()
          Returns the "logical size" of this BitField, which is the index of the highest set bit in the BitField plus one.
 boolean isSet(int bitIndex)
          Tests whether the bit specified by the index is set.
static boolean isSet(int bits, int mask)
          Tests whether one or more bits are set in an external field of bits.
 void set(int bitIndex)
          Sets the bit specified by the index to 1.
static int set(int bits, int mask)
          Sets one or more bits in an external field of bits to 1.
 void setField(int bits)
          Sets the full bit mask for this BitField.
 void toggle(int bitIndex)
          Toggles the bit specified by the index.
static int toggle(int bits, int mask)
          Toggles one or more bits in an external field of bits.
 void unset(int bitIndex)
          Sets the bit specified by the index to 0.
static int unset(int bits, int mask)
          Sets one or more bits in an external field of bits to 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitField

public BitField()
Creates a new BitField. All bits are initially 0.


BitField

public BitField(int bits)
Creates a new BitField whose initial bits are defined by the specified bit mask.

Parameters:
bits - the initial bit mask.
Method Detail

getSize

public int getSize()
Returns the "logical size" of this BitField, which is the index of the highest set bit in the BitField plus one. Returns zero if the BitField contains no set bits.

Returns:
the logical size of this BitField.

set

public void set(int bitIndex)
Sets the bit specified by the index to 1.

Parameters:
bitIndex - the index of the bit to be set.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range.

unset

public void unset(int bitIndex)
Sets the bit specified by the index to 0.

Parameters:
bitIndex - the index of the bit to be cleared.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range.

clear

public void clear(int bitIndex)
Deprecated. Replace with {#unset(int)}.


toggle

public void toggle(int bitIndex)
Toggles the bit specified by the index.

Parameters:
bitIndex - the index of the bit to be toggled.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range.

isSet

public boolean isSet(int bitIndex)
Tests whether the bit specified by the index is set.

Parameters:
bitIndex - the index of the bit to be tested.
Returns:
true if the bit is set; otherwise false.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range.

get

public int get(int bitIndex)
Returns the value of this BitField after masking all bits except the specified bit.

Parameters:
bitIndex - the index of the bit to be tested.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range.

getField

public int getField()
Returns the full bit mask for this BitField.


setField

public void setField(int bits)
Sets the full bit mask for this BitField.


isSet

public static boolean isSet(int bits,
                            int mask)
Tests whether one or more bits are set in an external field of bits.

Parameters:
bits - the external field of bits.
mask - the bit or set of bits to test against the bit field.
Returns:
true if all of the specified bits are set in the external bit field; false if any of the bits are not set, or if the mask is zero.

set

public static int set(int bits,
                      int mask)
Sets one or more bits in an external field of bits to 1.

Parameters:
bits - the external field of bits.
mask - the bit or set of bits to set in the bit field.
Returns:
the value of the external bit field after setting the specified bits.

unset

public static int unset(int bits,
                        int mask)
Sets one or more bits in an external field of bits to 0.

Parameters:
bits - the external field of bits.
mask - the bit or set of bits to clear in the bit field.
Returns:
the value of the external bit field after clearing the specified bits.

toggle

public static int toggle(int bits,
                         int mask)
Toggles one or more bits in an external field of bits.

Parameters:
bits - the external field of bits.
mask - the bit or set of bits to toggle in the bit field.
Returns:
the value of the external bit field after toggling the specified bits.

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.