1515
1616import java .io .IOException ;
1717import java .lang .reflect .InvocationTargetException ;
18+ import java .math .BigDecimal ;
19+ import java .math .BigInteger ;
1820import java .nio .channels .SeekableByteChannel ;
1921import java .nio .file .Files ;
2022import java .nio .file .Path ;
2123import java .nio .file .StandardOpenOption ;
2224import java .util .Arrays ;
25+ import java .util .BitSet ;
2326import java .util .Comparator ;
2427import java .util .Optional ;
2528
@@ -122,16 +125,16 @@ public static void displayData(SeekableByteChannel channel, HdfDataset ds, HdfFi
122125 if (ds .hasData ()) {
123126 switch (ds .getDimensionality ()) {
124127 case 0 :
125- displayScalarData (channel , ds , HdfData . class , reader );
128+ displayScalarData (channel , ds , reader );
126129 break ;
127130 case 1 :
128- displayVectorData (channel , ds , HdfData . class , reader );
131+ displayVectorData (channel , ds , reader );
129132 break ;
130133 case 2 :
131- displayMatrixData (channel , ds , HdfData . class , reader );
134+ displayMatrixData (channel , ds , reader );
132135 break ;
133136 default :
134- displayNDimData (channel , ds , HdfData . class , reader );
137+ displayNDimData (channel , ds , reader );
135138 break ;
136139
137140 }
@@ -149,16 +152,17 @@ public static void displayData(SeekableByteChannel channel, HdfDataset ds, HdfFi
149152 *
150153 * @param fileChannel the seekable byte channel for reading the HDF5 file
151154 * @param dataSet the dataset to read from
152- * @param clazz the class type of the data
153155 * @param hdfDataFile the HDF5 file context
154156 * @param <T> the type of the data
155157 * @throws IOException if an I/O error occurs
156158 */
157- public static <T > void displayScalarData (SeekableByteChannel fileChannel , HdfDataset dataSet , Class <T > clazz , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
159+ public static <T extends Comparable <T >> void displayScalarData (SeekableByteChannel fileChannel , HdfDataset dataSet , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
160+ Class <T > clazz = getClassForDatatype (dataSet );
158161 TypedDataSource <T > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , clazz );
159162
160- Optional <String > max = dataSource .streamScalar ().map (h ->h .toString ()).max (Comparator .naturalOrder ());
161- System .out .println (dataSet .getObjectPath () + " streamScalar nax = " + max .orElse ("NO MAX" ));
163+ // Optional<String> max = dataSource.streamScalar().map(h->h.toString()).max(Comparator.naturalOrder());
164+ Optional <T > max = dataSource .streamScalar ().max (Comparator .naturalOrder ());
165+ System .out .println (dataSet .getObjectPath () + " " + dataSet .getDatatype ().getDatatypeClass ().name () + "->" + clazz .getSimpleName () + " streamScalar max = " + (max .isPresent () ? max .get ().toString () : "NaN" ));
162166// long count = dataSource.parallelStreamScalar().count();
163167// System.out.println(dataSet.getObjectPath() + " stream count = " + String.format("%,d", count) + ":" + dataSet.getDatatype().toString());
164168 }
@@ -173,19 +177,20 @@ public static <T> void displayScalarData(SeekableByteChannel fileChannel, HdfDat
173177 *
174178 * @param fileChannel the seekable byte channel for reading the HDF5 file
175179 * @param dataSet the dataset to read from
176- * @param clazz the class type of the data elements
177180 * @param hdfDataFile the HDF5 file context
178181 * @param <T> the type of the data elements
179182 * @throws IOException if an I/O error occurs
180183 */
181- public static <T > void displayVectorData (SeekableByteChannel fileChannel , HdfDataset dataSet , Class <T > clazz , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
184+ public static <T extends Comparable <T >> void displayVectorData (SeekableByteChannel fileChannel , HdfDataset dataSet , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
185+ Class <T > clazz = getClassForDatatype (dataSet );
182186 TypedDataSource <T > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , clazz );
183187
184188// T[] resultArray = dataSource.readVector();
185189// log.info("{} read = {}", displayType(clazz, resultArray), displayValue(resultArray));
186190
187- Optional <String > max = dataSource .streamVector ().map (h ->h .toString ()).max (Comparator .naturalOrder ());
188- System .out .println (dataSet .getObjectPath () + " streamVector max = " + max .orElse ("NO MAX" ));
191+ // Optional<String> max = dataSource.streamVector().map(h->h.toString()).max(Comparator.naturalOrder());
192+ Optional <T > max = dataSource .streamVector ().max (Comparator .naturalOrder ());
193+ System .out .println (dataSet .getObjectPath () + " " + dataSet .getDatatype ().getDatatypeClass ().name () + "->" + clazz .getSimpleName () + " streamVector max = " + (max .isPresent () ? max .get ().toString () : "NaN" ));
189194
190195// long count = dataSource.parallelStreamVector().count();
191196// System.out.println(dataSet.getObjectPath() + " stream count = " + String.format("%,d", count) + ":" + dataSet.getDatatype().toString());
@@ -201,16 +206,16 @@ public static <T> void displayVectorData(SeekableByteChannel fileChannel, HdfDat
201206 *
202207 * @param fileChannel the seekable byte channel for reading the HDF5 file
203208 * @param dataSet the dataset to read from
204- * @param clazz the class type of the data elements
205209 * @param hdfDataFile the HDF5 file context
206210 * @param <T> the type of the data elements
207211 * @throws IOException if an I/O error occurs
208212 */
209- public static <T > void displayMatrixData (SeekableByteChannel fileChannel , HdfDataset dataSet , Class <T > clazz , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
213+ public static <T extends Comparable <T >> void displayMatrixData (SeekableByteChannel fileChannel , HdfDataset dataSet , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
214+ Class <T > clazz = getClassForDatatype (dataSet );
210215 TypedDataSource <T > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , clazz );
211216
212- Optional <String > max = dataSource .streamMatrix ().map (h ->h . toString ( )).max (Comparator .naturalOrder ());
213- System .out .println (dataSet .getObjectPath () + " streamMatrix max = " + max .orElse ( "NO MAX " ));
217+ Optional <T > max = dataSource .streamMatrix ().flatMap (h ->Arrays . stream ( h )).max (Comparator .naturalOrder ());
218+ System .out .println (dataSet .getObjectPath () + " " + dataSet . getDatatype (). getDatatypeClass (). name () + "->" + clazz . getSimpleName () + " streamMatrix max = " + ( max .isPresent () ? max . get (). toString () : "NaN " ));
214219
215220// long count = dataSource.parallelStreamMatrix().count();
216221// System.out.println(dataSet.getObjectPath() + " stream count = " + String.format("%,d", count) + ":" + dataSet.getDatatype().toString());
@@ -226,22 +231,38 @@ public static <T> void displayMatrixData(SeekableByteChannel fileChannel, HdfDat
226231 *
227232 * @param fileChannel the seekable byte channel for reading the HDF5 file
228233 * @param dataSet the dataset to read from
229- * @param clazz the class type of the data elements
230234 * @param hdfDataFile the HDF5 file context
231235 * @param <T> the type of the data elements
232236 * @throws IOException if an I/O error occurs
233237 */
234- private static <T > void displayNDimData (SeekableByteChannel fileChannel , HdfDataset dataSet , Class <T > clazz , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
238+ private static <T extends Comparable <T >> void displayNDimData (SeekableByteChannel fileChannel , HdfDataset dataSet , HdfDataFile hdfDataFile ) throws IOException , InvocationTargetException , InstantiationException , IllegalAccessException {
239+ Class <T > clazz = getClassForDatatype (dataSet );
235240 TypedDataSource <T > dataSource = new TypedDataSource <>(fileChannel , hdfDataFile , dataSet , clazz );
236-
237241// String readResult = flattenedArrayToString(dataSource.readFlattened(), dataSource.getShape());
238242// log.info("read = {}", readResult);
239243
240- Optional <String > max = dataSource .streamFlattened ().map (h ->h .toString ()).max (Comparator .naturalOrder ());
241- System .out .println (dataSet .getObjectPath () + " streamFlattened max = " + max .orElse ("NO MAX" ));
244+ // Optional<String> max = dataSource.streamFlattened().map(h->h.toString()).max(Comparator.naturalOrder());
245+ Optional <T > max = dataSource .streamFlattened ().max (Comparator .naturalOrder ());
246+ System .out .println (dataSet .getObjectPath () + " " + dataSet .getDatatype ().getDatatypeClass ().name () + "->" + clazz .getSimpleName () + " streamFlattened max = " + (max .isPresent () ? max .get ().toString () : "NaN" ));
242247
243248 // long count = dataSource.parallelStreamFlattened().count();
244249// System.out.println(dataSet.getObjectPath() + " stream count = " + String.format("%,d", count) + ":" + dataSet.getDatatype().toString());
245250 }
246251
252+ private static <T extends Comparable <T >> Class <T > getClassForDatatype (HdfDataset dataSet ) {
253+ return (Class <T >) switch (dataSet .getDatatype ().getDatatypeClass ()) {
254+ case FIXED -> Long .class ;
255+ case FLOAT -> Double .class ;
256+ case TIME -> Long .class ;
257+ case STRING -> String .class ;
258+ case BITFIELD -> String .class ;
259+ case OPAQUE -> String .class ;
260+ case COMPOUND -> String .class ;
261+ case REFERENCE -> String .class ;
262+ case ENUM -> String .class ;
263+ case VLEN -> String .class ;
264+ case ARRAY -> String .class ;
265+ };
266+
267+ }
247268}
0 commit comments