byucc.jhdl.base
Class Flags

java.lang.Object
  extended bybyucc.jhdl.base.Flags

public class Flags
extends java.lang.Object

This class defines a set of flag manipulation utilities designed for optimal use of memory. Simply use an int to hold your flags.
For example, this sets bits 2 and 4 to true if bit 3 is true:
int flags;
...
if (Flags.get(flags, BIT_3))
flags = Flags.set(flags, BIT_2 | BIT_4);

Author:
Eric Blake

Field Summary
static int ALL_BITS
          Mask for all 32 bits.
static int BIT_0
          Masks for each bit possible.
static int BIT_1
          Masks for each bit possible.
static int BIT_10
          Masks for each bit possible.
static int BIT_11
          Masks for each bit possible.
static int BIT_12
          Masks for each bit possible.
static int BIT_13
          Masks for each bit possible.
static int BIT_14
          Masks for each bit possible.
static int BIT_15
          Masks for each bit possible.
static int BIT_16
          Masks for each bit possible.
static int BIT_17
          Masks for each bit possible.
static int BIT_18
          Masks for each bit possible.
static int BIT_19
          Masks for each bit possible.
static int BIT_2
          Masks for each bit possible.
static int BIT_20
          Masks for each bit possible.
static int BIT_21
          Masks for each bit possible.
static int BIT_22
          Masks for each bit possible.
static int BIT_23
          Masks for each bit possible.
static int BIT_24
          Masks for each bit possible.
static int BIT_25
          Masks for each bit possible.
static int BIT_26
          Masks for each bit possible.
static int BIT_27
          Masks for each bit possible.
static int BIT_28
          Masks for each bit possible.
static int BIT_29
          Masks for each bit possible.
static int BIT_3
          Masks for each bit possible.
static int BIT_30
          Masks for each bit possible.
static int BIT_31
          Masks for each bit possible.
static int BIT_4
          Masks for each bit possible.
static int BIT_5
          Masks for each bit possible.
static int BIT_6
          Masks for each bit possible.
static int BIT_7
          Masks for each bit possible.
static int BIT_8
          Masks for each bit possible.
static int BIT_9
          Masks for each bit possible.
 
Constructor Summary
Flags()
           
 
Method Summary
static int clear(int flags, int mask)
          Clears all masked bits, short for set(flags, mask, false).
static int clearAll()
          Clears all bits.
static boolean equal(int flag1, int flag2, int mask)
          Checks if all masked bits of flagset 1 equal corresponding bits in flagset 2.
static boolean get(int flags, int mask)
          Checks if all masked bits are true.
static boolean getAny(int flags, int mask)
          Checks if any masked bit is true.
static int set(int flags, int mask)
          Sets all masked bits, short for set(flags, mask, true).
static int set(int flags, int mask, boolean value)
          Sets all masked bits to value.
static int set(int flag1, int flag2, int mask)
          Sets all masked bits in flagset 1 to value of corresponding bits in flagset 2.
For example, set(BIT_0 | BIT_1 | BIT_2, BIT_0 | BIT_2 | BIT_3, BIT_1 | BIT_2) returns BIT_0 | BIT_2, leaving bits 0 and 3 of flag1 unchanged, and setting bits 1 and 2 to their current value in flag2.
static int setAll()
          Sets all bits.
static int toggle(int flags, int mask)
          Toggles masked bits between true and false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIT_0

public static final int BIT_0
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_1

public static final int BIT_1
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_2

public static final int BIT_2
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_3

public static final int BIT_3
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_4

public static final int BIT_4
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_5

public static final int BIT_5
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_6

public static final int BIT_6
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_7

public static final int BIT_7
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_8

public static final int BIT_8
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_9

public static final int BIT_9
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_10

public static final int BIT_10
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_11

public static final int BIT_11
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_12

public static final int BIT_12
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_13

public static final int BIT_13
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_14

public static final int BIT_14
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_15

public static final int BIT_15
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_16

public static final int BIT_16
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_17

public static final int BIT_17
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_18

public static final int BIT_18
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_19

public static final int BIT_19
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_20

public static final int BIT_20
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_21

public static final int BIT_21
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_22

public static final int BIT_22
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_23

public static final int BIT_23
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_24

public static final int BIT_24
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_25

public static final int BIT_25
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_26

public static final int BIT_26
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_27

public static final int BIT_27
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_28

public static final int BIT_28
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_29

public static final int BIT_29
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_30

public static final int BIT_30
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

BIT_31

public static final int BIT_31
Masks for each bit possible. Use | (bitwise or) to combine into other masks.

See Also:
Constant Field Values

ALL_BITS

public static final int ALL_BITS
Mask for all 32 bits.

See Also:
Constant Field Values
Constructor Detail

Flags

public Flags()
Method Detail

set

public static final int set(int flags,
                            int mask)
Sets all masked bits, short for set(flags, mask, true).

Parameters:
flags - The flag set to modify.
mask - The bits to set.
Returns:
An updated flag set.

set

public static final int set(int flags,
                            int mask,
                            boolean value)
Sets all masked bits to value.

Parameters:
flags - The flag set to modify.
mask - The bits to set.
value - The value to set bits to.
Returns:
An updated flag set.

set

public static final int set(int flag1,
                            int flag2,
                            int mask)
Sets all masked bits in flagset 1 to value of corresponding bits in flagset 2.
For example, set(BIT_0 | BIT_1 | BIT_2, BIT_0 | BIT_2 | BIT_3, BIT_1 | BIT_2) returns BIT_0 | BIT_2, leaving bits 0 and 3 of flag1 unchanged, and setting bits 1 and 2 to their current value in flag2.

Parameters:
flag1 - The flag set to modify.
flag2 - The flag set to read from.
mask - The bits to set.
Returns:
An update of flag set 1.

clear

public static final int clear(int flags,
                              int mask)
Clears all masked bits, short for set(flags, mask, false).

Parameters:
flags - The flag set to modify.
mask - The bits to clear.
Returns:
An updated flag set.

get

public static final boolean get(int flags,
                                int mask)
Checks if all masked bits are true.

Parameters:
flags - The flag set to read.
mask - The bits to read.
Returns:
true if all masked bits are true, false if any bit is false.

getAny

public static final boolean getAny(int flags,
                                   int mask)
Checks if any masked bit is true.

Parameters:
flags - The flag set to read.
mask - The bits to read.
Returns:
true if any masked bit is true, false if all bits are false.

equal

public static final boolean equal(int flag1,
                                  int flag2,
                                  int mask)
Checks if all masked bits of flagset 1 equal corresponding bits in flagset 2.

Parameters:
flag1 - The first flag set.
flag2 - The second flag set.
mask - The bits to compare.
Returns:
true only if all masked bits are equal between flag1 and flag2.

toggle

public static final int toggle(int flags,
                               int mask)
Toggles masked bits between true and false.

Parameters:
flags - The flag set to modify.
mask - The bits to toggle.
Returns:
An updated flag set.

clearAll

public static final int clearAll()
Clears all bits.

Returns:
An updated flag set.

setAll

public static final int setAll()
Sets all bits.

Returns:
An updated flag set.


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.