53
54 import java.util.ArrayList;
55 import java.util.Objects;
56
57 public class VirtualObjectDebugInfoTest extends DebugInfoTest {
58
59 private static class TestClass {
60
61 private long longField;
62 private int intField;
63 private float floatField;
64 private Object[] arrayField;
65
66 TestClass() {
67 this.longField = 8472;
68 this.intField = 42;
69 this.floatField = 3.14f;
70 this.arrayField = new Object[]{Integer.valueOf(58), this, null, Integer.valueOf(17), "Hello, World!"};
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (!(o instanceof TestClass)) {
76 return false;
77 }
78
79 TestClass other = (TestClass) o;
80 if (this.longField != other.longField || this.intField != other.intField || this.floatField != other.floatField || this.arrayField.length != other.arrayField.length) {
81 return false;
82 }
83
84 for (int i = 0; i < this.arrayField.length; i++) {
85 // break cycle
86 if (this.arrayField[i] == this && other.arrayField[i] == other) {
87 continue;
88 }
89
90 if (!Objects.equals(this.arrayField[i], other.arrayField[i])) {
91 return false;
92 }
|
53
54 import java.util.ArrayList;
55 import java.util.Objects;
56
57 public class VirtualObjectDebugInfoTest extends DebugInfoTest {
58
59 private static class TestClass {
60
61 private long longField;
62 private int intField;
63 private float floatField;
64 private Object[] arrayField;
65
66 TestClass() {
67 this.longField = 8472;
68 this.intField = 42;
69 this.floatField = 3.14f;
70 this.arrayField = new Object[]{Integer.valueOf(58), this, null, Integer.valueOf(17), "Hello, World!"};
71 }
72
73 @Override
74 public String toString() {
75 var builder = new StringBuilder()
76 .append("{l: ")
77 .append(longField)
78 .append("; ")
79 .append("i: ")
80 .append(intField)
81 .append("; ")
82 .append("f: ")
83 .append(floatField)
84 .append("; ")
85 .append("a[")
86 .append(arrayField.length)
87 .append("]: ");
88 for (int i = 0; i < arrayField.length; ++i) {
89 if (i != 0) {
90 builder.append("; ");
91 }
92 builder.append("[").append(i).append("]=");
93 if (arrayField[i] == this) {
94 builder.append("this");
95 } else {
96 builder.append(arrayField[i]);
97 }
98 }
99 builder.append("}");
100 return builder.toString();
101 }
102
103 @Override
104 public boolean equals(Object o) {
105 if (!(o instanceof TestClass)) {
106 return false;
107 }
108
109 TestClass other = (TestClass) o;
110 if (this.longField != other.longField || this.intField != other.intField || this.floatField != other.floatField || this.arrayField.length != other.arrayField.length) {
111 return false;
112 }
113
114 for (int i = 0; i < this.arrayField.length; i++) {
115 // break cycle
116 if (this.arrayField[i] == this && other.arrayField[i] == other) {
117 continue;
118 }
119
120 if (!Objects.equals(this.arrayField[i], other.arrayField[i])) {
121 return false;
122 }
|