Commit caa722a2 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Fix up a few coding issues:

 - Remove a redundant if check on the objectId in the third segment.  This
shouldn't happen anyways.
 - Remove an unused variable.
 - Correct a comment from a copy+paste error.
 - If properties are not found (not that there are none), then throw an exception.
 - Use the classname as found in the MCOS section, to make finding errors easier.
 - Even though it isn't used, store the segment 2 index for object properties,
   for the future.
parent 4240e667
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -519,13 +519,7 @@ public class MatFileReader
                                        // and use the index into this segment as the id instead.

            // Then parse it into the form needed for the object.

            MatMCOSObjectInformation objHolder = objectInfoList.get(objectId - 1);
            if (objHolder == null) {
                objHolder = new MatMCOSObjectInformation(classNamesList.get(classIndex - 1), classIndex, objectId, segment4Index);
                objectInfoList.put(objectId - 1, objHolder);
            }

            objectInfoList.put(objectId - 1, new MatMCOSObjectInformation(classNamesList.get(classIndex - 1), classIndex, objectId, segment2Index, segment4Index));
        }

        // Sanity check, position in the buffer should equal the start of the fourth segment!
@@ -539,7 +533,6 @@ public class MatFileReader
            throw new IllegalStateException("MAT file's MCOS data has different byte values for unknown fields!  Aborting!");
        }
        List<Map<String, MLArray>> segment4Properties = new ArrayList<Map<String, MLArray>>();
        int propertiesIndex = 0;
        while (mcosDataBuf.position() < segmentIndexes[4]) {
            Map<String, MLArray> properties = new HashMap<String, MLArray>();
            int propertiesCount = mcosDataBuf.getInt();
@@ -566,7 +559,7 @@ public class MatFileReader
        }


        // Sanity check, position in the buffer should equal the start of the fourth segment!
        // Sanity check, position in the buffer should equal the start of the fifth segment!
        if (mcosDataBuf.position() != segmentIndexes[4]) {
            throw new IllegalStateException("Data from the properties section (2) was not all read!  At: " + mcosDataBuf.position() + ", wanted: " + segmentIndexes[4]);
        }
@@ -578,6 +571,8 @@ public class MatFileReader
                for (Map.Entry<String, MLArray> attribute : segment4Properties.get(it.segment4PropertiesIndex - 1).entrySet()) {
                    objAttributes.setField(attribute.getKey(), attribute.getValue());
                }
            } else {
                throw new IllegalStateException("Properties are not found!  Not sure where to look ...");
            }
        }

@@ -598,7 +593,8 @@ public class MatFileReader
        for (Map.Entry<String, MLArray> it : data.entrySet()) {
            if ( it.getValue() instanceof MLObjectPlaceholder ) {
                MLObjectPlaceholder obj = (MLObjectPlaceholder) it.getValue();
                it.setValue(new MLObject(obj.name, classNamesList.get(obj.classId - 1), objectInfoList.get(obj.objectId - 1).structure));
                MatMCOSObjectInformation objectInformation = objectInfoList.get(obj.objectId - 1);
                it.setValue(new MLObject(obj.name, classNamesList.get(objectInformation.classId - 1), objectInformation.structure));
            }
        }
    }
+3 −1
Original line number Diff line number Diff line
@@ -10,19 +10,21 @@ import ca.mjdsystems.jmatio.types.MLStructure;
 * @author Matthew Dawson <matthew@mjdsystems.ca>
 */
class MatMCOSObjectInformation {
    MatMCOSObjectInformation(String className, int classId, int objectId, int segment4PropertiesIndex)
    MatMCOSObjectInformation(String className, int classId, int objectId, int segment2PropertiesIndex, int segment4PropertiesIndex)
    {
        this.className = className;

        this.objectId = objectId;
        this.classId = classId;

        this.segment2PropertiesIndex = segment2PropertiesIndex;
        this.segment4PropertiesIndex = segment4PropertiesIndex;
    }

    final String className;
    final int objectId;
    final int classId;
    final int segment2PropertiesIndex;
    final int segment4PropertiesIndex;
    final MLStructure structure = new MLStructure("", new int[]{1,1});
}