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;
assertNotNull(result);
}
-
-
/**
* Run the Declaration getElementType() method test.
*/
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);
+ }
}
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;
return temp;
}
- private ArrayDefinition setUpDeclaration(IDeclaration decl,
+ private ArrayDefinition setUpDeclaration(@NonNull IDeclaration decl,
@NonNull List<Definition> defs) {
CompoundDeclaration ad = new ArrayDeclaration(0, decl);
ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
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;
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);
+ }
+
}
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;
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);
}
}
@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
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);
+ }
}
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;
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
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;
@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);
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);
+ }
+
}
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;
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
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;
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;
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);
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);
+ }
}
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;
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);
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
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) {
* 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();
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 {
*
* @return the label
*/
- @Nullable
- public String getLabel() {
+ public @Nullable String getLabel() {
return fLabel;
}
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
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;
+ }
+
}
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;
+ }
+
}
*/
int getMaximumSize();
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(Object other);
+
}
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;
+ }
+
}
/**
* 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;
public int getMaximumSize() {
return Integer.MAX_VALUE;
}
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
}
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;
+ }
+
}
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;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = (prime * result) + fFieldMap.entrySet().hashCode();
+ for (Entry<String, IDeclaration> field : fFieldMap.entrySet()) {
+ result = prime * result + field.getKey().hashCode();
+ result = prime * result + field.getValue().hashCode();
+ }
result = (prime * result) + (int) (fMaxAlign ^ (fMaxAlign >>> 32));
return result;
}
return false;
}
StructDeclaration other = (StructDeclaration) obj;
- if (!fFieldMap.entrySet().equals(other.fFieldMap.entrySet())) {
+ if (fFieldMap.size() != other.fFieldMap.size()) {
return false;
}
+
+ List<String> localFieldNames = new ArrayList<>();
+ localFieldNames.addAll(fFieldMap.keySet());
+
+ List<IDeclaration> localDecs = new ArrayList<>();
+ localDecs.addAll(fFieldMap.values());
+
+ List<String> otherFieldNames = new ArrayList<>();
+ otherFieldNames.addAll(other.fFieldMap.keySet());
+
+ List<IDeclaration> 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;
}
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;
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<String, IDeclaration> 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;
+ }
+
}
*
* TODO: investigate performance
*/
- private final ArrayListMultimap<String, String> fChildrenNames = ArrayListMultimap.create();
+ private final transient ArrayListMultimap<String, String> fChildrenNames = ArrayListMultimap.create();
// ------------------------------------------------------------------------
// Constructors
return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
}
- @NonNull
- private List<Definition> read(@NonNull BitBuffer input, @Nullable IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
+ private @NonNull List<Definition> read(@NonNull BitBuffer input, @Nullable IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
Builder<Definition> definitions = new ImmutableList.Builder<>();
if (!fChildrenNames.containsKey(fieldName)) {
for (int i = 0; i < fLength; i++) {
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
definitions.add(fElemType.createDefinition(definitionScope, elemName, input));
}
@SuppressWarnings("null")
- @NonNull
- ImmutableList<Definition> build = definitions.build();
+ @NonNull ImmutableList<Definition> build = definitions.build();
return new ArrayDefinition(this, definitionScope, fieldName, build);
}
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
}
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;
+ }
+
}
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;
+ }
+
}