com.jniwrapper.util
Class FlagSet

java.lang.Object
  extended by com.jniwrapper.util.FlagSet

public class FlagSet
extends java.lang.Object

FlagSet is a flags container and provides simple logical operations using bitmasks.

NOTE: We do not use the BitSet class because it provides setting bits by index but not by the bitmask (flag).


Constructor Summary
FlagSet()
           
FlagSet(long flags)
           
 
Method Summary
 void add(long flag)
          Adds the specified flag to the flag set.
 void and(long flag)
          AND function of existing and specified flags.
 void clear()
          Sets the flag set to zero.
 boolean contains(long flag)
          Verifies if the specified flag is present in the flag set.
 boolean getBit(int index)
          Gets the bit by the specified index.
 int getBits(int from, int to)
          Returns the number from specified range of the bits.
 long getFlags()
          Returns the flag set value.
static long getMask(int from, int to)
          Returns the mask for specified bit range.
 void or(long flag)
          OR function of existing and specified flags.
 void remove(long flag)
          Removes the specified flag from the flag set.
 void setBit(int index, boolean set)
          Sets or removes the bit by specified index.
 void setBits(int from, int to, long value)
           
 void setupFlag(long flag, boolean set)
          Sets the specified flag.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FlagSet

public FlagSet()

FlagSet

public FlagSet(long flags)
Method Detail

and

public void and(long flag)
AND function of existing and specified flags.

Parameters:
flag -

or

public void or(long flag)
OR function of existing and specified flags.

Parameters:
flag -

add

public void add(long flag)
Adds the specified flag to the flag set. Equivalent of or(long) function.

Parameters:
flag - flag to add.

remove

public void remove(long flag)
Removes the specified flag from the flag set.

Parameters:
flag - flag to remove.

contains

public boolean contains(long flag)
Verifies if the specified flag is present in the flag set.

Parameters:
flag - flag to check.
Returns:
true if the glag exits, false othewise.

clear

public void clear()
Sets the flag set to zero.


getFlags

public long getFlags()
Returns the flag set value.

Returns:
the flags value.

setupFlag

public void setupFlag(long flag,
                      boolean set)
Sets the specified flag.

Parameters:
flag - flag to set or remove.
set - if true - set the flag; false - remove.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getBits

public int getBits(int from,
                   int to)
Returns the number from specified range of the bits.

Parameters:
from - specifies begin index of the bits range.
to - specifies end index of the bits range.
Returns:
the integer value of the specified bits range.

getBit

public boolean getBit(int index)
Gets the bit by the specified index.

Parameters:
index - the bit index.
Returns:
true if bit is set, otherwise false.

setBit

public void setBit(int index,
                   boolean set)
Sets or removes the bit by specified index.

Parameters:
index - the bit index.
set - true - set bit to 1; false - clear the bit.

setBits

public void setBits(int from,
                    int to,
                    long value)

getMask

public static long getMask(int from,
                           int to)
Returns the mask for specified bit range.

Parameters:
from - specifies begin index of the bits range.
to - specifies end index of the bits range.
Returns:
the integer value of the mask.