E[] getGenericArrayAsBoxedPrimitive(final DataType dataType) {
+ final Object[] retVal;
+ getArraySizeDescriptor();
+ retVal = switch (dataType) {
+ case BOOL -> GenericsHelper.toObject(buffer.getBooleanArray());
+ case BYTE -> GenericsHelper.toObject(buffer.getByteArray());
+ case CHAR -> GenericsHelper.toObject(buffer.getCharArray());
+ case SHORT -> GenericsHelper.toObject(buffer.getShortArray());
+ case INT -> GenericsHelper.toObject(buffer.getIntArray());
+ case LONG -> GenericsHelper.toObject(buffer.getLongArray());
+ case FLOAT -> GenericsHelper.toObject(buffer.getFloatArray());
+ case DOUBLE -> GenericsHelper.toObject(buffer.getDoubleArray());
+ case STRING -> buffer.getStringArray();
+ default -> throw new IllegalArgumentException("type not implemented - " + dataType);
+ };
return (E[]) retVal;
}
private WireDataFieldDescription getRootElement() {
final int headerOffset = 1 + PROTOCOL_NAME.length() + 3; // unique byte + protocol length + 3 x byte for version
- return new WireDataFieldDescription(this, null, "ROOT".hashCode(), "ROOT", DataType.OTHER, buffer.position() + headerOffset, -1, -1);
+ return new WireDataFieldDescription(this, null, "ROOT", DataType.OTHER, buffer.position() + headerOffset, -1, -1);
}
public static byte getDataType(final DataType dataType) {
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/ClassFieldDescription.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/ClassFieldDescription.java
index 4a69f98a..d0437853 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/ClassFieldDescription.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/ClassFieldDescription.java
@@ -32,7 +32,6 @@ public class ClassFieldDescription implements FieldDescription {
private final int hierarchyDepth;
private final Field field;
private final String fieldName;
- private final int fieldNameHashCode;
private final String fieldNameRelative;
private final String fieldUnit;
private final String fieldDescription;
@@ -102,7 +101,6 @@ protected ClassFieldDescription(final Class> referenceClass, final Field field
if (referenceClass == null) {
this.field = Objects.requireNonNull(field, "field must not be null");
classType = field.getType();
- fieldNameHashCode = field.getName().hashCode();
fieldName = field.getName().intern();
fieldNameRelative = this.parent == null ? fieldName : (this.parent.getFieldNameRelative() + "." + fieldName).intern();
@@ -111,7 +109,6 @@ protected ClassFieldDescription(final Class> referenceClass, final Field field
} else {
this.field = null; // NOPMD it's a root, no field definition available
classType = referenceClass;
- fieldNameHashCode = classType.getName().hashCode();
fieldName = classType.getName().intern();
fieldNameRelative = fieldName;
@@ -201,14 +198,9 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof FieldDescription)) {
+ if (!(obj instanceof FieldDescription other)) {
return false;
}
- final FieldDescription other = (FieldDescription) obj;
- if (this.getFieldNameHashCode() != other.getFieldNameHashCode()) {
- return false;
- }
-
if (this.getDataType() != other.getDataType()) {
return false;
}
@@ -218,18 +210,9 @@ public boolean equals(final Object obj) {
@Override
public FieldDescription findChildField(final String fieldName) {
- return findChildField(fieldName.hashCode(), fieldName);
- }
-
- @Override
- public FieldDescription findChildField(final int fieldNameHashCode, final String fieldName) {
for (final FieldDescription child : children) {
final String name = child.getFieldName();
- //noinspection StringEquality
- if (name == fieldName) { //NOSONAR NOPMD early return if the same String object reference
- return child;
- }
- if (child.getFieldNameHashCode() == fieldNameHashCode && name.equals(fieldName)) {
+ if (name.equals(fieldName)) { // NOSONAR NOPMD early return if the same String object reference
return child;
}
}
@@ -331,11 +314,6 @@ public String getFieldName() {
return fieldName;
}
- @Override
- public int getFieldNameHashCode() {
- return fieldNameHashCode;
- }
-
/**
* @return relative field name within class hierarchy (ie. field_level0.field_level1.variable_0)
*/
@@ -474,11 +452,6 @@ public String getTypeNameSimple() {
return typeNameSimple;
}
- @Override
- public int hashCode() {
- return fieldNameHashCode;
- }
-
/**
* @return the isAbstract
*/
@@ -662,7 +635,7 @@ protected static void exploreClass(final Class> classType, final ClassFieldDes
protected static void printClassStructure(final ClassFieldDescription field, final boolean fullView, final int recursionLevel) {
final String enumOrClass = field.isEnum() ? "Enum " : "class ";
- final String typeCategory = (field.isInterface() ? "interface " : (field.isPrimitive() ? "" : enumOrClass)); //NOSONAR //NOPMD
+ final String typeCategory = (field.isInterface() ? "interface " : (field.isPrimitive() ? "" : enumOrClass)); // NOSONAR //NOPMD
final String typeName = field.getTypeName() + field.getGenericFieldTypeString();
final String mspace = spaces(recursionLevel * ClassUtils.getIndentationNumberOfSpace());
final boolean isSerialisable = field.isSerializable();
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/CmwLightSerialiser.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/CmwLightSerialiser.java
index 5cdc6b7f..6742dff4 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/CmwLightSerialiser.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/CmwLightSerialiser.java
@@ -20,8 +20,8 @@
/**
* Light-weight open-source implementation of a (de-)serialiser that is binary-compatible to the serialiser used by CMW,
- * a proprietary closed-source middle-ware used in some accelerator laboratories.
- *
+ * a proprietary closed-source middleware used in some accelerator laboratories.
+ *
* N.B. this implementation is intended only for performance/functionality comparison and to enable a backward compatible
* transition to the {@link BinarySerialiser} implementation which is a bit more flexible,
* has some additional (optional) features, and a better IO performance. See the corresponding benchmarks for details;
@@ -111,7 +111,7 @@ public CmwLightSerialiser(final IoBuffer buffer) {
public ProtocolInfo checkHeaderInfo() {
final var fieldName = "";
final int dataSize = FastByteBuffer.SIZE_OF_INT;
- final var headerStartField = new WireDataFieldDescription(this, parent, fieldName.hashCode(), fieldName, DataType.START_MARKER, buffer.position(), buffer.position(), dataSize); // NOPMD - needs to be read here
+ final var headerStartField = new WireDataFieldDescription(this, parent, fieldName, DataType.START_MARKER, buffer.position(), buffer.position(), dataSize); // NOPMD - needs to be read here
final var nEntries = buffer.getInt();
if (nEntries <= 0) {
throw new IllegalStateException("nEntries = " + nEntries + " <= 0!");
@@ -216,7 +216,7 @@ public > Enum getEnum(final Enum enumeration) {
try {
final var values = enumClass.getMethod("values");
final Object[] possibleEnumValues = (Object[]) values.invoke(null);
- //noinspection unchecked
+ // noinspection unchecked
return (Enum) possibleEnumValues[ordinal]; // NOSONAR NOPMD
} catch (final ReflectiveOperationException e) {
LOGGER.atError().setCause(e).addArgument(enumClass).log("could not match 'valueOf(String)' function for class/(supposedly) enum of {}");
@@ -268,9 +268,7 @@ public WireDataFieldDescription getFieldHeader() {
throw new IllegalStateException("should not reach here -- format is incompatible with CMW");
}
- final int fieldNameHashCode = fieldName.hashCode(); //TODO: verify same hashcode function
-
- lastFieldHeader = new WireDataFieldDescription(this, parent, fieldNameHashCode, fieldName, dataType, headerStart, dataStartOffset, dataSize);
+ lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName, dataType, headerStart, dataStartOffset, dataSize);
final int dataStartPosition = headerStart + dataStartOffset;
buffer.position(dataStartPosition);
@@ -1014,7 +1012,7 @@ public WireDataFieldDescription putFieldHeader(final FieldDescription fieldDescr
// from hereon there are data specific structures
buffer.ensureAdditionalCapacity(16); // allocate 16+ bytes to account for potential array header (safe-bet)
}
- lastFieldHeader = new WireDataFieldDescription(this, parent, fieldDescription.getFieldNameHashCode(), fieldDescription.getFieldName(), customDataType, headerStart, dataStartOffset, dataSize);
+ lastFieldHeader = new WireDataFieldDescription(this, parent, fieldDescription.getFieldName(), customDataType, headerStart, dataStartOffset, dataSize);
updateDataEntryCount();
return lastFieldHeader;
@@ -1042,8 +1040,7 @@ public WireDataFieldDescription putFieldHeader(final String fieldName, final Dat
buffer.ensureAdditionalCapacity(16); // allocate 16+ bytes to account for potential array header (safe-bet)
}
- final int fieldNameHashCode = fieldName.hashCode(); // TODO: check hashCode function
- lastFieldHeader = new WireDataFieldDescription(this, parent, fieldNameHashCode, fieldName, dataType, headerStart, dataStartOffset, dataSize);
+ lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName, dataType, headerStart, dataStartOffset, dataSize);
updateDataEntryCount();
return lastFieldHeader;
@@ -1054,7 +1051,7 @@ public void putHeaderInfo(final FieldDescription... field) {
parent = lastFieldHeader = getRootElement();
final var fieldName = "";
final int dataSize = FastByteBuffer.SIZE_OF_INT;
- lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName.hashCode(), fieldName, DataType.START_MARKER, buffer.position(), buffer.position(), dataSize);
+ lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName, DataType.START_MARKER, buffer.position(), buffer.position(), dataSize);
buffer.putInt(0);
updateDataEntryCount();
parent = lastFieldHeader;
@@ -1085,7 +1082,7 @@ public void updateDataEndMarker(final WireDataFieldDescription fieldHeader) {
}
private WireDataFieldDescription getRootElement() {
- return new WireDataFieldDescription(this, null, "ROOT".hashCode(), "ROOT", DataType.OTHER, buffer.position(), -1, -1);
+ return new WireDataFieldDescription(this, null, "ROOT", DataType.OTHER, buffer.position(), -1, -1);
}
private void updateDataEntryCount() {
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/FastByteBuffer.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/FastByteBuffer.java
index 734d2831..fec64c78 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/FastByteBuffer.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/FastByteBuffer.java
@@ -17,15 +17,15 @@
/**
* FastByteBuffer implementation based on JVM 'Unsafe' Class. based on:
- * https://mechanical-sympathy.blogspot.com/2012/07/native-cc-like-performance-for-java.html
- * http://java-performance.info/various-methods-of-binary-serialization-in-java/
- *
+ * ...
+ * ...
+ *
* All accesses are range checked, because the performance impact was determined to be negligible.
- *
+ *
* Read operations return "IndexOutOfBoundsException" if there are not enough bytes left in the buffer.
* For primitive types, the check can be done before, but for arrays and strings the size field has to be read first.
* Therefore, the position after a failed non-primitive read is not necessarily the position before the read attempt.
- *
+ *
* When there is not enough space for a write operation, the behaviour depends on the autoRange and byteArrayCache
* variables. If autoRange is false, the operation returns an IndexOutOfBounds exception and the position is set to the
* position before the operation. For Strings there is a worst case space estimate being done, so an operation might
@@ -53,18 +53,24 @@ public class FastByteBuffer implements IoBuffer {
static {
// get an instance of the otherwise private 'Unsafe' class
try {
- @SuppressWarnings("Java9ReflectionClassVisibility")
- Class> cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); // NOSONAR NOPMD
- Field logger = cls.getDeclaredField("logger");
-
final Field field = Unsafe.class.getDeclaredField("theUnsafe");
- field.setAccessible(true); //NOSONAR
+ field.setAccessible(true); // NOSONAR
unsafe = (Unsafe) field.get(null);
- unsafe.putObjectVolatile(cls, unsafe.staticFieldOffset(logger), null);
-
- } catch (NoSuchFieldException | SecurityException | IllegalAccessException | ClassNotFoundException e) { // NOPMD
+ } catch (NoSuchFieldException | IllegalAccessException e) { // NOPMD
+ // If we cannot obtain Unsafe, fail fast as the implementation depends on it
throw new SecurityException(e); // NOPMD
}
+
+ // Best-effort: try to disable IllegalAccessLogger if present on this JDK.
+ // This is optional and should never prevent class initialization.
+ try {
+ Class> cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); // NOSONAR NOPMD
+ Field logger = cls.getDeclaredField("logger");
+ unsafe.putObjectVolatile(cls, unsafe.staticFieldOffset(logger), null);
+ } catch (Throwable t) {
+ // Ignore: class may not exist or may be inaccessible on this JDK (e.g., JDK 21+).
+ // This is purely an optimization to reduce noise; do not break initialization.
+ }
}
private final ReadWriteLock internalLock = new ReentrantReadWriteLock();
@@ -172,7 +178,7 @@ public void ensureCapacity(final int newCapacity) {
if (!autoResize) {
throw new IndexOutOfBoundsException("required capacity: " + newCapacity + " out of bounds: " + capacity() + " and autoResize is disabled");
}
- //TODO: add smarter enlarging algorithm (ie. increase fast for small arrays, + n% for medium sized arrays, byte-by-byte for large arrays)
+ // TODO: add smarter enlarging algorithm (ie. increase fast for small arrays, + n% for medium sized arrays, byte-by-byte for large arrays)
final int addCapacity = Math.min(Math.max(DEFAULT_MIN_CAPACITY_INCREASE, newCapacity >> 3), DEFAULT_MAX_CAPACITY_INCREASE); // min, +12.5%, max
// if we are reading, limit() marks valid data, when writing, position() marks end of valid data, limit() is safe bet because position <= limit
forceCapacity(newCapacity + addCapacity, limit());
@@ -481,7 +487,7 @@ public String[] getStringArray(final String[] dst, final int length) {
public String getStringISO8859() {
final int arraySize = getInt(); // for C++ zero terminated string
checkAvailable(arraySize);
- //alt safe-fallback final String str = new String(buffer, position, arraySize - 1, StandardCharsets.ISO_8859_1)
+ // alt safe-fallback final String str = new String(buffer, position, arraySize - 1, StandardCharsets.ISO_8859_1)
@SuppressWarnings("deprecation")
final String str = new String(buffer, 0, intPos, arraySize - 1); // NOSONAR NOPMD fastest alternative that is public API
// final String str = FastStringBuilder.iso8859BytesToString(buffer, position, arraySize - 1)
@@ -918,7 +924,7 @@ private static void copyMemory(final Object srcBase, final int srcOffset, final
// Fast UTF-8 byte-array to String(Builder) decode - code originally based on Google's ProtoBuffer implementation and since modified
@SuppressWarnings("PMD")
- private static void decodeUTF8(byte[] bytes, int offset, int size, StringBuilder result) { //NOSONAR
+ private static void decodeUTF8(byte[] bytes, int offset, int size, StringBuilder result) { // NOSONAR
// Bitwise OR combines the sign bits so any negative value fails the check.
// N.B. many code snippets are in-lined for performance reasons (~10% performance improvement) ... this is a JIT hot spot.
if ((offset | size | bytes.length - offset - size) < 0) {
@@ -987,7 +993,7 @@ private static void decodeUTF8(byte[] bytes, int offset, int size, StringBuilder
final byte byte3 = unsafe.getByte(bytes, readPos++);
final int resultPos1 = resultPos++;
if (byte2 > (byte) 0xBF // is not trailing byte
- // overlong? 5 most significant bits must not all be zero
+ // overlong? 5 most significant bits must not all be zero
|| (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
// check for illegal surrogate codepoints
|| (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
@@ -1043,7 +1049,7 @@ private static int encodeISO8859(final String sequence, final byte[] bytes, fina
// Fast UTF-8 String (CharSequence) to byte-array encoder - code originally based on Google's ProtoBuffer implementation and since modified
@SuppressWarnings("PMD")
- private static int encodeUTF8(final CharSequence sequence, final byte[] bytes, final int offset, final int length) { //NOSONAR
+ private static int encodeUTF8(final CharSequence sequence, final byte[] bytes, final int offset, final int length) { // NOSONAR
int utf16Length = sequence.length();
int base = ARRAY_BYTE_BASE_OFFSET + offset;
int i = 0;
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/Field.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/Field.java
index 98a4a648..1e9827ae 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/Field.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/Field.java
@@ -225,72 +225,100 @@ public short getShort(final Object classReference) {
}
}
- /** @return {@code Class} object that identifies the declared type for this {@code Field} object. */
+ /**
+ * @return {@code Class} object that identifies the declared type for this {@code Field} object.
+ */
public final Class> getType() {
return jdkField.getType();
}
- /** @return {@code true} if the field is defined with the {@code abstract} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code abstract} modifier, {@code false} otherwise.
+ */
public final boolean isAbstract() {
return Modifier.isAbstract(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code final} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code final} modifier, {@code false} otherwise.
+ */
public final boolean isFinal() {
return Modifier.isFinal(jdkField.getModifiers());
}
- /** @return @return {@code true} if the field is defined with the {@code native} modifier, {@code false} otherwise. */
+ /**
+ * @return @return {@code true} if the field is defined with the {@code native} modifier, {@code false} otherwise.
+ */
public final boolean isNative() {
return Modifier.isNative(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code private} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code private} modifier, {@code false} otherwise.
+ */
public final boolean isPackagePrivate() {
return !isPrivate() && !isProtected() && !isPublic();
}
- /** @return {@code true} if the field is a primitive (e.g. boolean, int, .., float, double value, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is a primitive (e.g. boolean, int, .., float, double value, {@code false} otherwise.
+ */
public final boolean isPrimitive() {
return primitive;
}
- /** @return {@code true} if the field is defined with the {@code private} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code private} modifier, {@code false} otherwise.
+ */
public final boolean isPrivate() {
return Modifier.isPrivate(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code protected} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code protected} modifier, {@code false} otherwise.
+ */
public final boolean isProtected() {
return Modifier.isProtected(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code public} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code public} modifier, {@code false} otherwise.
+ */
public final boolean isPublic() {
return Modifier.isPublic(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code static} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code static} modifier, {@code false} otherwise.
+ */
public final boolean isStatic() {
return Modifier.isStatic(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code strictfp} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code strictfp} modifier, {@code false} otherwise.
+ */
public final boolean isStrict() {
return Modifier.isStrict(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code synchronised} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code synchronised} modifier, {@code false} otherwise.
+ */
public final boolean isSynchronized() {
return Modifier.isSynchronized(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code transient} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code transient} modifier, {@code false} otherwise.
+ */
public final boolean isTransient() {
return Modifier.isTransient(jdkField.getModifiers());
}
- /** @return {@code true} if the field is defined with the {@code volatile} modifier, {@code false} otherwise. */
+ /**
+ * @return {@code true} if the field is defined with the {@code volatile} modifier, {@code false} otherwise.
+ */
public final boolean isVolatile() {
return Modifier.isVolatile(jdkField.getModifiers());
}
@@ -478,12 +506,12 @@ public T getAnnotation(@NotNull final Class annotation
}
@Override
- public final Annotation[] getAnnotations() {
+ public final Annotation @NotNull[] getAnnotations() {
return getDeclaredAnnotations();
}
@Override
- public Annotation[] getDeclaredAnnotations() {
+ public Annotation @NotNull[] getDeclaredAnnotations() {
if (declaredAnnotations == null) {
declaredAnnotations = jdkField.getDeclaredAnnotations();
}
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/JsonSerialiser.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/JsonSerialiser.java
index ef7ac1ad..6b82acd5 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/JsonSerialiser.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/JsonSerialiser.java
@@ -35,7 +35,7 @@ public class JsonSerialiser implements IoSerialiser {
public static final char QUOTE = '\"';
private static final String NULL = "null";
private static final String ASSIGN = ": ";
- private static final String LINE_BREAK = System.getProperty("line.separator");
+ private static final String LINE_BREAK = System.lineSeparator();
public static final String UNCHECKED = "unchecked";
private final StringBuilder builder = new StringBuilder(DEFAULT_INITIAL_CAPACITY); // NOPMD
private IoBuffer buffer;
@@ -56,10 +56,10 @@ public JsonSerialiser(final IoBuffer buffer) {
this.buffer = buffer;
// JsonStream.setIndentionStep(DEFAULT_INDENTATION)
- // JsonStream.setMode(EncodingMode.REFLECTION_MODE) -- enable as a fall back
- // JsonIterator.setMode(DecodingMode.REFLECTION_MODE) -- enable as a fall back
- JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
- JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
+ JsonStream.setMode(EncodingMode.REFLECTION_MODE); // enable as a fall-back
+ JsonIterator.setMode(DecodingMode.REFLECTION_MODE); // enable as a fall-back
+ // JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
+ // JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
try {
PreciseFloatSupport.enable();
@@ -86,7 +86,7 @@ public ProtocolInfo checkHeaderInfo() {
throw new IllegalStateException(NOT_A_JSON_COMPATIBLE_PROTOCOL, e);
}
- final WireDataFieldDescription headerStartField = new WireDataFieldDescription(this, null, JSON_ROOT.hashCode(), JSON_ROOT, DataType.OTHER, buffer.position(), count - 1, -1);
+ final WireDataFieldDescription headerStartField = new WireDataFieldDescription(this, null, JSON_ROOT, DataType.OTHER, buffer.position(), count - 1, -1);
final ProtocolInfo header = new ProtocolInfo(this, headerStartField, JsonSerialiser.class.getCanonicalName(), (byte) 1, (byte) 0, (byte) 0);
parent = lastFieldHeader = headerStartField;
queryFieldName = JSON_ROOT;
@@ -271,7 +271,7 @@ public WireDataFieldDescription parseIoStream(final boolean readHeader) {
iter.reset(buffer.elements(), 0, buffer.limit());
tempRoot = root = iter.readAny();
- final WireDataFieldDescription fieldRoot = new WireDataFieldDescription(this, null, "ROOT".hashCode(), "ROOT", DataType.OTHER, buffer.position(), -1, -1);
+ final WireDataFieldDescription fieldRoot = new WireDataFieldDescription(this, null, "ROOT", DataType.OTHER, buffer.position(), -1, -1);
parseIoStream(fieldRoot, tempRoot, "");
return fieldRoot;
@@ -795,14 +795,14 @@ public WireDataFieldDescription putFieldHeader(final FieldDescription fieldDescr
@Override
public WireDataFieldDescription putFieldHeader(final String fieldName, final DataType dataType) {
- lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName.hashCode(), fieldName, dataType, -1, 1, -1);
+ lastFieldHeader = new WireDataFieldDescription(this, parent, fieldName, dataType, -1, 1, -1);
queryFieldName = fieldName;
return lastFieldHeader;
}
@Override
public void putHeaderInfo(final FieldDescription... field) {
- if (builder.length() > 0) {
+ if (!builder.isEmpty()) {
final byte[] outputStrBytes = builder.toString().getBytes(StandardCharsets.UTF_8);
buffer.ensureAdditionalCapacity(outputStrBytes.length);
System.arraycopy(outputStrBytes, 0, buffer.elements(), buffer.position(), outputStrBytes.length);
@@ -829,7 +829,7 @@ public void putStartMarker(final FieldDescription fieldDescription) {
}
public void serialiseObject(final Object obj) {
- if (builder.length() > 0) {
+ if (!builder.isEmpty()) {
final byte[] outputStrBytes = builder.toString().getBytes(StandardCharsets.UTF_8);
buffer.ensureAdditionalCapacity(outputStrBytes.length);
System.arraycopy(outputStrBytes, 0, buffer.elements(), buffer.position(), outputStrBytes.length);
@@ -906,7 +906,7 @@ private void parseIoStream(final WireDataFieldDescription fieldRoot, final Any a
}
final Map map = any.asMap();
- final WireDataFieldDescription putStartMarker = new WireDataFieldDescription(this, fieldRoot, fieldName.hashCode(), fieldName, DataType.START_MARKER, 0, -1, -1);
+ final WireDataFieldDescription putStartMarker = new WireDataFieldDescription(this, fieldRoot, fieldName, DataType.START_MARKER, 0, -1, -1);
for (Map.Entry child : map.entrySet()) {
final String childName = child.getKey();
final Any childAny = map.get(childName);
@@ -914,7 +914,7 @@ private void parseIoStream(final WireDataFieldDescription fieldRoot, final Any a
if (data instanceof Map) {
parseIoStream(putStartMarker, childAny, childName);
} else if (data != null) {
- new WireDataFieldDescription(this, putStartMarker, childName.hashCode(), childName, DataType.fromClassType(data.getClass()), 0, -1, -1); // NOPMD - necessary to allocate inside loop
+ new WireDataFieldDescription(this, putStartMarker, childName, DataType.fromClassType(data.getClass()), 0, -1, -1); // NOPMD - necessary to allocate inside loop
}
}
// add if necessary:
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/ProtocolInfo.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/ProtocolInfo.java
index ef2515f1..295253fe 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/ProtocolInfo.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/ProtocolInfo.java
@@ -10,7 +10,7 @@ public class ProtocolInfo extends WireDataFieldDescription {
private final byte versionMicro;
public ProtocolInfo(final IoSerialiser source, final WireDataFieldDescription fieldDescription, final String producer, final byte major, final byte minor, final byte micro) {
- super(source, null, fieldDescription.hashCode(), fieldDescription.getFieldName(), fieldDescription.getDataType(), fieldDescription.getFieldStart(), fieldDescription.getDataStartOffset(), fieldDescription.getDataSize());
+ super(source, null, fieldDescription.getFieldName(), fieldDescription.getDataType(), fieldDescription.getFieldStart(), fieldDescription.getDataStartOffset(), fieldDescription.getDataSize());
this.fieldHeader = fieldDescription;
producerName = producer;
versionMajor = major;
@@ -20,10 +20,9 @@ public ProtocolInfo(final IoSerialiser source, final WireDataFieldDescription fi
@Override
public boolean equals(final Object obj) {
- if (!(obj instanceof ProtocolInfo)) {
+ if (!(obj instanceof ProtocolInfo other)) {
return false;
}
- final ProtocolInfo other = (ProtocolInfo) obj;
return other.isCompatible();
}
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/WireDataFieldDescription.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/WireDataFieldDescription.java
index 7cc8ee9f..db225f38 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/WireDataFieldDescription.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/WireDataFieldDescription.java
@@ -14,13 +14,12 @@
/**
* Field header descriptor
- *
+ *
* @author rstein
*/
public class WireDataFieldDescription implements FieldDescription {
private static final Logger LOGGER = LoggerFactory.getLogger(WireDataFieldDescription.class);
private final String fieldName;
- private final int fieldNameHashCode;
private final DataType dataType;
private final List children = new ArrayList<>();
private final FieldDescription parent;
@@ -40,20 +39,16 @@ public class WireDataFieldDescription implements FieldDescription {
*
* @param source the referenced IoBuffer (if any)
* @param parent the optional parent field header (for cascaded objects)
- * @param fieldNameHashCode the fairly-unique hash-code of the field name,
- * N.B. checked during 1st iteration against fieldName, if no collisions are present then
- * this check is being suppressed
* @param fieldName the clear text field name description
* @param dataType the data type of that field
* @param fieldStart the absolute buffer position from which the field header can be parsed
* @param dataStartOffset the position from which the actual data can be parsed onwards
* @param dataSize the expected number of bytes to skip the data block
*/
- public WireDataFieldDescription(final IoSerialiser source, final FieldDescription parent, final int fieldNameHashCode, final String fieldName, final DataType dataType, //
+ public WireDataFieldDescription(final IoSerialiser source, final FieldDescription parent, final String fieldName, final DataType dataType, //
final int fieldStart, final int dataStartOffset, final int dataSize) {
ioSerialiser = source;
this.parent = parent;
- this.fieldNameHashCode = fieldNameHashCode;
this.fieldName = fieldName;
this.dataType = dataType;
this.fieldStart = fieldStart;
@@ -71,14 +66,9 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof FieldDescription)) {
+ if (!(obj instanceof FieldDescription other)) {
return false;
}
- FieldDescription other = (FieldDescription) obj;
- if (this.getFieldNameHashCode() != other.getFieldNameHashCode()) {
- return false;
- }
-
if (this.getDataType() != other.getDataType()) {
return false;
}
@@ -88,18 +78,10 @@ public boolean equals(final Object obj) {
@Override
public FieldDescription findChildField(final String fieldName) {
- return findChildField(fieldName.hashCode(), fieldName);
- }
-
- @Override
- public FieldDescription findChildField(final int fieldNameHashCode, final String fieldName) {
- for (final FieldDescription field : children) { //NOSONAR
- final String name = field.getFieldName();
- if (name == fieldName) { // NOSONAR NOPMD early return if the same String object reference
- return field;
- }
- if (field.hashCode() == fieldNameHashCode && name.equals(fieldName)) {
- return field;
+ for (final FieldDescription child : children) {
+ final String name = child.getFieldName();
+ if (name.equals(fieldName)) { // NOSONAR NOPMD early return if the same String object reference
+ return child;
}
}
return null;
@@ -166,11 +148,6 @@ public String getFieldName() {
return fieldName;
}
- @Override
- public int getFieldNameHashCode() {
- return fieldNameHashCode;
- }
-
@Override
public int getFieldStart() {
return fieldStart;
@@ -192,63 +169,35 @@ public void setFieldUnit(final String fieldUnit) {
*/
public Object data(DataType... overwriteType) {
ioSerialiser.setQueryFieldName(fieldName, fieldDataStart);
- switch (overwriteType.length == 0 ? this.dataType : overwriteType[0]) {
- case START_MARKER:
- case END_MARKER:
- return null;
- case BOOL:
- return ioSerialiser.getBoolean();
- case BYTE:
- return ioSerialiser.getByte();
- case SHORT:
- return ioSerialiser.getShort();
- case INT:
- return ioSerialiser.getInt();
- case LONG:
- return ioSerialiser.getLong();
- case FLOAT:
- return ioSerialiser.getFloat();
- case DOUBLE:
- return ioSerialiser.getDouble();
- case CHAR:
- return ioSerialiser.getChar();
- case STRING:
- return ioSerialiser.getString();
- case BOOL_ARRAY:
- return ioSerialiser.getBooleanArray();
- case BYTE_ARRAY:
- return ioSerialiser.getByteArray();
- case SHORT_ARRAY:
- return ioSerialiser.getShortArray();
- case INT_ARRAY:
- return ioSerialiser.getIntArray();
- case LONG_ARRAY:
- return ioSerialiser.getLongArray();
- case FLOAT_ARRAY:
- return ioSerialiser.getFloatArray();
- case DOUBLE_ARRAY:
- return ioSerialiser.getDoubleArray();
- case CHAR_ARRAY:
- return ioSerialiser.getCharArray();
- case STRING_ARRAY:
- return ioSerialiser.getStringArray();
- case ENUM:
- return ioSerialiser.getEnum(null);
- case LIST:
- return ioSerialiser.getList(null);
- case MAP:
- return ioSerialiser.getMap(null);
- case QUEUE:
- return ioSerialiser.getQueue(null);
- case SET:
- return ioSerialiser.getSet(null);
- case COLLECTION:
- return ioSerialiser.getCollection(null);
- case OTHER:
- return ioSerialiser.getCustomData(null);
- default:
- throw new IllegalStateException("unknown dataType = " + dataType);
- }
+ return switch (overwriteType.length == 0 ? this.dataType : overwriteType[0]) {
+ case START_MARKER, END_MARKER -> null;
+ case BOOL -> ioSerialiser.getBoolean();
+ case BYTE -> ioSerialiser.getByte();
+ case SHORT -> ioSerialiser.getShort();
+ case INT -> ioSerialiser.getInt();
+ case LONG -> ioSerialiser.getLong();
+ case FLOAT -> ioSerialiser.getFloat();
+ case DOUBLE -> ioSerialiser.getDouble();
+ case CHAR -> ioSerialiser.getChar();
+ case STRING -> ioSerialiser.getString();
+ case BOOL_ARRAY -> ioSerialiser.getBooleanArray();
+ case BYTE_ARRAY -> ioSerialiser.getByteArray();
+ case SHORT_ARRAY -> ioSerialiser.getShortArray();
+ case INT_ARRAY -> ioSerialiser.getIntArray();
+ case LONG_ARRAY -> ioSerialiser.getLongArray();
+ case FLOAT_ARRAY -> ioSerialiser.getFloatArray();
+ case DOUBLE_ARRAY -> ioSerialiser.getDoubleArray();
+ case CHAR_ARRAY -> ioSerialiser.getCharArray();
+ case STRING_ARRAY -> ioSerialiser.getStringArray();
+ case ENUM -> ioSerialiser.getEnum(null);
+ case LIST -> ioSerialiser.getList(null);
+ case MAP -> ioSerialiser.getMap(null);
+ case QUEUE -> ioSerialiser.getQueue(null);
+ case SET -> ioSerialiser.getSet(null);
+ case COLLECTION -> ioSerialiser.getCollection(null);
+ case OTHER -> ioSerialiser.getCustomData(null);
+ default -> throw new IllegalStateException("unknown dataType = " + dataType);
+ };
}
/**
@@ -268,11 +217,6 @@ public Class> getType() {
return dataType.getClassTypes().get(0);
}
- @Override
- public int hashCode() {
- return fieldNameHashCode;
- }
-
@Override
public boolean isAnnotationPresent() {
return fieldUnit != null || fieldDescription != null || fieldDirection != null || (fieldGroups != null && !fieldGroups.isEmpty());
diff --git a/serialiser/src/main/java/io/opencmw/serialiser/spi/iobuffer/DataSetSerialiser.java b/serialiser/src/main/java/io/opencmw/serialiser/spi/iobuffer/DataSetSerialiser.java
index 0768e371..68d4750c 100644
--- a/serialiser/src/main/java/io/opencmw/serialiser/spi/iobuffer/DataSetSerialiser.java
+++ b/serialiser/src/main/java/io/opencmw/serialiser/spi/iobuffer/DataSetSerialiser.java
@@ -30,9 +30,9 @@
* Class to efficiently serialise and de-serialise DataSet objects into binary byte arrays. The performance can be tuned
* through:
*
- * - using floats (ie. memory-IO vs network-IO bound serialisation), or
+ * - using floats (i.e. memory-IO vs network-IO bound serialisation), or
* - via {@link #setDataLablesSerialised(boolean)} (default: true) to control whether data labels and styles shall be processed
- * - via {@link #setMetaDataSerialised(boolean)} (default: true) to control whether meta data shall be processed
+ * - via {@link #setMetaDataSerialised(boolean)} (default: true) to control whether metadata shall be processed
*
*
* @author rstein
@@ -147,7 +147,7 @@ public void write(final DataSet dataSet, final boolean asFloat) {
AssertUtils.notNull("dataSet", dataSet);
AssertUtils.notNull("ioSerialiser", ioSerialiser);
final String dataStartMarkerName = "START_MARKER_DATASET:" + dataSet.getName();
- final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.OTHER, -1, -1, -1);
+ final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.OTHER, -1, -1, -1);
ioSerialiser.putStartMarker(dataStartMarker);
writeHeaderDataToStream(dataSet);
@@ -168,12 +168,12 @@ public void write(final DataSet dataSet, final boolean asFloat) {
}
final String dataEndMarkerName = "END_MARKER_DATASET:" + dataSet.getName();
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker);
}
protected FieldDescription checkFieldCompatibility(final FieldDescription rootField, final int fieldNameHashCode, final String fieldName, final DataType... requireDataTypes) {
- FieldDescription fieldHeader = rootField.findChildField(fieldNameHashCode, fieldName);
+ FieldDescription fieldHeader = rootField.findChildField(fieldName);
if (fieldHeader == null) {
return null;
}
@@ -203,28 +203,18 @@ protected static int getDimIndex(String fieldName, String prefix) {
}
protected static double[] getDoubleArray(final IoSerialiser ioSerialiser, final double[] origArray, final DataType dataType) {
- switch (dataType) {
- case BOOL_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getBooleanArray());
- case BYTE_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getByteArray());
- case SHORT_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getShortArray());
- case INT_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getIntArray());
- case LONG_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getLongArray());
- case FLOAT_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getFloatArray());
- case DOUBLE_ARRAY:
- return ioSerialiser.getDoubleArray(origArray);
- case CHAR_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getCharArray());
- case STRING_ARRAY:
- return GenericsHelper.toDoublePrimitive(ioSerialiser.getStringArray());
- default:
- throw new IllegalArgumentException("dataType '" + dataType + "' is not an array");
- }
+ return switch (dataType) {
+ case BOOL_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getBooleanArray());
+ case BYTE_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getByteArray());
+ case SHORT_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getShortArray());
+ case INT_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getIntArray());
+ case LONG_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getLongArray());
+ case FLOAT_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getFloatArray());
+ case DOUBLE_ARRAY -> ioSerialiser.getDoubleArray(origArray);
+ case CHAR_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getCharArray());
+ case STRING_ARRAY -> GenericsHelper.toDoublePrimitive(ioSerialiser.getStringArray());
+ default -> throw new IllegalArgumentException("dataType '" + dataType + "' is not an array");
+ };
}
protected void parseDataLabels(final DataSetBuilder builder, final FieldDescription fieldRoot) {
@@ -253,266 +243,260 @@ protected void parseHeaders(final IoSerialiser ioSerialiser, final DataSetBuilde
// check for axis descriptions (all fields starting with AXIS)
for (FieldDescription fieldDescription : fieldRoot.getChildren()) {
- parseHeader(ioSerialiser, builder, fieldDescription);
- }
- }
+ parseHeader(ioSerialiser, builder, fieldDescription);
+ }
+ }
- protected void parseMetaData(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final FieldDescription rootField) {
- if (checkFieldCompatibility(rootField, INFO_LIST.hashCode(), INFO_LIST, DataType.STRING_ARRAY) != null) {
- builder.setMetaInfoList(ioSerialiser.getStringArray());
- }
+ protected void parseMetaData(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final FieldDescription rootField) {
+ if (checkFieldCompatibility(rootField, INFO_LIST.hashCode(), INFO_LIST, DataType.STRING_ARRAY) != null) {
+ builder.setMetaInfoList(ioSerialiser.getStringArray());
+ }
- if (checkFieldCompatibility(rootField, WARNING_LIST.hashCode(), WARNING_LIST, DataType.STRING_ARRAY) != null) {
- builder.setMetaWarningList(ioSerialiser.getStringArray());
- }
+ if (checkFieldCompatibility(rootField, WARNING_LIST.hashCode(), WARNING_LIST, DataType.STRING_ARRAY) != null) {
+ builder.setMetaWarningList(ioSerialiser.getStringArray());
+ }
- if (checkFieldCompatibility(rootField, ERROR_LIST.hashCode(), ERROR_LIST, DataType.STRING_ARRAY) != null) {
- builder.setMetaErrorList(ioSerialiser.getStringArray());
- }
+ if (checkFieldCompatibility(rootField, ERROR_LIST.hashCode(), ERROR_LIST, DataType.STRING_ARRAY) != null) {
+ builder.setMetaErrorList(ioSerialiser.getStringArray());
+ }
- if (checkFieldCompatibility(rootField, META_INFO.hashCode(), META_INFO, DataType.MAP) != null) {
- Map map = new HashMap<>(); // NOPMD - thread-safe usage
- map = ioSerialiser.getMap(map);
- builder.setMetaInfoMap(map);
- }
- }
-
- protected void parseNumericData(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, final FieldDescription rootField) {
- // check for numeric data
- for (FieldDescription fieldDescription : rootField.getChildren()) {
- final String fieldName = fieldDescription.getFieldName();
- if (fieldName == null || (fieldDescription.getDataType() != DataType.DOUBLE_ARRAY && fieldDescription.getDataType() != DataType.FLOAT_ARRAY)) {
- continue;
+ if (checkFieldCompatibility(rootField, META_INFO.hashCode(), META_INFO, DataType.MAP) != null) {
+ Map map = new HashMap<>(); // NOPMD - thread-safe usage
+ map = ioSerialiser.getMap(map);
+ builder.setMetaInfoMap(map);
+ }
}
- if (fieldName.startsWith(ARRAY_PREFIX)) {
- readValues(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
- } else if (fieldName.startsWith(EP_PREFIX)) {
- readPosError(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
- } else if (fieldName.startsWith(EN_PREFIX)) {
- readNegError(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
- }
- }
- }
- @SuppressWarnings("PMD.NPathComplexity")
- protected void writeDataLabelsToStream(final DataSet dataSet) {
- if (dataSet instanceof AbstractDataSet) {
- final StringHashMapList labelMap = ((AbstractDataSet>) dataSet).getDataLabelMap();
- if (!labelMap.isEmpty()) {
- ioSerialiser.put(DATA_LABELS, labelMap, Integer.class, String.class);
- }
- final StringHashMapList styleMap = ((AbstractDataSet>) dataSet).getDataStyleMap();
- if (!styleMap.isEmpty()) {
- ioSerialiser.put(DATA_STYLES, styleMap, Integer.class, String.class);
+ protected void parseNumericData(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, final FieldDescription rootField) {
+ // check for numeric data
+ for (FieldDescription fieldDescription : rootField.getChildren()) {
+ final String fieldName = fieldDescription.getFieldName();
+ if (fieldName == null || (fieldDescription.getDataType() != DataType.DOUBLE_ARRAY && fieldDescription.getDataType() != DataType.FLOAT_ARRAY)) {
+ continue;
+ }
+ if (fieldName.startsWith(ARRAY_PREFIX)) {
+ readValues(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
+ } else if (fieldName.startsWith(EP_PREFIX)) {
+ readPosError(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
+ } else if (fieldName.startsWith(EN_PREFIX)) {
+ readNegError(ioSerialiser, builder, origDataSet, fieldDescription, fieldName);
+ }
+ }
}
- return;
- }
- final int dataCount = dataSet.getDataCount();
- final Map labelMap = new HashMap<>(); // NOPMD - protected by lock and faster
- for (int index = 0; index < dataCount; index++) {
- final String label = dataSet.getDataLabel(index);
- if ((label != null) && !label.isEmpty()) {
- labelMap.put(index, label);
+ @SuppressWarnings("PMD.NPathComplexity")
+ protected void writeDataLabelsToStream(final DataSet dataSet) {
+ if (dataSet instanceof AbstractDataSet) {
+ final StringHashMapList labelMap = ((AbstractDataSet>) dataSet).getDataLabelMap();
+ if (!labelMap.isEmpty()) {
+ ioSerialiser.put(DATA_LABELS, labelMap, Integer.class, String.class);
+ }
+ final StringHashMapList styleMap = ((AbstractDataSet>) dataSet).getDataStyleMap();
+ if (!styleMap.isEmpty()) {
+ ioSerialiser.put(DATA_STYLES, styleMap, Integer.class, String.class);
+ }
+ return;
+ }
+
+ final int dataCount = dataSet.getDataCount();
+ final Map labelMap = new HashMap<>(); // NOPMD - protected by lock and faster
+ for (int index = 0; index < dataCount; index++) {
+ final String label = dataSet.getDataLabel(index);
+ if ((label != null) && !label.isEmpty()) {
+ labelMap.put(index, label);
+ }
+ }
+ if (!labelMap.isEmpty()) {
+ ioSerialiser.put(DATA_LABELS, labelMap, Integer.class, String.class);
+ }
+
+ final Map styleMap = new HashMap<>(); // NOPMD - protected by lock and faster
+ for (int index = 0; index < dataCount; index++) {
+ final String style = dataSet.getStyle(index);
+ if ((style != null) && !style.isEmpty()) {
+ styleMap.put(index, style);
+ }
+ }
+ if (!styleMap.isEmpty()) {
+ ioSerialiser.put(DATA_STYLES, styleMap, Integer.class, String.class);
+ }
}
- }
- if (!labelMap.isEmpty()) {
- ioSerialiser.put(DATA_LABELS, labelMap, Integer.class, String.class);
- }
- final Map styleMap = new HashMap<>(); // NOPMD - protected by lock and faster
- for (int index = 0; index < dataCount; index++) {
- final String style = dataSet.getStyle(index);
- if ((style != null) && !style.isEmpty()) {
- styleMap.put(index, style);
+ protected void writeHeaderDataToStream(final DataSet dataSet) {
+ // common header data
+ ioSerialiser.put(DATA_SET_NAME, dataSet.getName());
+ ioSerialiser.put(DIMENSIONS, dataSet.getDimension());
+ final List axisDescriptions = dataSet.getAxisDescriptions();
+ StringBuilder builder = new StringBuilder(60);
+ for (int i = 0; i < axisDescriptions.size(); i++) {
+ builder.setLength(0);
+ final String prefix = builder.append(AXIS).append(i).append('.').toString();
+ builder.setLength(0);
+ final String name = builder.append(prefix).append(NAME).toString();
+ builder.setLength(0);
+ final String unit = builder.append(prefix).append(UNIT).toString();
+ builder.setLength(0);
+ final String minName = builder.append(prefix).append(MIN).toString();
+ builder.setLength(0);
+ final String maxName = builder.append(prefix).append(MAX).toString();
+
+ ioSerialiser.put(name, dataSet.getAxisDescription(i).getName());
+ ioSerialiser.put(unit, dataSet.getAxisDescription(i).getUnit());
+ ioSerialiser.put(minName, dataSet.getAxisDescription(i).getMin());
+ ioSerialiser.put(maxName, dataSet.getAxisDescription(i).getMax());
+ }
}
- }
- if (!styleMap.isEmpty()) {
- ioSerialiser.put(DATA_STYLES, styleMap, Integer.class, String.class);
- }
- }
-
- protected void writeHeaderDataToStream(final DataSet dataSet) {
- // common header data
- ioSerialiser.put(DATA_SET_NAME, dataSet.getName());
- ioSerialiser.put(DIMENSIONS, dataSet.getDimension());
- final List axisDescriptions = dataSet.getAxisDescriptions();
- StringBuilder builder = new StringBuilder(60);
- for (int i = 0; i < axisDescriptions.size(); i++) {
- builder.setLength(0);
- final String prefix = builder.append(AXIS).append(i).append('.').toString();
- builder.setLength(0);
- final String name = builder.append(prefix).append(NAME).toString();
- builder.setLength(0);
- final String unit = builder.append(prefix).append(UNIT).toString();
- builder.setLength(0);
- final String minName = builder.append(prefix).append(MIN).toString();
- builder.setLength(0);
- final String maxName = builder.append(prefix).append(MAX).toString();
-
- ioSerialiser.put(name, dataSet.getAxisDescription(i).getName());
- ioSerialiser.put(unit, dataSet.getAxisDescription(i).getUnit());
- ioSerialiser.put(minName, dataSet.getAxisDescription(i).getMin());
- ioSerialiser.put(maxName, dataSet.getAxisDescription(i).getMax());
- }
- }
-
- protected void writeMetaDataToStream(final DataSet dataSet) {
- if (!(dataSet instanceof DataSetMetaData)) {
- return;
- }
- final DataSetMetaData metaDataSet = (DataSetMetaData) dataSet;
- ioSerialiser.put(INFO_LIST, metaDataSet.getInfoList().toArray(new String[0]));
- ioSerialiser.put(WARNING_LIST, metaDataSet.getWarningList().toArray(new String[0]));
- ioSerialiser.put(ERROR_LIST, metaDataSet.getErrorList().toArray(new String[0]));
- ioSerialiser.put(META_INFO, metaDataSet.getMetaInfo(), String.class, String.class);
- }
+ protected void writeMetaDataToStream(final DataSet dataSet) {
+ if (!(dataSet instanceof DataSetMetaData metaDataSet)) {
+ return;
+ }
- /**
- * @param dataSet to be exported
- */
- protected void writeNumericBinaryDataToBufferDouble(final DataSet dataSet) {
- final int nDim = dataSet.getDimension();
- if (dataSet instanceof GridDataSet) {
- GridDataSet gridDataSet = (GridDataSet) dataSet;
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final boolean gridDimension = dimIndex < gridDataSet.getNGrid();
- final int nsamples = gridDimension ? gridDataSet.getShape(dimIndex) : dataSet.getDataCount();
- final double[] values = gridDimension ? gridDataSet.getGridValues(dimIndex) : dataSet.getValues(dimIndex);
- ioSerialiser.put(ARRAY_PREFIX + dimIndex, values, nsamples);
+ ioSerialiser.put(INFO_LIST, metaDataSet.getInfoList().toArray(new String[0]));
+ ioSerialiser.put(WARNING_LIST, metaDataSet.getWarningList().toArray(new String[0]));
+ ioSerialiser.put(ERROR_LIST, metaDataSet.getErrorList().toArray(new String[0]));
+ ioSerialiser.put(META_INFO, metaDataSet.getMetaInfo(), String.class, String.class);
}
- return; // GridDataSet does not provide errors
- }
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final int nsamples = dataSet.getDataCount();
- ioSerialiser.put(ARRAY_PREFIX + dimIndex, dataSet.getValues(dimIndex), nsamples);
- }
- if (!(dataSet instanceof DataSetError)) {
- return; // data set does not have any error definition
- }
- final DataSetError ds = (DataSetError) dataSet;
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final int nsamples = dataSet.getDataCount();
- switch (ds.getErrorType(dimIndex)) {
- case SYMMETRIC:
- ioSerialiser.put(EP_PREFIX + dimIndex, ds.getErrorsPositive(dimIndex), nsamples);
- break;
- case ASYMMETRIC:
- ioSerialiser.put(EN_PREFIX + dimIndex, ds.getErrorsNegative(dimIndex), nsamples);
- ioSerialiser.put(EP_PREFIX + dimIndex, ds.getErrorsPositive(dimIndex), nsamples);
- break;
- case NO_ERROR:
- default:
- break;
- }
- }
- }
- /**
- * @param dataSet to be exported
- */
- protected void writeNumericBinaryDataToBufferFloat(final DataSet dataSet) {
- final int nDim = dataSet.getDimension();
- if (dataSet instanceof GridDataSet) {
- GridDataSet gridDataSet = (GridDataSet) dataSet;
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final boolean gridDimension = dimIndex < gridDataSet.getNGrid();
- final int nsamples = gridDimension ? gridDataSet.getShape(dimIndex) : dataSet.getDataCount();
- final float[] values = MathUtils.toFloats(gridDimension ? gridDataSet.getGridValues(dimIndex) : dataSet.getValues(dimIndex));
- ioSerialiser.put(ARRAY_PREFIX + dimIndex, values, nsamples);
+ /**
+ * @param dataSet to be exported
+ */
+ protected void writeNumericBinaryDataToBufferDouble(final DataSet dataSet) {
+ final int nDim = dataSet.getDimension();
+ if (dataSet instanceof GridDataSet gridDataSet) {
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final boolean gridDimension = dimIndex < gridDataSet.getNGrid();
+ final int nsamples = gridDimension ? gridDataSet.getShape(dimIndex) : dataSet.getDataCount();
+ final double[] values = gridDimension ? gridDataSet.getGridValues(dimIndex) : dataSet.getValues(dimIndex);
+ ioSerialiser.put(ARRAY_PREFIX + dimIndex, values, nsamples);
+ }
+ return; // GridDataSet does not provide errors
+ }
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final int nsamples = dataSet.getDataCount();
+ ioSerialiser.put(ARRAY_PREFIX + dimIndex, dataSet.getValues(dimIndex), nsamples);
+ }
+ if (!(dataSet instanceof DataSetError ds)) {
+ return; // data set does not have any error definition
+ }
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final int nsamples = dataSet.getDataCount();
+ switch (ds.getErrorType(dimIndex)) {
+ case SYMMETRIC:
+ ioSerialiser.put(EP_PREFIX + dimIndex, ds.getErrorsPositive(dimIndex), nsamples);
+ break;
+ case ASYMMETRIC:
+ ioSerialiser.put(EN_PREFIX + dimIndex, ds.getErrorsNegative(dimIndex), nsamples);
+ ioSerialiser.put(EP_PREFIX + dimIndex, ds.getErrorsPositive(dimIndex), nsamples);
+ break;
+ case NO_ERROR:
+ default:
+ break;
+ }
+ }
}
- return; // GridDataSet does not provide errors
- }
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final int nsamples = dataSet.getDataCount();
- ioSerialiser.put(ARRAY_PREFIX + dimIndex, MathUtils.toFloats(dataSet.getValues(dimIndex)), nsamples);
- }
-
- if (!(dataSet instanceof DataSetError)) {
- return; // data set does not have any error definition
- }
- final DataSetError ds = (DataSetError) dataSet;
- for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
- final int nsamples = dataSet.getDataCount();
- switch (ds.getErrorType(dimIndex)) {
- case SYMMETRIC:
- ioSerialiser.put(EP_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsPositive(dimIndex)), nsamples);
- break;
- case ASYMMETRIC:
- ioSerialiser.put(EN_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsNegative(dimIndex)), nsamples);
- ioSerialiser.put(EP_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsPositive(dimIndex)), nsamples);
- break;
- case NO_ERROR:
- default:
- break;
+ /**
+ * @param dataSet to be exported
+ */
+ protected void writeNumericBinaryDataToBufferFloat(final DataSet dataSet) {
+ final int nDim = dataSet.getDimension();
+ if (dataSet instanceof GridDataSet gridDataSet) {
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final boolean gridDimension = dimIndex < gridDataSet.getNGrid();
+ final int nsamples = gridDimension ? gridDataSet.getShape(dimIndex) : dataSet.getDataCount();
+ final float[] values = MathUtils.toFloats(gridDimension ? gridDataSet.getGridValues(dimIndex) : dataSet.getValues(dimIndex));
+ ioSerialiser.put(ARRAY_PREFIX + dimIndex, values, nsamples);
+ }
+ return; // GridDataSet does not provide errors
+ }
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final int nsamples = dataSet.getDataCount();
+ ioSerialiser.put(ARRAY_PREFIX + dimIndex, MathUtils.toFloats(dataSet.getValues(dimIndex)), nsamples);
+ }
+
+ if (!(dataSet instanceof DataSetError ds)) {
+ return; // data set does not have any error definition
+ }
+ for (int dimIndex = 0; dimIndex < nDim; dimIndex++) {
+ final int nsamples = dataSet.getDataCount();
+ switch (ds.getErrorType(dimIndex)) {
+ case SYMMETRIC:
+ ioSerialiser.put(EP_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsPositive(dimIndex)), nsamples);
+ break;
+ case ASYMMETRIC:
+ ioSerialiser.put(EN_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsNegative(dimIndex)), nsamples);
+ ioSerialiser.put(EP_PREFIX + dimIndex, MathUtils.toFloats(ds.getErrorsPositive(dimIndex)), nsamples);
+ break;
+ case NO_ERROR:
+ default:
+ break;
+ }
+ }
}
- }
- }
- private void parseHeader(final IoSerialiser ioSerialiser, final DataSetBuilder builder, FieldDescription fieldDescription) {
- final String fieldName = fieldDescription.getFieldName();
- if (fieldName == null || !fieldName.startsWith(AXIS)) {
- return; // not axis related field
- }
- final String[] parsed = fieldName.split("\\.");
- if (parsed.length <= 1) {
- return; // couldn't parse axis field
- }
- final int dimension = getDimIndex(parsed[0], AXIS);
- if (dimension < 0) {
- return; // couldn't parse dimIndex
- }
- ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
- switch (parsed[1]) {
- case MIN:
- builder.setAxisMin(dimension, ioSerialiser.getBuffer().getDouble());
- break;
- case MAX:
- builder.setAxisMax(dimension, ioSerialiser.getBuffer().getDouble());
- break;
- case NAME:
- builder.setAxisName(dimension, ioSerialiser.getBuffer().getString());
- break;
- case UNIT:
- builder.setAxisUnit(dimension, ioSerialiser.getBuffer().getString());
- break;
- default:
- LOGGER.atWarn().addArgument(parsed[1]).log("parseHeader(): encountered unknown tag {} - ignore");
- break;
- }
- }
+ private void parseHeader(final IoSerialiser ioSerialiser, final DataSetBuilder builder, FieldDescription fieldDescription) {
+ final String fieldName = fieldDescription.getFieldName();
+ if (fieldName == null || !fieldName.startsWith(AXIS)) {
+ return; // not axis related field
+ }
+ final String[] parsed = fieldName.split("\\.");
+ if (parsed.length <= 1) {
+ return; // couldn't parse axis field
+ }
+ final int dimension = getDimIndex(parsed[0], AXIS);
+ if (dimension < 0) {
+ return; // couldn't parse dimIndex
+ }
+ ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
+ switch (parsed[1]) {
+ case MIN:
+ builder.setAxisMin(dimension, ioSerialiser.getBuffer().getDouble());
+ break;
+ case MAX:
+ builder.setAxisMax(dimension, ioSerialiser.getBuffer().getDouble());
+ break;
+ case NAME:
+ builder.setAxisName(dimension, ioSerialiser.getBuffer().getString());
+ break;
+ case UNIT:
+ builder.setAxisUnit(dimension, ioSerialiser.getBuffer().getString());
+ break;
+ default:
+ LOGGER.atWarn().addArgument(parsed[1]).log("parseHeader(): encountered unknown tag {} - ignore");
+ break;
+ }
+ }
- private void readNegError(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription, final String fieldName) {
- int dimIndex = getDimIndex(fieldName, EN_PREFIX);
- if (dimIndex >= 0) {
- ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
- final double[] origErrorArray = (origDataSet instanceof DataSetError) ? ((DataSetError) origDataSet).getErrorsNegative(dimIndex) : null;
- builder.setNegErrorNoCopy(dimIndex, getDoubleArray(ioSerialiser, origErrorArray, fieldDescription.getDataType()));
- }
- }
+ private void readNegError(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription, final String fieldName) {
+ int dimIndex = getDimIndex(fieldName, EN_PREFIX);
+ if (dimIndex >= 0) {
+ ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
+ final double[] origErrorArray = (origDataSet instanceof DataSetError) ? ((DataSetError) origDataSet).getErrorsNegative(dimIndex) : null;
+ builder.setNegErrorNoCopy(dimIndex, getDoubleArray(ioSerialiser, origErrorArray, fieldDescription.getDataType()));
+ }
+ }
- private void readPosError(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription,
- final String fieldName) {
- int dimIndex = getDimIndex(fieldName, EP_PREFIX);
- if (dimIndex >= 0) {
- ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
- final double[] origErrorArray = (origDataSet instanceof DataSetError) ? ((DataSetError) origDataSet).getErrorsPositive(dimIndex) : null;
- builder.setPosErrorNoCopy(dimIndex, getDoubleArray(ioSerialiser, origErrorArray, fieldDescription.getDataType()));
- }
- }
+ private void readPosError(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription,
+ final String fieldName) {
+ int dimIndex = getDimIndex(fieldName, EP_PREFIX);
+ if (dimIndex >= 0) {
+ ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
+ final double[] origErrorArray = (origDataSet instanceof DataSetError) ? ((DataSetError) origDataSet).getErrorsPositive(dimIndex) : null;
+ builder.setPosErrorNoCopy(dimIndex, getDoubleArray(ioSerialiser, origErrorArray, fieldDescription.getDataType()));
+ }
+ }
- private void readValues(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription,
- final String fieldName) {
- int dimIndex = getDimIndex(fieldName, ARRAY_PREFIX);
- if (dimIndex >= 0) {
- ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
- builder.setValuesNoCopy(dimIndex, getDoubleArray(ioSerialiser, origDataSet == null ? null : origDataSet.getValues(dimIndex), fieldDescription.getDataType()));
- }
- }
+ private void readValues(final IoSerialiser ioSerialiser, final DataSetBuilder builder, final DataSet origDataSet, FieldDescription fieldDescription,
+ final String fieldName) {
+ int dimIndex = getDimIndex(fieldName, ARRAY_PREFIX);
+ if (dimIndex >= 0) {
+ ioSerialiser.getBuffer().position(fieldDescription.getDataStartPosition());
+ builder.setValuesNoCopy(dimIndex, getDoubleArray(ioSerialiser, origDataSet == null ? null : origDataSet.getValues(dimIndex), fieldDescription.getDataType()));
+ }
+ }
- public static DataSetSerialiser withIoSerialiser(final IoSerialiser ioSerialiser) {
- return new DataSetSerialiser(ioSerialiser);
+ public static DataSetSerialiser withIoSerialiser(final IoSerialiser ioSerialiser) {
+ return new DataSetSerialiser(ioSerialiser);
+ }
}
-}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/IoClassSerialiserTests.java b/serialiser/src/test/java/io/opencmw/serialiser/IoClassSerialiserTests.java
index 78cca905..d4793ed1 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/IoClassSerialiserTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/IoClassSerialiserTests.java
@@ -70,10 +70,9 @@ protected void addCustomClassSerialiser(final IoClassSerialiser serialiser) {
// provide a writer function
final FieldSerialiser.TriConsumer writeFunction = (io, obj, field) -> {
final Object localObj = field == null || field.getField() == null ? obj : field.getField().get(obj);
- if (!(localObj instanceof CustomClass)) {
+ if (!(localObj instanceof CustomClass customClass)) {
throw new IllegalArgumentException("object " + obj + " is not of type CustomClass");
}
- CustomClass customClass = (CustomClass) localObj;
// place custom elements/composites etc. here - N.B. ordering is of paramount importance since
// these raw fields are not preceded by field headers
io.getBuffer().putDouble(customClass.testDouble);
@@ -94,10 +93,9 @@ protected void addCustomClassSerialiser(final IoClassSerialiser serialiser) {
if (sourceField == null) {
return new CustomClass(doubleVal, intVal, str);
} else {
- if (!(sourceField instanceof CustomClass)) {
+ if (!(sourceField instanceof CustomClass customClass)) {
throw new IllegalArgumentException("object " + obj + " is not of type CustomClass");
}
- CustomClass customClass = (CustomClass) sourceField;
customClass.testDouble = doubleVal;
customClass.testInt = intVal;
customClass.testString = str;
@@ -162,7 +160,6 @@ void testNestedClass() {
@ParameterizedTest(name = "IoBuffer class - {0}")
@ValueSource(classes = { ByteBuffer.class, FastByteBuffer.class })
- @SuppressWarnings("unchecked")
void testGenericSerialiserIdentity(final Class extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
assertNotNull(bufferClass, "bufferClass being not null");
assertNotNull(bufferClass.getConstructor(int.class), "Constructor(Integer) present");
@@ -243,7 +240,7 @@ void testGenericSerialiserIdentity(final Class extends IoBuffer> bufferClass)
assertTrue(destinationClass.dataSetSet.stream().anyMatch(ds -> ds.getName().equals("SetDataSet#1")));
assertTrue(destinationClass.dataSetSet.stream().anyMatch(ds -> ds.getName().equals("SetDataSet#2")));
- //assertEquals(sourceClass.dataSetQueue, destinationClass.dataSetQueue);
+ // assertEquals(sourceClass.dataSetQueue, destinationClass.dataSetQueue);
assertTrue(destinationClass.dataSetQueue.stream().anyMatch(ds -> ds.getName().equals("QueueDataSet#1")));
assertTrue(destinationClass.dataSetQueue.stream().anyMatch(ds -> ds.getName().equals("QueueDataSet#2")));
@@ -336,7 +333,6 @@ void testGenericSerialiserIdentityMultiArray(final Class extends IoBuffer> buf
@ParameterizedTest(name = "IoBuffer class - {0}")
@ValueSource(classes = { ByteBuffer.class, FastByteBuffer.class })
- @SuppressWarnings("unchecked")
void testGenericSerialiserIdentityCollectionOfCustomTypes(final Class extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
assertNotNull(bufferClass, "bufferClass being not null");
assertNotNull(bufferClass.getConstructor(int.class), "Constructor(Integer) present");
@@ -511,9 +507,8 @@ public NestedClass() {
public boolean equals(final Object o) {
if (this == o)
return true;
- if (!(o instanceof NestedClass))
+ if (!(o instanceof NestedClass that))
return false;
- final NestedClass that = (NestedClass) o;
return i == that.i && Objects.equals(class1, that.class1) && Objects.equals(class2, that.class2) && Objects.equals(class3, that.class3);
}
@@ -548,9 +543,8 @@ public String toString() {
public boolean equals(final Object o) {
if (this == o)
return true;
- if (!(o instanceof NonStaticInnerClass))
+ if (!(o instanceof NonStaticInnerClass that))
return false;
- final NonStaticInnerClass that = (NonStaticInnerClass) o;
return j == that.j;
}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/IoSerialiserTests.java b/serialiser/src/test/java/io/opencmw/serialiser/IoSerialiserTests.java
index 6b706fcf..e2adc6d4 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/IoSerialiserTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/IoSerialiserTests.java
@@ -50,7 +50,7 @@ void simpleStreamerTest(final Class extends IoBuffer> bufferClass) throws NoSu
// first test - check for equal initialisation -- this should be trivial
assertEquals(inputObject, outputObject1);
- //final IoBuffer buffer = new FastByteBuffer(1000000);
+ // final IoBuffer buffer = new FastByteBuffer(1000000);
final IoClassSerialiser serialiser = new IoClassSerialiser(buffer, BinarySerialiser.class);
serialiser.serialiseObject(inputObject);
@@ -209,7 +209,7 @@ void testParsingInterface(final Class extends IoSerialiser> ioSerialiserClass,
buffer.reset();
final WireDataFieldDescription rootField = ioClassSerialiser.parseWireFormat();
- //rootField.printFieldStructure();
+ // rootField.printFieldStructure();
assertEquals("ROOT", rootField.getFieldName());
final WireDataFieldDescription classFields = (WireDataFieldDescription) (rootField.getChildren().get(0));
@@ -296,7 +296,7 @@ void benchmarkPerformanceTests() {
// POJO performance
assertDoesNotThrow(() -> JsonHelper.testPerformancePojo(nIterations, inputObject, outputObject));
- assertDoesNotThrow(() -> JsonHelper.testPerformancePojoCodeGen(nIterations, inputObject, outputObject));
+ // assertDoesNotThrow(() -> JsonHelper.testPerformancePojoCodeGen(nIterations, inputObject, outputObject)); // code generation has to be adapted to newer java versions due to stricter encapsulation
// assertDoesNotThrow(() -> CmwHelper.testPerformancePojo(nIterations, inputObject, outputObject));
assertDoesNotThrow(() -> CmwLightHelper.testPerformancePojo(nIterations, inputObject, outputObject));
assertDoesNotThrow(() -> SerialiserHelper.testPerformancePojo(nIterations, inputObject, outputObject));
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/annotations/SerialiserAnnotationTests.java b/serialiser/src/test/java/io/opencmw/serialiser/annotations/SerialiserAnnotationTests.java
index 3859e6b0..13e1d64c 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/annotations/SerialiserAnnotationTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/annotations/SerialiserAnnotationTests.java
@@ -29,7 +29,7 @@ void testAnnotationGeneration() {
final ClassFieldDescription classFieldDescription = ClassUtils.getFieldDescription(dataClass.getClass());
// classFieldDescription.printFieldStructure();
- final FieldDescription energyField = classFieldDescription.findChildField("energy".hashCode(), "energy");
+ final FieldDescription energyField = classFieldDescription.findChildField("energy");
assertNotNull(energyField);
assertEquals("GeV/u", energyField.getFieldUnit());
assertEquals("energy description", energyField.getFieldDescription());
@@ -37,7 +37,7 @@ void testAnnotationGeneration() {
assertFalse(energyField.getFieldGroups().isEmpty());
assertEquals("A", energyField.getFieldGroups().get(0));
- final FieldDescription temperatureField = classFieldDescription.findChildField("temperature".hashCode(), "temperature");
+ final FieldDescription temperatureField = classFieldDescription.findChildField("temperature");
assertNotNull(temperatureField);
assertEquals("°C", temperatureField.getFieldUnit());
assertEquals("important temperature reading", temperatureField.getFieldDescription());
@@ -67,7 +67,7 @@ void testCustomSerialiserIdentity(final Class extends IoBuffer> bufferClass) t
final WireDataFieldDescription root = ioSerialiser.parseIoStream(true);
final FieldDescription serialiserFieldDescriptions = root.getChildren().get(0);
- final FieldDescription energyField = serialiserFieldDescriptions.findChildField("energy".hashCode(), "energy");
+ final FieldDescription energyField = serialiserFieldDescriptions.findChildField("energy");
assertNotNull(energyField);
assertEquals("GeV/u", energyField.getFieldUnit());
assertEquals("energy description", energyField.getFieldDescription());
@@ -75,7 +75,7 @@ void testCustomSerialiserIdentity(final Class extends IoBuffer> bufferClass) t
assertFalse(energyField.getFieldGroups().isEmpty());
assertEquals("A", energyField.getFieldGroups().get(0));
- final FieldDescription temperatureField = serialiserFieldDescriptions.findChildField("temperature".hashCode(), "temperature");
+ final FieldDescription temperatureField = serialiserFieldDescriptions.findChildField("temperature");
assertNotNull(temperatureField);
assertEquals("°C", temperatureField.getFieldUnit());
assertEquals("important temperature reading", temperatureField.getFieldDescription());
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/DataSetSerialiserBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/DataSetSerialiserBenchmark.java
index ea49b772..fc79f032 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/DataSetSerialiserBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/DataSetSerialiserBenchmark.java
@@ -18,7 +18,7 @@
/**
* Simple benchmark to verify that the in-place DataSet (de-)serialiser is not significantly slower than creating a new DataSet
- *
+ *
* Benchmark Mode Cnt Score Error Units
* DataSetSerialiserBenchmark.serialiserRoundTripByteBufferInplace thrpt 10 5971.023 ± 100.145 ops/s
* DataSetSerialiserBenchmark.serialiserRoundTripByteBufferNewDataSet thrpt 10 5652.462 ± 114.474 ops/s
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/JsonSelectionBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/JsonSelectionBenchmark.java
index 38351a79..974fe383 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/JsonSelectionBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/JsonSelectionBenchmark.java
@@ -26,10 +26,10 @@
/**
* simple benchmark to evaluate various JSON libraries.
* N.B. This is not intended as a complete JSON serialiser evaluation but to indicate some rough trends.
- *
+ *
* testClassId 1: being a string-heavy test data class
* testClassId 2: being a numeric-data-heavy test data class
- *
+ *
* Benchmark (testClassId) Mode Cnt Score Error Units
* JsonSelectionBenchmark.pojoFastJson string-heavy thrpt 10 12857.850 ± 109.050 ops/s
* JsonSelectionBenchmark.pojoFastJson numeric-heavy thrpt 10 91.458 ± 0.437 ops/s
@@ -41,7 +41,7 @@
* JsonSelectionBenchmark.pojoJsonIter numeric-heavy thrpt 10 86.629 ± 1.122 ops/s
* JsonSelectionBenchmark.pojoJsonIterCodeGen string-heavy thrpt 10 41048.034 ± 396.628 ops/s
* JsonSelectionBenchmark.pojoJsonIterCodeGen numeric-heavy thrpt 10 377.412 ± 9.755 ops/s
- *
+ *
* Process finished with exit code 0
*/
@State(Scope.Benchmark)
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/ReflectionBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/ReflectionBenchmark.java
index b37286a1..0be2ea1a 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/ReflectionBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/ReflectionBenchmark.java
@@ -14,7 +14,7 @@
/**
* Benchmark to compare, test and rationalise some assumptions that went into the serialiser refactoring
- *
+ *
* last test output (openjdk 11.0.7 2020-04-14, took 24 min):
* Benchmark Mode Cnt Score Error Units
* ReflectionBenchmark.fieldAccess1ViaMethod thrpt 10 368156046.779 ± 29954108.137 ops/s
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserAssumptionsBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserAssumptionsBenchmark.java
index bf97e2aa..4d70e293 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserAssumptionsBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserAssumptionsBenchmark.java
@@ -18,7 +18,7 @@
/**
* Benchmark to compare, test and rationalise some assumptions that went into the serialiser refactoring
- *
+ *
* last test output (openjdk 11.0.7 2020-04-14, took ~1:15h):
Benchmark Mode Cnt Score Error Units
SerialiserAssumptionsBenchmark.fluentDesignVoid thrpt 10 471049302.874 ± 38950975.384 ops/s
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserBenchmark.java
index b6975753..734b8582 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserBenchmark.java
@@ -23,7 +23,7 @@
* More thorough (JMH-based)) benchmark of various internal and external serialiser protocols.
* Test consists of a simple repeated POJO->serialised->byte[] buffer -> de-serialisation -> POJO + comparison checks.
* N.B. this isn't as precise as the JMH tests but gives a rough idea whether the protocol degraded or needs to be improved.
- *
+ *
* Benchmark (testClassId) Mode Cnt Score Error Units
* SerialiserBenchmark.customCmwLight string-heavy thrpt 10 49954.479 ± 560.726 ops/s
* SerialiserBenchmark.customCmwLight numeric-heavy thrpt 10 22433.828 ± 195.939 ops/s
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserQuickBenchmark.java b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserQuickBenchmark.java
index fd1f20a8..d1ab3a0e 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserQuickBenchmark.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/benchmark/SerialiserQuickBenchmark.java
@@ -13,7 +13,7 @@
* Simple (rough) benchmark of various internal and external serialiser protocols.
* Test consists of a simple repeated POJO->serialised->byte[] buffer -> de-serialisation -> POJO + comparison checks.
* N.B. this isn't as precise as the JMH tests but gives a rough idea whether the protocol degraded or needs to be improved.
- *
+ *
* Example output - numbers should be compared relatively (nIterations = 100000):
* (openjdk 11.0.7 2020-04-14, ASCII-only, nSizePrimitiveArrays = 10, nSizeString = 100, nestedClassRecursion = 1)
* [..] more string-heavy TestDataClass
@@ -22,28 +22,28 @@
* - CMW Serializer (Map only) throughput = 220.2 MB/s for 6.3 kB per test run (took 2871.0 ms)
* - CmwLight Serializer (Map only) throughput = 683.1 MB/s for 6.4 kB per test run (took 935.0 ms)
* - IO Serializer (Map only) throughput = 810.0 MB/s for 7.4 kB per test run (took 908.0 ms)
- *
+ *
* - FlatBuffers (custom FlexBuffers) throughput = 173.7 MB/s for 6.1 kB per test run (took 3536.0 ms)
* - CmwLight Serializer (custom) throughput = 460.5 MB/s for 6.4 kB per test run (took 1387.0 ms)
* - IO Serializer (custom) throughput = 545.0 MB/s for 7.3 kB per test run (took 1344.0 ms)
- *
+ *
* - JSON Serializer (POJO) throughput = 53.8 MB/s for 5.2 kB per test run (took 9747.0 ms)
* - CMW Serializer (POJO) throughput = 182.8 MB/s for 6.3 kB per test run (took 3458.0 ms)
* - CmwLight Serializer (POJO) throughput = 329.2 MB/s for 6.3 kB per test run (took 1906.0 ms)
* - IO Serializer (POJO) throughput = 374.9 MB/s for 7.2 kB per test run (took 1925.0 ms)
- *
- * [..] more primitive-array-heavy TestDataClass
+ *
+ * […] more primitive-array-heavy TestDataClass
* (openjdk 11.0.7 2020-04-14, UTF8, nSizePrimitiveArrays = 1000, nSizeString = 0, nestedClassRecursion = 0)
* - run 1
* - JSON Serializer (Map only) throughput = 350.7 MB/s for 34.3 kB per test run (took 9793.0 ms)
* - CMW Serializer (Map only) throughput = 1.7 GB/s for 29.2 kB per test run (took 1755.0 ms)
* - CmwLight Serializer (Map only) throughput = 6.7 GB/s for 29.2 kB per test run (took 437.0 ms)
* - IO Serializer (Map only) throughput = 6.1 GB/s for 29.7 kB per test run (took 485.0 ms)
- *
+ *
* - FlatBuffers (custom FlexBuffers) throughput = 123.1 MB/s for 30.1 kB per test run (took 24467.0 ms)
* - CmwLight Serializer (custom) throughput = 3.9 GB/s for 29.2 kB per test run (took 751.0 ms)
* - IO Serializer (custom) throughput = 3.8 GB/s for 29.7 kB per test run (took 782.0 ms)
- *
+ *
* - JSON Serializer (POJO) throughput = 31.7 MB/s for 34.3 kB per test run (took 108415.0 ms)
* - CMW Serializer (POJO) throughput = 1.5 GB/s for 29.2 kB per test run (took 1924.0 ms)
* - CmwLight Serializer (POJO) throughput = 3.5 GB/s for 29.1 kB per test run (took 824.0 ms)
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/spi/BinarySerialiserTests.java b/serialiser/src/test/java/io/opencmw/serialiser/spi/BinarySerialiserTests.java
index ebc9c750..c454e16b 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/spi/BinarySerialiserTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/spi/BinarySerialiserTests.java
@@ -407,7 +407,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
// add start marker
positionBefore.add(buffer.position());
final String dataStartMarkerName = "StartMarker";
- final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(dataStartMarker);
positionAfter.add(buffer.position());
@@ -444,7 +444,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
// add end marker
positionBefore.add(buffer.position());
final String dataEndMarkerName = "EndMarker";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker);
positionAfter.add(buffer.position());
@@ -459,7 +459,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
// header info
assertEquals(positionBefore.removeFirst(), buffer.position());
ProtocolInfo headerInfo = ioSerialiser.checkHeaderInfo();
- assertNotEquals(headerInfo, new Object()); // silly comparison for coverage reasons
+ assertNotEquals(new Object(), headerInfo); // silly comparison for coverage reasons
assertNotNull(headerInfo);
assertEquals(BinarySerialiser.PROTOCOL_NAME, headerInfo.getProducerName());
assertEquals(BinarySerialiser.VERSION_MAJOR, headerInfo.getVersionMajor());
@@ -562,7 +562,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
header = ioSerialiser.getFieldHeader();
assertEquals("enum", header.getFieldName(), "enum type retrieval");
buffer.position(header.getDataStartPosition());
- assertDoesNotThrow(ioSerialiser::getEnumTypeList); //skips enum info
+ assertDoesNotThrow(ioSerialiser::getEnumTypeList); // skips enum info
buffer.position(header.getDataStartPosition());
assertEquals(DataType.ENUM, ioSerialiser.getEnum(DataType.OTHER), "enum retrieval");
assertEquals(positionAfter.removeFirst(), buffer.position());
@@ -657,7 +657,7 @@ void testParseIoStream(final Class extends IoBuffer> bufferClass) throws Insta
// start nested data
final String nestedContextName = "nested context";
- final WireDataFieldDescription nestedContextMarker = new WireDataFieldDescription(ioSerialiser, null, nestedContextName.hashCode(), nestedContextName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription nestedContextMarker = new WireDataFieldDescription(ioSerialiser, null, nestedContextName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(nestedContextMarker); // add start marker
ioSerialiser.put("booleanArray", new boolean[] { true }, 1);
ioSerialiser.put("byteArray", new byte[] { (byte) 0x42 }, 1);
@@ -666,7 +666,7 @@ void testParseIoStream(final Class extends IoBuffer> bufferClass) throws Insta
// end nested data
final String dataEndMarkerName = "Life is good!";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker); // add end marker
buffer.flip();
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/spi/IoBufferTests.java b/serialiser/src/test/java/io/opencmw/serialiser/spi/IoBufferTests.java
index 978d382c..cd9f71a0 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/spi/IoBufferTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/spi/IoBufferTests.java
@@ -27,7 +27,7 @@ class IoBufferTests {
protected static final double[] doubleTestArray = { Float.MAX_VALUE + 1.1e9, Float.MAX_VALUE + 1.2e9, Float.MAX_VALUE + 1.3e9f, -Float.MAX_VALUE - 1.1e9f, -Float.MAX_VALUE - 1.2e9f, Float.MAX_VALUE - 1.3e9f };
protected static final char[] charTestArray = { 'a', 'b', 'c', 'd' };
protected static final String[] stringTestArray = { "Is", "this", "the", "real", "life?", "Is", "this", "just", "fantasy?", "", null };
- protected static final String[] stringTestArrayNullAsEmpty = Arrays.stream(stringTestArray).map(s -> s == null ? "" : s).toArray(String[]::new);
+ protected static final String[] stringTestArrayNullAsEmpty = Arrays.stream(stringTestArray).map(s -> s == null ? "" : s).toArray(String[] ::new);
private static final int BUFFER_SIZE = 1000;
@ParameterizedTest(name = "IoBuffer class - {0}")
@@ -166,7 +166,7 @@ void primitivesArraysASCII() {
{
final char[] chars = Character.toChars(0x1F701);
final String fourByteCharacter = new String(chars);
- String utf8TestString = "Γειά σου Κόσμε! - " + fourByteCharacter + " 語 \u00ea \u00f1 \u00fc + some normal ASCII character";
+ String utf8TestString = "Γειά σου Κόσμε! - " + fourByteCharacter + " 語 ê ñ ü + some normal ASCII character";
buffer.reset();
assertDoesNotThrow(() -> buffer.putStringArray(stringTestArray, stringTestArray.length));
assertDoesNotThrow(() -> buffer.putStringArray(stringTestArray, -1));
@@ -221,17 +221,17 @@ void primitivesMixed(final Class extends IoBuffer> bufferClass) throws NoSuchM
buffer.flip();
assertTrue(buffer.getBoolean());
assertFalse(buffer.getBoolean());
- assertEquals(buffer.getByte(), (byte) 0xFE);
- assertEquals(buffer.getShort(), (short) 43);
+ assertEquals((byte) 0xFE, buffer.getByte());
+ assertEquals((short) 43, buffer.getShort());
assertEquals(1025, buffer.getInt());
- assertEquals(buffer.getLong(), largeLong);
+ assertEquals(largeLong, buffer.getLong());
assertEquals(1.3e10f, buffer.getFloat());
assertEquals(1.3e10f, buffer.getDouble());
assertEquals('@', buffer.getChar());
assertEquals((char) 513, buffer.getChar());
assertEquals("Hello World!", buffer.getStringISO8859());
assertEquals("Γειά σου Κόσμε!", buffer.getString());
- assertEquals(buffer.position(), position);
+ assertEquals(position, buffer.position());
}
@ParameterizedTest(name = "IoBuffer class - {0}")
@@ -253,12 +253,12 @@ void primitivesSimple(final Class extends IoBuffer> bufferClass) throws NoSuch
buffer.reset();
buffer.putByte((byte) 0xFE);
buffer.flip();
- assertEquals(buffer.getByte(), (byte) 0xFE);
+ assertEquals((byte) 0xFE, buffer.getByte());
buffer.reset();
buffer.putShort((short) 43);
buffer.flip();
- assertEquals(buffer.getShort(), (short) 43);
+ assertEquals((short) 43, buffer.getShort());
buffer.reset();
buffer.putInt(1025);
@@ -269,7 +269,7 @@ void primitivesSimple(final Class extends IoBuffer> bufferClass) throws NoSuch
final long largeLong = (long) Integer.MAX_VALUE + (long) 10;
buffer.putLong(largeLong);
buffer.flip();
- assertEquals(buffer.getLong(), largeLong);
+ assertEquals(largeLong, buffer.getLong());
buffer.reset();
buffer.putFloat(1.3e10f);
@@ -313,17 +313,17 @@ void primitivesSimpleInPlace(final Class extends IoBuffer> bufferClass) throws
assertFalse(buffer.getBoolean(0));
buffer.putByte(1, (byte) 0xFE);
- assertEquals(buffer.getByte(1), (byte) 0xFE);
+ assertEquals((byte) 0xFE, buffer.getByte(1));
buffer.putShort(2, (short) 43);
- assertEquals(buffer.getShort(2), (short) 43);
+ assertEquals((short) 43, buffer.getShort(2));
buffer.putInt(3, 1025);
assertEquals(1025, buffer.getInt(3));
final long largeLong = (long) Integer.MAX_VALUE + (long) 10;
buffer.putLong(4, largeLong);
- assertEquals(buffer.getLong(4), largeLong);
+ assertEquals(largeLong, buffer.getLong(4));
buffer.putFloat(5, 1.3e10f);
assertEquals(1.3e10f, buffer.getFloat(5));
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/spi/JsonSerialiserTests.java b/serialiser/src/test/java/io/opencmw/serialiser/spi/JsonSerialiserTests.java
index 443fe9bc..a42fa992 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/spi/JsonSerialiserTests.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/spi/JsonSerialiserTests.java
@@ -39,7 +39,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
ioSerialiser.putHeaderInfo();
// add start marker
final String dataStartMarkerName = "StartMarker";
- final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataStartMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(dataStartMarker);
// add Collection - List
final List list = Arrays.asList(1, 2, 3);
@@ -58,7 +58,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
ioSerialiser.put("enum", DataType.ENUM);
// add end marker
final String dataEndMarkerName = "EndMarker";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker); // end start marker
ioSerialiser.putEndMarker(dataEndMarker); // end header info
@@ -84,7 +84,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
// header info
ProtocolInfo headerInfo = ioSerialiser.checkHeaderInfo();
- assertNotEquals(headerInfo, new Object()); // silly comparison for coverage reasons
+ assertNotEquals(new Object(), headerInfo); // silly comparison for coverage reasons
assertNotNull(headerInfo);
assertEquals(JsonSerialiser.class.getCanonicalName(), headerInfo.getProducerName());
assertEquals(1, headerInfo.getVersionMajor());
@@ -95,7 +95,7 @@ void testHeaderAndSpecialItems(final Class extends IoBuffer> bufferClass) thro
@DisplayName("basic primitive array writer tests")
@ParameterizedTest(name = "IoBuffer class - {0}")
@ValueSource(classes = { ByteBuffer.class, FastByteBuffer.class })
- void testParseIoStream(final Class extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { //NOSONAR NOPMD
+ void testParseIoStream(final Class extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { // NOSONAR NOPMD
assertNotNull(bufferClass, "bufferClass being not null");
assertNotNull(bufferClass.getConstructor(int.class), "Constructor(Integer) present");
final IoBuffer buffer = bufferClass.getConstructor(int.class).newInstance(2 * BUFFER_SIZE); // a bit larger buffer since we test more cases at once
@@ -144,7 +144,7 @@ void testParseIoStream(final Class extends IoBuffer> bufferClass) throws Insta
// start nested data
final String nestedContextName = "nested context";
- final WireDataFieldDescription nestedContextMarker = new WireDataFieldDescription(ioSerialiser, null, nestedContextName.hashCode(), nestedContextName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription nestedContextMarker = new WireDataFieldDescription(ioSerialiser, null, nestedContextName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(nestedContextMarker); // add start marker
ioSerialiser.put("booleanArray", new boolean[] { true }, 1);
ioSerialiser.put("byteArray", new byte[] { (byte) 0x42 }, 1);
@@ -153,7 +153,7 @@ void testParseIoStream(final Class extends IoBuffer> bufferClass) throws Insta
// end nested data
final String dataEndMarkerName = "Life is good!";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker); // add end marker
buffer.flip();
@@ -215,7 +215,7 @@ void testObjectAlongPrimitives() {
simpleObj2.switches = Collections.emptyList();
ioSerialiser.put("SimpleObjects", List.of(simpleObj, simpleObj2), SimpleClass.class);
- ioSerialiser.putEndMarker(new WireDataFieldDescription(ioSerialiser, null, "end marker".hashCode(), "end marker", DataType.END_MARKER, -1, -1, -1));
+ ioSerialiser.putEndMarker(new WireDataFieldDescription(ioSerialiser, null, "end marker", DataType.END_MARKER, -1, -1, -1));
ioSerialiser.getBuffer().flip();
@@ -291,9 +291,8 @@ public void setValues() {
public boolean equals(final Object o) {
if (this == o)
return true;
- if (!(o instanceof SimpleClass))
+ if (!(o instanceof SimpleClass that))
return false;
- final SimpleClass that = (SimpleClass) o;
return integer == that.integer && Objects.equals(foo, that.foo) && Objects.equals(switches, that.switches);
}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/utils/CmwLightHelper.java b/serialiser/src/test/java/io/opencmw/serialiser/utils/CmwLightHelper.java
index aaf8af30..874a80f8 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/utils/CmwLightHelper.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/utils/CmwLightHelper.java
@@ -312,7 +312,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
// 1D-arrays
ioSerialiser.put("boolArray", pojo.boolArray, pojo.boolArray.length);
ioSerialiser.put("byteArray", pojo.byteArray, pojo.byteArray.length);
- //ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.length); // not supported by CMW
+ // ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.length); // not supported by CMW
ioSerialiser.put("shortArray", pojo.shortArray, pojo.shortArray.length);
ioSerialiser.put("intArray", pojo.intArray, pojo.intArray.length);
ioSerialiser.put("longArray", pojo.longArray, pojo.longArray.length);
@@ -324,7 +324,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
ioSerialiser.put("nDimensions", pojo.nDimensions, pojo.nDimensions.length);
ioSerialiser.put("boolNdimArray", pojo.boolNdimArray, pojo.nDimensions);
ioSerialiser.put("byteNdimArray", pojo.byteNdimArray, pojo.nDimensions);
- //ioSerialiser.put("charNdimArray", pojo.nDimensions); // not supported by CMW
+ // ioSerialiser.put("charNdimArray", pojo.nDimensions); // not supported by CMW
ioSerialiser.put("shortNdimArray", pojo.shortNdimArray, pojo.nDimensions);
ioSerialiser.put("intNdimArray", pojo.intNdimArray, pojo.nDimensions);
ioSerialiser.put("longNdimArray", pojo.longNdimArray, pojo.nDimensions);
@@ -333,7 +333,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (pojo.nestedData != null) {
final String dataStartMarkerName = "nestedData";
- final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(nestedDataMarker);
serialiseCustom(ioSerialiser, pojo.nestedData, false);
ioSerialiser.putEndMarker(nestedDataMarker);
@@ -341,7 +341,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (header) {
final String dataEndMarkerName = "OBJ_ROOT_END";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker);
}
}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/utils/FlatBuffersHelper.java b/serialiser/src/test/java/io/opencmw/serialiser/utils/FlatBuffersHelper.java
index a3490e7a..f8ebb968 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/utils/FlatBuffersHelper.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/utils/FlatBuffersHelper.java
@@ -304,7 +304,7 @@ public static void deserialiseCustom(FlexBuffers.Map map, final TestDataClass po
final FlexBuffers.Map nestedMap = map.get("nestedData").asMap();
- if (nestedMap != null && nestedMap.size() != 0) {
+ if (nestedMap != null && !nestedMap.isEmpty()) {
deserialiseCustom(map.get("nestedData").asMap(), pojo.nestedData, false);
}
}
@@ -339,7 +339,7 @@ public static void testCustomSerialiserPerformance(final int iterations, final T
}
public static int checkCustomSerialiserIdentity(final TestDataClass inputObject, final TestDataClass outputObject) {
- //final FlexBuffersBuilder floatBuffersBuilder = new FlexBuffersBuilder(new ArrayReadWriteBuf(rawByteBuffer), FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS);
+ // final FlexBuffersBuilder floatBuffersBuilder = new FlexBuffersBuilder(new ArrayReadWriteBuf(rawByteBuffer), FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS);
final FlexBuffersBuilder floatBuffersBuilder = new FlexBuffersBuilder(new ArrayReadWriteBuf(rawByteBuffer), FlexBuffersBuilder.BUILDER_FLAG_NONE);
final ByteBuffer retVal = FlatBuffersHelper.serialiseCustom(floatBuffersBuilder, inputObject);
final int nBytesFlatBuffers = retVal.limit();
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/utils/JsonHelper.java b/serialiser/src/test/java/io/opencmw/serialiser/utils/JsonHelper.java
index ffc34800..4f1c344f 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/utils/JsonHelper.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/utils/JsonHelper.java
@@ -24,7 +24,7 @@
import com.jsoniter.spi.JsonException;
public final class JsonHelper {
- private static final Logger LOGGER = LoggerFactory.getLogger(SerialiserQuickBenchmark.class); // N.B. SerialiserQuickBenchmark reference on purpose
+ private static final Logger LOGGER = LoggerFactory.getLogger(JsonHelper.class); // N.B. SerialiserQuickBenchmark reference on purpose
private static final IoBuffer byteBuffer = new FastByteBuffer(1000000);
// private static final IoBuffer byteBuffer = new ByteBuffer(20000);
private static final JsonSerialiser jsonSerialiser = new JsonSerialiser(byteBuffer);
@@ -53,11 +53,11 @@ public static int checkSerialiserIdentity(final TestDataClass inputObject, TestD
outputObject.clear();
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
// JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
- // JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
+ JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
// JsonStream.setIndentionStep(2); // sets line-breaks and indentation (more human readable)
- //Base64Support.enable();
- //Base64FloatSupport.enableEncodersAndDecoders();
- JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
+ // Base64Support.enable();
+ // Base64FloatSupport.enableEncodersAndDecoders();
+ JsonStream.setMode(EncodingMode.REFLECTION_MODE);
try {
PreciseFloatSupport.enable();
@@ -119,7 +119,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
// 1D-arrays
ioSerialiser.put("boolArray", pojo.boolArray, pojo.boolArray.length);
ioSerialiser.put("byteArray", pojo.byteArray, pojo.byteArray.length);
- //ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.lenght);
+ // ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.lenght);
ioSerialiser.put("shortArray", pojo.shortArray, pojo.shortArray.length);
ioSerialiser.put("intArray", pojo.intArray, pojo.intArray.length);
ioSerialiser.put("longArray", pojo.longArray, pojo.longArray.length);
@@ -131,7 +131,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
ioSerialiser.put("nDimensions", pojo.nDimensions, pojo.nDimensions.length);
ioSerialiser.put("boolNdimArray", pojo.boolNdimArray, pojo.nDimensions);
ioSerialiser.put("byteNdimArray", pojo.byteNdimArray, pojo.nDimensions);
- //ioSerialiser.put("charNdimArray", pojo.nDimensions);
+ // ioSerialiser.put("charNdimArray", pojo.nDimensions);
ioSerialiser.put("shortNdimArray", pojo.shortNdimArray, pojo.nDimensions);
ioSerialiser.put("intNdimArray", pojo.intNdimArray, pojo.nDimensions);
ioSerialiser.put("longNdimArray", pojo.longNdimArray, pojo.nDimensions);
@@ -140,7 +140,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (pojo.nestedData != null) {
final String dataStartMarkerName = "nestedData";
- final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(nestedDataMarker);
serialiseCustom(ioSerialiser, pojo.nestedData, false);
ioSerialiser.putEndMarker(nestedDataMarker);
@@ -148,7 +148,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (header) {
final String dataEndMarkerName = "OBJ_ROOT_END";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker);
}
}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/utils/SerialiserHelper.java b/serialiser/src/test/java/io/opencmw/serialiser/utils/SerialiserHelper.java
index f9fa04f3..ddc79286 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/utils/SerialiserHelper.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/utils/SerialiserHelper.java
@@ -130,8 +130,8 @@ public static void deserialiseCustom(IoSerialiser ioSerialiser, final TestDataCl
pojo.boolArray = ioSerialiser.getBooleanArray();
getFieldHeader(ioSerialiser);
pojo.byteArray = ioSerialiser.getByteArray();
- //getFieldHeader(ioSerialiser);
- //pojo.charArray = ioSerialiser.getCharArray(ioSerialiser);
+ // getFieldHeader(ioSerialiser);
+ // pojo.charArray = ioSerialiser.getCharArray(ioSerialiser);
getFieldHeader(ioSerialiser);
pojo.shortArray = ioSerialiser.getShortArray();
getFieldHeader(ioSerialiser);
@@ -218,7 +218,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
// 1D-arrays
ioSerialiser.put("boolArray", pojo.boolArray, pojo.boolArray.length);
ioSerialiser.put("byteArray", pojo.byteArray, pojo.byteArray.length);
- //ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.lenght);
+ // ioSerialiser.put("charArray", pojo.charArray, pojo.charArray.lenght);
ioSerialiser.put("shortArray", pojo.shortArray, pojo.shortArray.length);
ioSerialiser.put("intArray", pojo.intArray, pojo.intArray.length);
ioSerialiser.put("longArray", pojo.longArray, pojo.longArray.length);
@@ -230,7 +230,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
ioSerialiser.put("nDimensions", pojo.nDimensions, pojo.nDimensions.length);
ioSerialiser.put("boolNdimArray", pojo.boolNdimArray, pojo.nDimensions);
ioSerialiser.put("byteNdimArray", pojo.byteNdimArray, pojo.nDimensions);
- //ioSerialiser.put("charNdimArray", pojo.nDimensions);
+ // ioSerialiser.put("charNdimArray", pojo.nDimensions);
ioSerialiser.put("shortNdimArray", pojo.shortNdimArray, pojo.nDimensions);
ioSerialiser.put("intNdimArray", pojo.intNdimArray, pojo.nDimensions);
ioSerialiser.put("longNdimArray", pojo.longNdimArray, pojo.nDimensions);
@@ -239,7 +239,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (pojo.nestedData != null) {
final String dataStartMarkerName = "nestedData";
- final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName.hashCode(), dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription nestedDataMarker = new WireDataFieldDescription(ioSerialiser, null, dataStartMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putStartMarker(nestedDataMarker);
serialiseCustom(ioSerialiser, pojo.nestedData, false);
ioSerialiser.putEndMarker(nestedDataMarker);
@@ -247,7 +247,7 @@ public static void serialiseCustom(final IoSerialiser ioSerialiser, final TestDa
if (header) {
final String dataEndMarkerName = "OBJ_ROOT_END";
- final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName.hashCode(), dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
+ final WireDataFieldDescription dataEndMarker = new WireDataFieldDescription(ioSerialiser, null, dataEndMarkerName, DataType.START_MARKER, -1, -1, -1);
ioSerialiser.putEndMarker(dataEndMarker);
}
}
diff --git a/serialiser/src/test/java/io/opencmw/serialiser/utils/TestDataClass.java b/serialiser/src/test/java/io/opencmw/serialiser/utils/TestDataClass.java
index dfa2f013..f0f839f2 100644
--- a/serialiser/src/test/java/io/opencmw/serialiser/utils/TestDataClass.java
+++ b/serialiser/src/test/java/io/opencmw/serialiser/utils/TestDataClass.java
@@ -69,7 +69,7 @@ public TestDataClass() {
public TestDataClass(final int nSizePrimitives, final int nSizeString, final int nestedClassRecursion) {
if (nestedClassRecursion > 0) {
nestedData = new TestDataClass(nSizePrimitives, nSizeString, nestedClassRecursion - 1);
- nestedData.init(nSizePrimitives + 1, nSizeString + 1); //N.B. '+1' to have different sizes for nested classes
+ nestedData.init(nSizePrimitives + 1, nSizeString + 1); // N.B. '+1' to have different sizes for nested classes
}
init(nSizePrimitives, nSizeString);
@@ -126,11 +126,10 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof TestDataClass)) {
+ if (!(obj instanceof TestDataClass other)) {
LOGGER.atError().addArgument(obj).log("incompatible object type of obj = '{}'");
return false;
}
- final TestDataClass other = (TestDataClass) obj;
boolean returnState = true;
if (this.bool1 != other.bool1) {
LOGGER.atError().addArgument("bool1").addArgument(this.bool1).addArgument(other.bool1) //
@@ -228,12 +227,12 @@ public boolean equals(final Object obj) {
LOGGER.atError().addArgument("byteArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
returnState = false;
}
- //try {
- // assertArrayEquals(this.charArray, other.charArray);
- //} catch(AssertionFailedError e) {
- // LOGGER.atError().addArgument("charArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
- // returnState = false;
- //}
+ // try {
+ // assertArrayEquals(this.charArray, other.charArray);
+ // } catch(AssertionFailedError e) {
+ // LOGGER.atError().addArgument("charArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
+ // returnState = false;
+ // }
try {
assertArrayEquals(this.shortArray, other.shortArray);
} catch (AssertionFailedError e) {
@@ -290,12 +289,12 @@ public boolean equals(final Object obj) {
LOGGER.atError().addArgument("byteNdimArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
returnState = false;
}
- //try {
- // assertArrayEquals(this.charNdimArray, other.charNdimArray);
- //} catch(AssertionFailedError e) {
- // LOGGER.atError().addArgument("charNdimArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
- // returnState = false;
- //}
+ // try {
+ // assertArrayEquals(this.charNdimArray, other.charNdimArray);
+ // } catch(AssertionFailedError e) {
+ // LOGGER.atError().addArgument("charNdimArray").addArgument(e.getMessage()).log("field '{}' does not match '{}'");
+ // returnState = false;
+ // }
try {
assertArrayEquals(this.shortNdimArray, other.shortNdimArray);
} catch (AssertionFailedError e) {