Class Bitmap

java.lang.Object
org.osgi.test.common.bitmaps.Bitmap

public class Bitmap extends Object
Useful class for producing human-friendly dumps of bit fields. Has support functions for single-bit values (toString(int) and multi-bit fields maskToString(int).
  • Constructor Details

    • Bitmap

      public Bitmap(int[] types, IntFunction<String> mappingFunction)
      Constructs a bitmap
      Parameters:
      types - the full set of known allowed field values in this bit map.
      mappingFunction - function to produce a human-friendly string for the given map.
    • Bitmap

      public Bitmap(Map<Integer,String> mapping)
  • Method Details

    • getKnownMask

      public int getKnownMask()
      Returns:
      A mask of all known allowed values in this bit mask.
    • getUnknownMask

      public int getUnknownMask()
      Returns:
      A mask of all values that are not known to be allowed in this bit mask.
    • hasSingleBit

      public static boolean hasSingleBit(int type)
      Checks to see if it has exactly one bit set.
      Parameters:
      type - the bit field to check
      Returns:
      true if only one bit set, otherwise false.
    • toString

      public String toString(int type)
      Return a string representation of the given type. Expects to be passed a field with exactly one bit set - if you want to dump a bit mask, then please use maskToString(int)
      Parameters:
      type - the field being converted.
      Returns:
      Description of the given field.
      Throws:
      IllegalArgumentException - if the field has more than one bit set.
      See Also:
    • maskToString

      public String maskToString(int mask)
      Return a string representation of the given type mask. If the mask contains multiple bits, their string representations are separated by pipes (" | ").
      Parameters:
      mask - the field being converted.
      Returns:
      Description of the given field.
      See Also:
    • typeMatchesMask

      public static boolean typeMatchesMask(int type, int mask)