4040 *
4141 * The declaration of a integer basic data type.
4242 *
43+ * note: there are some basic declarations. They are not needed, but are kept
44+ * for API reasons.
45+ *
4346 * @version 1.0
4447 * @author Matthew Khouzam
4548 * @author Simon Marchi
@@ -56,66 +59,98 @@ public final class IntegerDeclaration extends Declaration implements ISimpleData
5659 private static final int SIZE_8 = 8 ;
5760 /**
5861 * unsigned int 32 bits big endian
62+ *
63+ * @apiNote Not used in code, only for testing.
5964 */
6065 public static final IntegerDeclaration UINT_32B_DECL = new IntegerDeclaration (32 , false , ByteOrder .BIG_ENDIAN );
6166 /**
6267 * unsigned int 32 bits little endian
68+ *
69+ * @apiNote Not used in code, only for testing.
6370 */
6471 public static final IntegerDeclaration UINT_32L_DECL = new IntegerDeclaration (32 , false , ByteOrder .LITTLE_ENDIAN );
6572 /**
6673 * signed int 32 bits big endian
74+ *
75+ * @apiNote Not used in code, only for testing.
6776 */
6877 public static final IntegerDeclaration INT_32B_DECL = new IntegerDeclaration (32 , true , ByteOrder .BIG_ENDIAN );
6978 /**
7079 * signed int 32 bits little endian
80+ *
81+ * @apiNote Not used in code, only for testing.
7182 */
7283 public static final IntegerDeclaration INT_32L_DECL = new IntegerDeclaration (32 , true , ByteOrder .LITTLE_ENDIAN );
7384 /**
7485 * unsigned int 32 bits big endian
86+ *
87+ * @apiNote Not used in code, only for testing.
7588 */
7689 public static final IntegerDeclaration UINT_64B_DECL = new IntegerDeclaration (64 , false , ByteOrder .BIG_ENDIAN );
7790 /**
7891 * unsigned int 64 bits little endian
92+ *
93+ * @apiNote Not used in code, only for testing.
7994 */
8095 public static final IntegerDeclaration UINT_64L_DECL = new IntegerDeclaration (64 , false , ByteOrder .LITTLE_ENDIAN );
8196 /**
8297 * signed int 64 bits big endian
98+ *
99+ * @apiNote Not used in code, only for testing.
83100 */
84101 public static final IntegerDeclaration INT_64B_DECL = new IntegerDeclaration (64 , true , ByteOrder .BIG_ENDIAN );
85102 /**
86103 * signed int 64 bits little endian
104+ *
105+ * @apiNote Not used in code, only for testing.
87106 */
88107 public static final IntegerDeclaration INT_64L_DECL = new IntegerDeclaration (64 , true , ByteOrder .LITTLE_ENDIAN );
89108 /**
90109 * unsigned 8 bit int endianness doesn't matter since it's 8 bits (byte)
110+ *
111+ * @apiNote Not used in code, only for testing.
91112 */
92113 public static final IntegerDeclaration UINT_8_DECL = new IntegerDeclaration (8 , false , ByteOrder .BIG_ENDIAN );
93114 /**
94115 * signed 8 bit int endianness doesn't matter since it's 8 bits (char)
116+ *
117+ * @apiNote Not used in code, only for testing.
95118 */
96119 public static final IntegerDeclaration INT_8_DECL = new IntegerDeclaration (8 , true , ByteOrder .BIG_ENDIAN );
97120 /**
98121 * Unsigned 5 bit int, used for event headers
122+ *
123+ * @apiNote Not used in code, only for testing.
99124 */
100125 public static final IntegerDeclaration UINT_5B_DECL = new IntegerDeclaration (5 , false , 10 , ByteOrder .BIG_ENDIAN , Encoding .NONE , "" , 1 ); //$NON-NLS-1$
101126 /**
102127 * Unsigned 5 bit int, used for event headers
128+ *
129+ * @apiNote Not used in code, only for testing.
103130 */
104131 public static final IntegerDeclaration UINT_5L_DECL = new IntegerDeclaration (5 , false , 10 , ByteOrder .LITTLE_ENDIAN , Encoding .NONE , "" , 1 ); //$NON-NLS-1$
105132 /**
106133 * Unsigned 5 bit int, used for event headers
134+ *
135+ * @apiNote Not used in code, only for testing.
107136 */
108137 public static final IntegerDeclaration UINT_27B_DECL = new IntegerDeclaration (27 , false , 10 , ByteOrder .BIG_ENDIAN , Encoding .NONE , "" , 1 ); //$NON-NLS-1$
109138 /**
110139 * Unsigned 5 bit int, used for event headers
140+ * @deprecated use the {@link #createDeclaration(int, boolean, int, ByteOrder, Encoding, String, long, String, Map)} instead
111141 */
142+ @ Deprecated
112143 public static final IntegerDeclaration UINT_27L_DECL = new IntegerDeclaration (27 , false , 10 , ByteOrder .LITTLE_ENDIAN , Encoding .NONE , "" , 1 ); //$NON-NLS-1$
113144 /**
114145 * Unsigned 16 bit int, used for event headers
146+ *
147+ * @apiNote Not used in code, only for testing.
115148 */
116149 public static final IntegerDeclaration UINT_16B_DECL = new IntegerDeclaration (16 , false , ByteOrder .BIG_ENDIAN );
117150 /**
118151 * Unsigned 16 bit int, used for event headers
152+ *
153+ * @apiNote Not used in code, only for testing.
119154 */
120155 public static final IntegerDeclaration UINT_16L_DECL = new IntegerDeclaration (16 , false , ByteOrder .LITTLE_ENDIAN );
121156 // ------------------------------------------------------------------------
@@ -131,6 +166,7 @@ public final class IntegerDeclaration extends Declaration implements ISimpleData
131166 private final long fAlignment ;
132167 private final String fClock ;
133168 private boolean fVarint = false ;
169+
134170 private static class IntervalNode {
135171 final long start , end ;
136172 final String name ;
@@ -378,6 +414,7 @@ private void setMappings(Map<String, List<IntegerRange>> mappings) {
378414 private void buildIntervalTree () {
379415 fIntervalTree .clear ();
380416 for (Map .Entry <String , List <IntegerRange >> entry : fMappings .entrySet ()) {
417+ // TODO: extend mappings if they have the same key and overlap
381418 String name = entry .getKey ();
382419 for (IntegerRange range : entry .getValue ()) {
383420 fIntervalTree .add (new IntervalNode (range .getStart (), range .getEnd (), name ));
@@ -564,16 +601,7 @@ private long read(BitBuffer input) throws CTFException {
564601
565602 @ Override
566603 public int hashCode () {
567- final int prime = 31 ;
568- int result = 1 ;
569- result = prime * result + (int ) (fAlignment ^ (fAlignment >>> 32 ));
570- result = prime * result + fBase ;
571- result = prime * result + fByteOrder .toString ().hashCode ();
572- result = prime * result + fClock .hashCode ();
573- result = prime * result + fEncoding .hashCode ();
574- result = prime * result + fLength ;
575- result = prime * result + (fSigned ? 1231 : 1237 );
576- return result ;
604+ return Objects .hash (fAlignment , fBase , fByteOrder , fClock , fEncoding , fLength , fSigned , fMappings , getRole ());
577605 }
578606
579607 @ Override
@@ -645,13 +673,10 @@ String getMappingForValue(long value) {
645673 if (fIntervalTree .isEmpty ()) {
646674 return "" ; //$NON-NLS-1$
647675 }
648-
649676 List <String > matches = new ArrayList <>();
650-
651677 // Binary search for rightmost node with start <= value
652678 int left = 0 , right = fIntervalTree .size () - 1 ;
653679 int lastValid = -1 ;
654-
655680 while (left <= right ) {
656681 int mid = (left + right ) / 2 ;
657682 if (fIntervalTree .get (mid ).start <= value ) {
@@ -661,16 +686,13 @@ String getMappingForValue(long value) {
661686 right = mid - 1 ;
662687 }
663688 }
664-
665689 // Check all nodes from lastValid backwards for overlaps
666690 for (int i = lastValid ; i >= 0 ; i --) {
667691 IntervalNode node = fIntervalTree .get (i );
668- if (node .end < value ) {
669- break ;
692+ if (node .end >= value ) {
693+ matches . add ( node . name ) ;
670694 }
671- matches .add (node .name );
672695 }
673-
674696 return matches .isEmpty () ? "" : Objects .requireNonNull (String .join (" " , matches )); //$NON-NLS-1$ //$NON-NLS-2$
675697 }
676698
0 commit comments