You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2020/10/21 13:42:25 UTC
[plc4x] 07/08: Added hashCode and equals to S7Field. Added
Comparison Test.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch rel/0.6
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit c815c734b88871938a51c8bafdaa4962db574bf2
Author: julian <j....@pragmaticminds.de>
AuthorDate: Wed Aug 19 15:26:26 2020 +0200
Added hashCode and equals to S7Field. Added Comparison Test.
---
.../java/org/apache/plc4x/java/s7/model/S7Field.java | 19 +++++++++++++++++++
.../org/apache/plc4x/java/s7/model/S7FieldTests.java | 9 +++++++++
2 files changed, 28 insertions(+)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
index eba0e1b..6662615 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/model/S7Field.java
@@ -31,6 +31,7 @@ import org.apache.plc4x.java.utils.ReadBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -297,6 +298,24 @@ public class S7Field implements PlcField {
}
@Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ S7Field s7Field = (S7Field) o;
+ return getBlockNumber() == s7Field.getBlockNumber() &&
+ getByteOffset() == s7Field.getByteOffset() &&
+ getBitOffset() == s7Field.getBitOffset() &&
+ getNumElements() == s7Field.getNumElements() &&
+ getDataType() == s7Field.getDataType() &&
+ getMemoryArea() == s7Field.getMemoryArea();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getDataType(), getMemoryArea(), getBlockNumber(), getByteOffset(), getBitOffset(), getNumElements());
+ }
+
+ @Override
public String toString() {
return "S7Field{" +
"dataType=" + dataType +
diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
index 0c5d9cc..1ee51c3 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/model/S7FieldTests.java
@@ -56,6 +56,7 @@ class S7FieldTests {
Arguments.of("%DB444:14.0:BOOL", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 444, 14, 0),
// Simotion
Arguments.of("10-01-00-01-00-2D-84-00-00-08", TransportSize.BOOL, MemoryArea.DATA_BLOCKS, 45, 1, 0),
+ Arguments.of("%DB45:16.0:REAL", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0),
Arguments.of("10-08-00-01-00-2D-84-00-00-80", TransportSize.REAL, MemoryArea.DATA_BLOCKS, 45, 16, 0),
Arguments.of("10-07-00-01-00-98-84-00-06-C0", TransportSize.UDINT, MemoryArea.DATA_BLOCKS, 152, 216, 0)
/*,
@@ -122,4 +123,12 @@ class S7FieldTests {
final S7Field s7Field = S7Field.of("A0-01-00-01-00-2D-84-00-00-08");
});
}
+
+ @Test
+ void testSimotionadressEqualsRegularAdress() {
+ S7Field simotion = S7Field.of("10-08-00-01-00-2D-84-00-00-80");
+ S7Field regular = S7Field.of("%DB45:16.0:REAL");
+
+ assertEquals(regular, simotion);
+ }
}
\ No newline at end of file