From e00e6663044054f9359db1a09da50a697e183a6e Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Thu, 6 Nov 2014 15:24:16 -0500 Subject: [PATCH] ctf: add equals and hashcodes to Declarations Change-Id: I15d8030d2f75979012b87caae4dfc08bbda3ee7a Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/36093 Tested-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../tests/types/ArrayDeclaration2Test.java | 33 ++++- .../tests/types/ArrayDefinition2Test.java | 4 +- .../core/tests/types/EnumDeclarationTest.java | 49 ++++++++ .../tests/types/FloatDeclarationTest.java | 54 ++++++-- .../tests/types/IntegerDeclarationTest.java | 45 +++++++ .../tests/types/SequenceDeclaration2Test.java | 45 ++++++- .../tests/types/StringDeclarationTest.java | 36 ++++++ .../tests/types/StructDeclarationTest.java | 59 ++++++++- .../tests/types/VariantDeclarationTest.java | 77 +++++++++++- .../ctf/core/event/types/EnumDeclaration.java | 118 +++++++++++++++++- .../core/event/types/FloatDeclaration.java | 39 ++++++ .../ctf/core/event/types/IDeclaration.java | 6 + .../core/event/types/IntegerDeclaration.java | 63 ++++++++++ .../core/event/types/StringDeclaration.java | 46 ++++++- .../core/event/types/StructDeclaration.java | 31 ++++- .../core/event/types/VariantDeclaration.java | 73 +++++++++++ .../core/event/types/ArrayDeclaration.java | 35 +++++- .../core/event/types/SequenceDeclaration.java | 33 ++++- .../EventHeaderCompactDeclaration.java | 27 ++++ .../EventHeaderLargeDeclaration.java | 26 ++++ 20 files changed, 871 insertions(+), 28 deletions(-) diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDeclaration2Test.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDeclaration2Test.java index 985d2db887..9e83311025 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDeclaration2Test.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDeclaration2Test.java @@ -13,6 +13,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -87,8 +88,6 @@ public class ArrayDeclaration2Test { assertNotNull(result); } - - /** * Run the Declaration getElementType() method test. */ @@ -141,4 +140,34 @@ public class ArrayDeclaration2Test { assertEquals(left, right); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(2016, fixture.hashCode()); + assertEquals(new ArrayDeclaration(1, new StringDeclaration()).hashCode(), fixture.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + ArrayDeclaration a = new ArrayDeclaration(1, IntegerDeclaration.INT_32B_DECL); + ArrayDeclaration b = new ArrayDeclaration(2, IntegerDeclaration.INT_32B_DECL); + ArrayDeclaration c = new ArrayDeclaration(1, new StringDeclaration()); + ArrayDeclaration d = new ArrayDeclaration(1, IntegerDeclaration.INT_32B_DECL); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertEquals(a, d); + assertEquals(a, a); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertEquals(d, a); + assertEquals(a, a); + } } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDefinition2Test.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDefinition2Test.java index fef7455881..76366c8a1f 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDefinition2Test.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/ArrayDefinition2Test.java @@ -11,7 +11,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -86,7 +86,7 @@ public class ArrayDefinition2Test { return temp; } - private ArrayDefinition setUpDeclaration(IDeclaration decl, + private ArrayDefinition setUpDeclaration(@NonNull IDeclaration decl, @NonNull List defs) { CompoundDeclaration ad = new ArrayDeclaration(0, decl); ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs); diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/EnumDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/EnumDeclarationTest.java index cce60ef3c5..cb891cd89d 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/EnumDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/EnumDeclarationTest.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -120,4 +121,52 @@ public class EnumDeclarationTest { String left = "[declaration] enum["; assertEquals(left, result.substring(0, left.length())); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(-709790042, fixture.hashCode()); + EnumDeclaration a = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + a.add(0, 1, "hello"); + a.add(2, 3, "kitty"); + assertEquals(-82535941, a.hashCode()); + EnumDeclaration b = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1, + ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8)); + assertEquals(b.hashCode(), fixture.hashCode()); + assertNotEquals(a.hashCode(), fixture.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + EnumDeclaration a = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + EnumDeclaration b = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + b.add(2, 19, "hi"); + EnumDeclaration c = new EnumDeclaration(IntegerDeclaration.INT_32B_DECL); + EnumDeclaration d = new EnumDeclaration(IntegerDeclaration.INT_8_DECL); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertNotEquals(b, c); + assertEquals(a, d); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertNotEquals(c, b); + assertEquals(d, a); + a.add(2, 19, "hi"); + assertEquals(a, a); + assertEquals(a, b); + assertEquals(b, a); + assertNotEquals(a, d); + assertNotEquals(d, a); + d.add(2, 22, "hi"); + assertNotEquals(a, d); + assertNotEquals(d, a); + } + } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/FloatDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/FloatDeclarationTest.java index 0bc3d4146a..0ca5ce2994 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/FloatDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/FloatDeclarationTest.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -24,11 +25,10 @@ import org.junit.Test; public class FloatDeclarationTest { private FloatDeclaration fixture; - @Test public void ctorTest() { - for( int i = 1; i < 20; i++) { - fixture = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), 0); + for (int i = 1; i < 20; i++) { + fixture = new FloatDeclaration(i, 32 - i, ByteOrder.nativeOrder(), 0); assertNotNull(fixture); } } @@ -36,10 +36,10 @@ public class FloatDeclarationTest { @Test public void getterTest() { fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 1); - assertEquals( fixture.getAlignment(), 1); - assertEquals( fixture.getByteOrder(), ByteOrder.nativeOrder()); - assertEquals( fixture.getExponent(), 8); - assertEquals( fixture.getMantissa(), 24); + assertEquals(fixture.getAlignment(), 1); + assertEquals(fixture.getByteOrder(), ByteOrder.nativeOrder()); + assertEquals(fixture.getExponent(), 8); + assertEquals(fixture.getMantissa(), 24); } @Test @@ -47,4 +47,44 @@ public class FloatDeclarationTest { fixture = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0); assertTrue(fixture.toString().contains("float")); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + FloatDeclaration floatDeclaration = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); + FloatDeclaration a = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); + FloatDeclaration b = new FloatDeclaration(8, 24, ByteOrder.LITTLE_ENDIAN, 0); + assertEquals(5106065, floatDeclaration.hashCode()); + assertEquals(a.hashCode(), floatDeclaration.hashCode()); + assertNotEquals(b.hashCode(), floatDeclaration.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + FloatDeclaration a = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); + FloatDeclaration b = new FloatDeclaration(8, 24, ByteOrder.LITTLE_ENDIAN, 0); + FloatDeclaration c = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 8); + FloatDeclaration d = new FloatDeclaration(8, 8, ByteOrder.BIG_ENDIAN, 0); + FloatDeclaration e = new FloatDeclaration(24, 24, ByteOrder.BIG_ENDIAN, 0); + FloatDeclaration f = new FloatDeclaration(8, 24, ByteOrder.BIG_ENDIAN, 0); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertNotEquals(a, d); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertNotEquals(d, a); + assertNotEquals(e, a); + assertNotEquals(a, e); + + assertEquals(a, f); + assertEquals(f, a); + assertEquals(a, a); + } } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java index 3c5e6b2299..8b26c5a25a 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/IntegerDeclarationTest.java @@ -13,6 +13,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import java.math.BigInteger; @@ -277,4 +278,48 @@ public class IntegerDeclarationTest { IntegerDeclaration unsigned64bit = IntegerDeclaration.createDeclaration(64, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32); assertEquals(BigInteger.ZERO, unsigned64bit.getMinValue()); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(234767053, IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8).hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + IntegerDeclaration a = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 32); + IntegerDeclaration b = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 32); + IntegerDeclaration c = IntegerDeclaration.createDeclaration(32, true, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 32); + IntegerDeclaration d = IntegerDeclaration.createDeclaration(32, false, 16, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 32); + IntegerDeclaration e = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 32); + IntegerDeclaration f = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "", 32); + IntegerDeclaration g = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "hi", 32); + IntegerDeclaration h = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 16); + IntegerDeclaration i = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 32); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertNotEquals(a, d); + assertNotEquals(a, e); + assertNotEquals(a, f); + assertNotEquals(a, g); + assertNotEquals(a, h); + assertEquals(a, i); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertNotEquals(d, a); + assertNotEquals(e, a); + assertNotEquals(f, a); + assertNotEquals(g, a); + assertNotEquals(h, a); + assertEquals(i, a); + assertEquals(a, a); + } + } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java index 9ffed7e93e..4eaf405f92 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/SequenceDeclaration2Test.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; @@ -45,17 +46,19 @@ import com.google.common.collect.ImmutableList; @SuppressWarnings("javadoc") public class SequenceDeclaration2Test { - @NonNull private static final String FIELD_NAME = "LengthName"; + @NonNull + private static final String FIELD_NAME = "LengthName"; private SequenceDeclaration fixture; - @NonNull private BitBuffer input = new BitBuffer(); + @NonNull + private BitBuffer input = new BitBuffer(); @Before public void setUp() { fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration()); byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' }; ByteBuffer byb = ByteBuffer.wrap(array); - if( byb == null){ + if (byb == null) { throw new IllegalStateException("Failed to allocate memory"); } input = new BitBuffer(byb); @@ -123,4 +126,40 @@ public class SequenceDeclaration2Test { String left = "[declaration] sequence["; assertEquals(left, result.substring(0, left.length())); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(-1140774256, fixture.hashCode()); + SequenceDeclaration a = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL); + SequenceDeclaration b = new SequenceDeclaration("Hello", IntegerDeclaration.INT_32B_DECL); + SequenceDeclaration c = new SequenceDeclaration("Hi", new StringDeclaration()); + SequenceDeclaration d = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL); + assertNotEquals(a.hashCode(), b.hashCode()); + assertNotEquals(a.hashCode(), c.hashCode()); + assertEquals(a.hashCode(), d.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + SequenceDeclaration a = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL); + SequenceDeclaration b = new SequenceDeclaration("Hello", IntegerDeclaration.INT_32B_DECL); + SequenceDeclaration c = new SequenceDeclaration("Hi", new StringDeclaration()); + SequenceDeclaration d = new SequenceDeclaration("Hi", IntegerDeclaration.INT_32B_DECL); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertEquals(a, d); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertEquals(d, a); + assertEquals(a, a); + } + } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDeclarationTest.java index f4f17bedff..d723f488ea 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StringDeclarationTest.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import java.nio.ByteBuffer; @@ -115,4 +116,39 @@ public class StringDeclarationTest { assertEquals(left, right); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(32, fixture.hashCode()); + StringDeclaration a = new StringDeclaration(Encoding.ASCII); + StringDeclaration b = new StringDeclaration(); + StringDeclaration c = new StringDeclaration(Encoding.UTF8); + StringDeclaration d = new StringDeclaration(Encoding.ASCII); + assertNotEquals(a.hashCode(), b.hashCode()); + assertNotEquals(a.hashCode(), c.hashCode()); + assertEquals(a.hashCode(), d.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + StringDeclaration a = new StringDeclaration(Encoding.ASCII); + StringDeclaration b = new StringDeclaration(); + StringDeclaration c = new StringDeclaration(Encoding.UTF8); + StringDeclaration d = new StringDeclaration(Encoding.ASCII); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertEquals(a, d); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertEquals(d, a); + assertEquals(a, a); + } } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StructDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StructDeclarationTest.java index a8578b4a94..ca0bf7844e 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StructDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/StructDeclarationTest.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -20,6 +21,7 @@ import java.nio.ByteBuffer; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration; +import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.StringDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration; import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition; @@ -79,7 +81,7 @@ public class StructDeclarationTest { public void testCreateDefinition() throws CTFReaderException { String fieldName = ""; ByteBuffer allocate = ByteBuffer.allocate(100); - if( allocate == null){ + if (allocate == null) { throw new IllegalStateException("Failed to allocate memory"); } BitBuffer bb = new BitBuffer(allocate); @@ -138,4 +140,59 @@ public class StructDeclarationTest { assertEquals("[declaration] struct[", trunc); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(32, fixture.hashCode()); + StructDeclaration a = new StructDeclaration(8); + fixture.addField("hello", a); + a.addField("Time", IntegerDeclaration.INT_32B_DECL); + assertEquals(-864123628, fixture.hashCode()); + StructDeclaration b = new StructDeclaration(8); + StructDeclaration c = new StructDeclaration(8); + b.addField("hello", c); + c.addField("Time", IntegerDeclaration.INT_32B_DECL); + assertEquals(b.hashCode(), fixture.hashCode()); + c.addField("Space", IntegerDeclaration.INT_32L_DECL); + assertNotEquals(b.hashCode(), fixture.hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + StructDeclaration a = new StructDeclaration(8); + StructDeclaration b = new StructDeclaration(16); + StructDeclaration c = new StructDeclaration(8); + StructDeclaration d = new StructDeclaration(8); + StructDeclaration e = new StructDeclaration(8); + StructDeclaration f = new StructDeclaration(8); + c.addField("hi", new StringDeclaration()); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertEquals(a, d); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertEquals(d, a); + assertEquals(a, a); + a.addField("hi", new StringDeclaration()); + f.addField("hi", new StringDeclaration()); + e.addField("hello", new StringDeclaration()); + assertEquals(a, c); + assertEquals(c, a); + assertNotEquals(a, d); + d.addField("hi", IntegerDeclaration.INT_32B_DECL); + assertNotEquals(a, d); + a.addField("hello", new StringDeclaration()); + e.addField("hi", new StringDeclaration()); + f.addField("hello", IntegerDeclaration.INT_32B_DECL); + assertNotEquals(a, e); + assertNotEquals(a, f); + } } diff --git a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java index d505ba021a..b3b0a8d32d 100644 --- a/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java +++ b/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/VariantDeclarationTest.java @@ -12,6 +12,7 @@ package org.eclipse.tracecompass.ctf.core.tests.types; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assume.assumeTrue; @@ -141,7 +142,7 @@ public class VariantDeclarationTest { IDefinitionScope definitionScope = createDefinitionScope(); String fieldName = ""; ByteBuffer allocate = ByteBuffer.allocate(100); - if( allocate == null){ + if (allocate == null) { throw new IllegalStateException("Failed to allocate memory"); } BitBuffer bb = new BitBuffer(allocate); @@ -206,4 +207,78 @@ public class VariantDeclarationTest { assertEquals(left, right); } + + /** + * Test the hashcode + */ + @Test + public void hashcodeTest() { + assertEquals(923521, fixture.hashCode()); + assertEquals(fixture.hashCode(), new VariantDeclaration().hashCode()); + } + + /** + * Test the equals + */ + @Test + public void equalsTest() { + VariantDeclaration a = new VariantDeclaration(); + VariantDeclaration b = new VariantDeclaration(); + b.addField("hi", new StringDeclaration()); + VariantDeclaration c = new VariantDeclaration(); + c.addField("hi", new StringDeclaration()); + VariantDeclaration d = new VariantDeclaration(); + assertNotEquals(a, null); + assertNotEquals(a, new Object()); + assertNotEquals(a, b); + assertNotEquals(a, c); + assertEquals(a, d); + assertEquals(a, a); + assertEquals(b, c); + assertNotEquals(b, a); + assertNotEquals(c, a); + assertEquals(d, a); + assertEquals(c, b); + b.setTag("hi"); + assertNotEquals(b, c); + c.setTag("Hello"); + assertNotEquals(b, c); + c.setTag("hi"); + assertEquals(b, c); + b.addField("hello", IntegerDeclaration.INT_32B_DECL); + d.addField("hello", IntegerDeclaration.INT_32B_DECL); + d.addField("hi", new StringDeclaration()); + d.setTag("hi"); + assertEquals(b, d); + assertEquals(d, b); + } + + /** + * Test the equals out of order + */ + @Test + public void equalsOutOfOrderTest() { + VariantDeclaration a = new VariantDeclaration(); + VariantDeclaration b = new VariantDeclaration(); + b.addField("hi", new StringDeclaration()); + b.addField("hello", new VariantDeclaration()); + a.addField("hello", new VariantDeclaration()); + a.addField("hi", new StringDeclaration()); + assertEquals(b, a); + } + + /** + * Test the equals out of order + */ + @Test + public void equalsAddTwiceTest() { + VariantDeclaration a = new VariantDeclaration(); + VariantDeclaration b = new VariantDeclaration(); + b.addField("hi", new StringDeclaration()); + a.addField("hi", new StringDeclaration()); + assertEquals(b, a); + b.addField("hi", new VariantDeclaration()); + assertNotEquals(b, a); + } + } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDeclaration.java index 79447f8d99..5cec591dbd 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDeclaration.java @@ -151,7 +151,7 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp public EnumTable() { } - public boolean add(long low, long high, @Nullable String label) { + public synchronized boolean add(long low, long high, @Nullable String label) { LabelAndRange newRange = new LabelAndRange(low, high, label); for (LabelAndRange r : ranges) { @@ -172,7 +172,7 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp * the value to query * @return the label corresponding to that value */ - public @Nullable String query(long value) { + public synchronized @Nullable String query(long value) { for (LabelAndRange r : ranges) { if (r.intersects(value)) { return r.getLabel(); @@ -181,6 +181,39 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp return null; } + @Override + public synchronized int hashCode() { + final int prime = 31; + int result = 1; + for (LabelAndRange range : ranges) { + result = prime * result + range.hashCode(); + } + return result; + } + + @Override + public synchronized boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnumTable other = (EnumTable) obj; + if (ranges.size() != other.ranges.size()) { + return false; + } + for (int i = 0; i < ranges.size(); i++) { + if (!ranges.get(i).equals(other.ranges.get(i))) { + return false; + } + } + return true; + } + } private static class LabelAndRange { @@ -193,8 +226,7 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp * * @return the label */ - @Nullable - public String getLabel() { + public @Nullable String getLabel() { return fLabel; } @@ -212,6 +244,46 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp return this.intersects(other.low) || this.intersects(other.high); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + final String label = fLabel; + result = prime * result + ((label == null) ? 0 : label.hashCode()); + result = prime * result + (int) (high ^ (high >>> 32)); + result = prime * result + (int) (low ^ (low >>> 32)); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LabelAndRange other = (LabelAndRange) obj; + final String label = fLabel; + if (label == null) { + if (other.fLabel != null) { + return false; + } + } else if (!label.equals(other.fLabel)) { + return false; + } + if (high != other.high) { + return false; + } + if (low != other.low) { + return false; + } + return true; + } } @Override @@ -220,4 +292,42 @@ public final class EnumDeclaration extends Declaration implements ISimpleDatatyp return "[declaration] enum[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ } + @Override + public int hashCode() { + final int prime = 31; + int result = prime + fContainerType.hashCode(); + for (String label : fLabels) { + result = prime * result + label.hashCode(); + } + result = prime * result + fTable.hashCode(); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnumDeclaration other = (EnumDeclaration) obj; + if (!fContainerType.equals(other.fContainerType)) { + return false; + } + if (fLabels.size() != other.fLabels.size()) { + return false; + } + if (!fLabels.containsAll(other.fLabels)) { + return false; + } + if (!fTable.equals(other.fTable)) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/FloatDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/FloatDeclaration.java index 26ed60f8a2..992e9fef22 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/FloatDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/FloatDeclaration.java @@ -181,4 +181,43 @@ public final class FloatDeclaration extends Declaration implements ISimpleDataty ret *= expPow; return ret; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (fAlignement ^ (fAlignement >>> 32)); + result = prime * result + (fByteOrder.equals(ByteOrder.BIG_ENDIAN) ? 4321 : 1234); + result = prime * result + fExponent; + result = prime * result + fMantissa; + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + FloatDeclaration other = (FloatDeclaration) obj; + if (fAlignement != other.fAlignement) { + return false; + } + if (!fByteOrder.equals(other.fByteOrder)) { + return false; + } + if (fExponent != other.fExponent) { + return false; + } + if (fMantissa != other.fMantissa) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java index ab670cc52c..feb739690f 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IDeclaration.java @@ -78,4 +78,10 @@ public interface IDeclaration { */ int getMaximumSize(); + @Override + public abstract int hashCode(); + + @Override + public abstract boolean equals(Object other); + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java index 95bc7c8825..092850be38 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/IntegerDeclaration.java @@ -471,4 +471,67 @@ public class IntegerDeclaration extends Declaration implements ISimpleDatatypeDe return bits; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (fAlignment ^ (fAlignment >>> 32)); + result = prime * result + fBase; + result = prime * result + (fByteOrder.equals(ByteOrder.BIG_ENDIAN) ? 4321 : 1234); + result = prime * result + (fClock.hashCode()); + switch (fEncoding) { + case ASCII: + result = prime * result + 1; + break; + case NONE: + result = prime * result + 2; + break; + case UTF8: + result = prime * result + 3; + break; + default: + result = prime * result + 4; + break; + } + result = prime * result + fLength; + result = prime * result + (fSigned ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + IntegerDeclaration other = (IntegerDeclaration) obj; + if (fAlignment != other.fAlignment) { + return false; + } + if (fBase != other.fBase) { + return false; + } + if (!fByteOrder.equals(other.fByteOrder)) { + return false; + } + if (!fClock.equals(other.fClock)) { + return false; + } + if (fEncoding != other.fEncoding) { + return false; + } + if (fLength != other.fLength) { + return false; + } + if (fSigned != other.fSigned) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StringDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StringDeclaration.java index f687b7ae2c..086f0705d7 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StringDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StringDeclaration.java @@ -48,7 +48,9 @@ public class StringDeclaration extends Declaration { /** * Generate an encoded string declaration - * @param encoding the encoding, utf8 or ascii + * + * @param encoding + * the encoding, utf8 or ascii */ public StringDeclaration(Encoding encoding) { fEncoding = encoding; @@ -79,6 +81,7 @@ public class StringDeclaration extends Declaration { public int getMaximumSize() { return Integer.MAX_VALUE; } + // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ @@ -105,10 +108,51 @@ public class StringDeclaration extends Declaration { } return sb.toString(); } + @Override public String toString() { /* Only used for debugging */ return "[declaration] string[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ } + @Override + public int hashCode() { + final int prime = 31; + int result = prime; + if (fEncoding != null) { + switch (fEncoding) { + case ASCII: + result += 1; + break; + case NONE: + result += 2; + break; + case UTF8: + result += 3; + break; + default: + break; + } + } + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StringDeclaration other = (StringDeclaration) obj; + if (fEncoding != other.fEncoding) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java index ca73296ec9..a88b26e744 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java @@ -12,9 +12,12 @@ package org.eclipse.tracecompass.ctf.core.event.types; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -232,7 +235,10 @@ public class StructDeclaration extends Declaration { public int hashCode() { final int prime = 31; int result = 1; - result = (prime * result) + fFieldMap.entrySet().hashCode(); + for (Entry field : fFieldMap.entrySet()) { + result = prime * result + field.getKey().hashCode(); + result = prime * result + field.getValue().hashCode(); + } result = (prime * result) + (int) (fMaxAlign ^ (fMaxAlign >>> 32)); return result; } @@ -249,9 +255,30 @@ public class StructDeclaration extends Declaration { return false; } StructDeclaration other = (StructDeclaration) obj; - if (!fFieldMap.entrySet().equals(other.fFieldMap.entrySet())) { + if (fFieldMap.size() != other.fFieldMap.size()) { return false; } + + List localFieldNames = new ArrayList<>(); + localFieldNames.addAll(fFieldMap.keySet()); + + List localDecs = new ArrayList<>(); + localDecs.addAll(fFieldMap.values()); + + List otherFieldNames = new ArrayList<>(); + otherFieldNames.addAll(other.fFieldMap.keySet()); + + List otherDecs = new ArrayList<>(); + otherDecs.addAll(other.fFieldMap.values()); + + //check fields in order + for (int i = 0; i < fFieldMap.size(); i++) { + if ((!localFieldNames.get(i).equals(otherFieldNames.get(i))) || + (!otherDecs.get(i).equals(localDecs.get(i)))) { + return false; + } + } + if (fMaxAlign != other.fMaxAlign) { return false; } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java index 618cc5d283..f8c119e23a 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDeclaration.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer; import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope; @@ -186,4 +187,76 @@ public class VariantDeclaration extends Declaration { return "[declaration] variant[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fDeclarationToPopulate == null) ? 0 : fDeclarationToPopulate.hashCode()); + if (fFields == null) { + result = prime * result; + } else { + for (Entry field : fFields.entrySet()) { + result = prime * result + field.getValue().hashCode(); + } + } + result = prime * result + ((fPrevDefinitionScope == null) ? 0 : fPrevDefinitionScope.hashCode()); + result = prime * result + ((fTag == null) ? 0 : fTag.hashCode()); + result = prime * result + ((fTagDef == null) ? 0 : fTagDef.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + VariantDeclaration other = (VariantDeclaration) obj; + if (fDeclarationToPopulate == null) { + if (other.fDeclarationToPopulate != null) { + return false; + } + } else if (!fDeclarationToPopulate.equals(other.fDeclarationToPopulate)) { + return false; + } + // do not check the order of the fields + + if (fFields == null) { + if (other.fFields != null) { + return false; + } + } else { + if( !fFields.equals(other.fFields)) { + return false; + } + } + if (fPrevDefinitionScope == null) { + if (other.fPrevDefinitionScope != null) { + return false; + } + } else if (!fPrevDefinitionScope.equals(other.fPrevDefinitionScope)) { + return false; + } + if (fTag == null) { + if (other.fTag != null) { + return false; + } + } else if (!fTag.equals(other.fTag)) { + return false; + } + if (fTagDef == null) { + if (other.fTagDef != null) { + return false; + } + } else if (!fTagDef.equals(other.fTagDef)) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ArrayDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ArrayDeclaration.java index 713308bdef..dba627d3fa 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ArrayDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/ArrayDeclaration.java @@ -58,7 +58,7 @@ public final class ArrayDeclaration extends CompoundDeclaration { * * TODO: investigate performance */ - private final ArrayListMultimap fChildrenNames = ArrayListMultimap.create(); + private final transient ArrayListMultimap fChildrenNames = ArrayListMultimap.create(); // ------------------------------------------------------------------------ // Constructors @@ -118,8 +118,7 @@ public final class ArrayDeclaration extends CompoundDeclaration { return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$ } - @NonNull - private List read(@NonNull BitBuffer input, @Nullable IDefinitionScope definitionScope, String fieldName) throws CTFReaderException { + private @NonNull List read(@NonNull BitBuffer input, @Nullable IDefinitionScope definitionScope, String fieldName) throws CTFReaderException { Builder definitions = new ImmutableList.Builder<>(); if (!fChildrenNames.containsKey(fieldName)) { for (int i = 0; i < fLength; i++) { @@ -146,4 +145,34 @@ public final class ArrayDeclaration extends CompoundDeclaration { return (int) Math.min(Integer.MAX_VALUE, val); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + fElemType.hashCode(); + result = prime * result + fLength; + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ArrayDeclaration other = (ArrayDeclaration) obj; + if (!fElemType.equals(other.fElemType)) { + return false; + } + if (fLength != other.fLength) { + return false; + } + return true; + } + } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/SequenceDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/SequenceDeclaration.java index 5c958cca38..953d6e2e25 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/SequenceDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/SequenceDeclaration.java @@ -136,8 +136,7 @@ public class SequenceDeclaration extends CompoundDeclaration { definitions.add(fElemType.createDefinition(definitionScope, elemName, input)); } @SuppressWarnings("null") - @NonNull - ImmutableList build = definitions.build(); + @NonNull ImmutableList build = definitions.build(); return new ArrayDefinition(this, definitionScope, fieldName, build); } @@ -152,4 +151,34 @@ public class SequenceDeclaration extends CompoundDeclaration { return Integer.MAX_VALUE; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + fElemType.hashCode(); + result = prime * result + fLengthName.hashCode(); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SequenceDeclaration other = (SequenceDeclaration) obj; + if (!fElemType.equals(other.fElemType)) { + return false; + } + if (!fLengthName.equals(other.fLengthName)) { + return false; + } + return true; + } + } \ No newline at end of file diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java index b4b860aea2..883cc5ce8a 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderCompactDeclaration.java @@ -243,4 +243,31 @@ public class EventHeaderCompactDeclaration extends Declaration implements IEvent } return bo; } + +@Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (fByteOrder.equals(ByteOrder.BIG_ENDIAN) ? 4321 : 1234); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EventHeaderCompactDeclaration other = (EventHeaderCompactDeclaration) obj; + if (!fByteOrder.equals(other.fByteOrder)) { + return false; + } + return true; + } + } diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java index 177da8dc8f..0278099d87 100644 --- a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java +++ b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/types/composite/EventHeaderLargeDeclaration.java @@ -241,4 +241,30 @@ public class EventHeaderLargeDeclaration extends Declaration implements IEventHe return bo; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (fByteOrder.equals(ByteOrder.BIG_ENDIAN) ? 4321 : 1234); + return result; + } + + @Override + public boolean equals(@Nullable Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EventHeaderLargeDeclaration other = (EventHeaderLargeDeclaration) obj; + if (!fByteOrder.equals(other.fByteOrder)) { + return false; + } + return true; + } + } -- 2.34.1