Class Structure.BitOffsetComparator

  • All Implemented Interfaces:
    java.util.Comparator<java.lang.Object>
    Enclosing interface:
    Structure

    public static class Structure.BitOffsetComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.Object>
    BitOffsetComparator provides ability to compare an normalized bit offset (see getNormalizedBitfieldOffset(int, int, int, int, boolean)) with a DataTypeComponent object. The offset will be considered equal (0) if the component contains the offset. A normalized component bit numbering is used to establish the footprint of each component with an ordinal-based ordering (assumes specific LE/BE allocation rules). Bit offsets for this comparator number the first allocated bit of the structure as 0 and the last allocated bit of the structure as (8 * structLength) - 1. For big-endian bitfields the msb of the bitfield will be assigned the lower bit-number (assumes msb-allocated-first), while little-endian will perform similar numbering assuming byte-swap and bit-reversal of the storage unit (assumes lsb-allocated-first). Both cases result in a normalized view where normalized bit-0 is allocated first.
     
     Example:
        
     Big-Endian (normalized view):
        | . . . . . . . 7 | 8 9 . . . . . . |
        |<--------------------------------->| storage-size (2-bytes)
                            |<--------------| bit-offset (6, lsb position within storage unit)
                        |<--->|               bit-size (3)
                            
     Little-Endian (normalized view, w/ storage byte-swap and bit-reversal):
        | . . . . . . 6 7 | 8 . . . . . . . |
        |------------>|                       bit-offset (6, lsb position within storage unit)
                      |<--->|                 bit-size (3)
     
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Comparator<java.lang.Object> INSTANCE_BE  
      static java.util.Comparator<java.lang.Object> INSTANCE_LE  
    • Constructor Summary

      Constructors 
      Constructor Description
      BitOffsetComparator​(boolean bigEndian)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.Object o1, java.lang.Object o2)  
      static int getNormalizedBitfieldOffset​(int byteOffset, int storageSize, int effectiveBitSize, int bitOffset, boolean bigEndian)
      Compute the normalized bit offset of a bitfield relative to the start of a structure.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • INSTANCE_LE

        public static final java.util.Comparator<java.lang.Object> INSTANCE_LE
      • INSTANCE_BE

        public static final java.util.Comparator<java.lang.Object> INSTANCE_BE
    • Constructor Detail

      • BitOffsetComparator

        public BitOffsetComparator​(boolean bigEndian)
    • Method Detail

      • compare

        public int compare​(java.lang.Object o1,
                           java.lang.Object o2)
        Specified by:
        compare in interface java.util.Comparator<java.lang.Object>
      • getNormalizedBitfieldOffset

        public static int getNormalizedBitfieldOffset​(int byteOffset,
                                                      int storageSize,
                                                      int effectiveBitSize,
                                                      int bitOffset,
                                                      boolean bigEndian)
        Compute the normalized bit offset of a bitfield relative to the start of a structure. NOTE: This implementation currently relies only on endianess to dictate bit allocation ordering. If future support is added for alternate bitfield packing, this implementation will require modification.
        Parameters:
        byteOffset - byte offset within structure of storage unit
        storageSize - storage unit size (i.e., component length)
        effectiveBitSize - size of bitfield in bits
        bitOffset - left shift amount for bitfield based upon a big-endian view of the storage unit
        bigEndian - true if big-endian packing applies
        Returns:
        normalized bit-offset