diff --git a/src/main/java/fr/soleil/bensikin/data/snapshot/SnapshotAttributeDeltaValue.java b/src/main/java/fr/soleil/bensikin/data/snapshot/SnapshotAttributeDeltaValue.java index bf1b38cf9e63aa1398cacdc7879ecdd2de612548..339f43617370721a42f4a5710e67cd49369965e0 100644 --- a/src/main/java/fr/soleil/bensikin/data/snapshot/SnapshotAttributeDeltaValue.java +++ b/src/main/java/fr/soleil/bensikin/data/snapshot/SnapshotAttributeDeltaValue.java @@ -69,6 +69,8 @@ import fr.soleil.lib.project.math.NumberArrayUtils; */ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { + private static final String NULL = "null"; + /** * Builds a SnapshotAttributeDeltaValue from the difference between a read * value and a write value. @@ -85,7 +87,6 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { public SnapshotAttributeDeltaValue(SnapshotAttributeWriteValue writeValue, SnapshotAttributeReadValue readValue, boolean manageAllTypes) { super(writeValue.getDataFormat(), writeValue.getDataType(), null, null); - Object deltaValue = getDeltaValue(writeValue, readValue, manageAllTypes); if (readValue == null || writeValue == null) { setNotApplicable(true); @@ -94,19 +95,17 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { } Object value = deltaValue; Object nullElements = null; - if (deltaValue instanceof NullableData<?>) { - NullableData<?> data = (NullableData<?>) deltaValue; + if (deltaValue instanceof NullableData<?>) { + NullableData<?> data = (NullableData<?>) deltaValue; value = data.getValue(); nullElements = data.getNullElements(); } if (value == null) { setNotApplicable(true); } - if ((value instanceof String) || (value instanceof String[])) { setDataType(TangoConst.Tango_DEV_STRING); } - this.setValue(value, nullElements); } @@ -124,7 +123,7 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { private Object getDeltaValue(SnapshotAttributeWriteValue writeValue, SnapshotAttributeReadValue readValue, boolean manageAllTypes) { - switch (this.dataFormat) { + switch (dataFormat) { case SCALAR_DATA_FORMAT: return getScalarDeltaValue(writeValue, readValue, manageAllTypes); @@ -153,7 +152,7 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { * difference. * @return 29 juin 2005 */ - private NullableData<Boolean> getScalarDeltaValue(SnapshotAttributeWriteValue writeValue, + private NullableData<Boolean> getScalarDeltaValue(SnapshotAttributeWriteValue writeValue, SnapshotAttributeReadValue readValue, boolean manageAllTypes) { Object ret; Boolean nullElements = Boolean.FALSE; @@ -172,13 +171,13 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { Boolean nullWrite = (Boolean) writeValue.getNullElements(); nullElements = Boolean.valueOf(((nullRead != null) && nullRead.booleanValue()) || ((nullWrite != null) && nullWrite.booleanValue())); - Object write = writeValue.getScalarValue(), read = writeValue.getScalarValue(); + Object write = writeValue.getScalarValue(), read = readValue.getScalarValue(); switch (this.getDataType()) { case TangoConst.Tango_DEV_USHORT: case TangoConst.Tango_DEV_SHORT: try { - Short writeDouble = (Short) write; - Short readDouble = (Short) read; + Number writeDouble = (Number) write; + Number readDouble = (Number) read; if (writeDouble == null || readDouble == null) { nullElements = Boolean.FALSE; if (manageAllTypes) { @@ -198,11 +197,11 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { // a file String writeDouble_s = String.valueOf(write); String readDouble_s = String.valueOf(read); - if ("null".equals(writeDouble_s) || writeDouble_s.isEmpty() || "null".equals(readDouble_s) + if (NULL.equals(writeDouble_s) || writeDouble_s.isEmpty() || NULL.equals(readDouble_s) || readDouble_s.isEmpty()) { nullElements = Boolean.FALSE; if (manageAllTypes) { - if ("null".equals(writeDouble_s) && "null".equals(readDouble_s)) { + if (NULL.equals(writeDouble_s) && NULL.equals(readDouble_s)) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); } else if (writeDouble_s.isEmpty() && readDouble_s.isEmpty()) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); @@ -228,8 +227,8 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { // -------------------- case TangoConst.Tango_DEV_DOUBLE: try { - Double writeDouble = (Double) write; - Double readDouble = (Double) read; + Number writeDouble = (Number) write; + Number readDouble = (Number) read; if (writeDouble == null || readDouble == null) { nullElements = Boolean.FALSE; if (manageAllTypes) { @@ -248,11 +247,11 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { // happens when the read/write values are String loaded from a file String writeDouble_s = String.valueOf(write); String readDouble_s = String.valueOf(read); - if ("null".equals(writeDouble_s) || writeDouble_s.isEmpty() || "null".equals(readDouble_s) + if (NULL.equals(writeDouble_s) || writeDouble_s.isEmpty() || NULL.equals(readDouble_s) || readDouble_s.isEmpty()) { nullElements = Boolean.FALSE; if (manageAllTypes) { - if ("null".equals(writeDouble_s) && "null".equals(readDouble_s)) { + if (NULL.equals(writeDouble_s) && NULL.equals(readDouble_s)) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); } else if (writeDouble_s.isEmpty() && readDouble_s.isEmpty()) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); @@ -273,8 +272,8 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { case TangoConst.Tango_DEV_ULONG: case TangoConst.Tango_DEV_LONG: try { - Integer writeLong = (Integer) write; - Integer readLong = (Integer) read; + Number writeLong = (Number) write; + Number readLong = (Number) read; if (writeLong == null || readLong == null) { nullElements = Boolean.FALSE; if (manageAllTypes) { @@ -293,11 +292,11 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { // happens when the read/write values are String loaded from a file String writeLong_s = String.valueOf(write); String readLong_s = String.valueOf(read); - if ("null".equals(writeLong_s) || writeLong_s.isEmpty() || "null".equals(readLong_s) + if (NULL.equals(writeLong_s) || writeLong_s.isEmpty() || NULL.equals(readLong_s) || readLong_s.isEmpty()) { nullElements = Boolean.FALSE; if (manageAllTypes) { - if ("null".equals(writeLong_s) && "null".equals(readLong_s)) { + if (NULL.equals(writeLong_s) && NULL.equals(readLong_s)) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); } else if (writeLong_s.isEmpty() && readLong_s.isEmpty()) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); @@ -317,8 +316,8 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { break; case TangoConst.Tango_DEV_FLOAT: try { - Float writeFloat = (Float) write; - Float readFloat = (Float) read; + Number writeFloat = (Number) write; + Number readFloat = (Number) read; if (writeFloat == null || readFloat == null) { nullElements = Boolean.FALSE; if (manageAllTypes) { @@ -337,11 +336,11 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { // happens when the read/write values are String loaded from a file String writeFloat_s = String.valueOf(write); String readFloat_s = String.valueOf(read); - if ("null".equals(writeFloat_s) || writeFloat_s.isEmpty() || "null".equals(readFloat_s) + if (NULL.equals(writeFloat_s) || writeFloat_s.isEmpty() || NULL.equals(readFloat_s) || readFloat_s.isEmpty()) { nullElements = Boolean.FALSE; if (manageAllTypes) { - if ("null".equals(writeFloat_s) && "null".equals(readFloat_s)) { + if (NULL.equals(writeFloat_s) && NULL.equals(readFloat_s)) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); } else if (writeFloat_s.isEmpty() && readFloat_s.isEmpty()) { ret = Messages.getMessage("SNAPSHOT_COMPARE_VALUE_SAME"); @@ -381,7 +380,7 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { break; } } - return new NullableData<Boolean>(ret, nullElements); + return new NullableData<Boolean>(ret, nullElements); } /** @@ -399,7 +398,7 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { * @param readValue The read value * @return 29 juin 2005 */ - private NullableData<boolean[]> getSpectrumDeltaValue(SnapshotAttributeWriteValue writeValue, + private NullableData<boolean[]> getSpectrumDeltaValue(SnapshotAttributeWriteValue writeValue, SnapshotAttributeReadValue readValue, boolean manageAllTypes) { if (writeValue == null || readValue == null) { return null; @@ -660,7 +659,7 @@ public class SnapshotAttributeDeltaValue extends SnapshotAttributeValue { } // end switch (dataType) - return new NullableData<boolean[]>(ret, nullElements); + return new NullableData<boolean[]>(ret, nullElements); } /**