Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/TestNodes.java @ 12388:96c1d057a5ed
Truffle: Added experimental serialization API.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 02 Oct 2013 15:33:08 +0200 |
parents | |
children | a08b8694f556 |
comparison
equal
deleted
inserted
replaced
12387:aff825fef0fd | 12388:96c1d057a5ed |
---|---|
1 /* | |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.test.nodes.serial; | |
24 | |
25 import java.util.*; | |
26 | |
27 import com.oracle.truffle.api.nodes.*; | |
28 | |
29 final class TestNodes { | |
30 | |
31 private TestNodes() { | |
32 } | |
33 | |
34 static class StringNode extends Node { | |
35 | |
36 private final String name; | |
37 | |
38 public StringNode(String name) { | |
39 this.name = name; | |
40 } | |
41 | |
42 @Override | |
43 public int hashCode() { | |
44 return Objects.hash(name); | |
45 } | |
46 | |
47 @Override | |
48 public boolean equals(Object obj) { | |
49 if (obj == null) { | |
50 return false; | |
51 } else if (obj.getClass() != getClass()) { | |
52 return false; | |
53 } else if ((((Node) obj).getParent() != null) && !((Node) obj).getParent().equals(getParent())) { | |
54 return false; | |
55 } else if (!Objects.equals(name, ((StringNode) obj).name)) { | |
56 return false; | |
57 } | |
58 return true; | |
59 } | |
60 } | |
61 | |
62 static class EmptyNode extends Node { | |
63 | |
64 @Override | |
65 public int hashCode() { | |
66 return super.hashCode(); | |
67 } | |
68 | |
69 @Override | |
70 public boolean equals(Object obj) { | |
71 if (obj == null) { | |
72 return false; | |
73 } else if (obj.getClass() != getClass()) { | |
74 return false; | |
75 } else if ((((Node) obj).getParent() != null) && !((Node) obj).getParent().equals(getParent())) { | |
76 return false; | |
77 } | |
78 return true; | |
79 } | |
80 } | |
81 | |
82 static class NodeWithOneChild extends EmptyNode { | |
83 | |
84 @Child Node child; | |
85 | |
86 public NodeWithOneChild(Node child) { | |
87 this.child = adoptChild(child); | |
88 } | |
89 | |
90 } | |
91 | |
92 static class NodeWithTwoChilds extends EmptyNode { | |
93 | |
94 @Child Node child1; | |
95 @Child Node child2; | |
96 | |
97 public NodeWithTwoChilds(Node child1, Node child2) { | |
98 this.child1 = adoptChild(child1); | |
99 this.child2 = adoptChild(child2); | |
100 } | |
101 | |
102 } | |
103 | |
104 static class NodeWithThreeChilds extends EmptyNode { | |
105 | |
106 @Child Node child1; | |
107 @Child Node child2; | |
108 @Child Node child3; | |
109 | |
110 public NodeWithThreeChilds(Node child1, Node child2, Node child3) { | |
111 this.child1 = adoptChild(child1); | |
112 this.child2 = adoptChild(child2); | |
113 this.child3 = adoptChild(child3); | |
114 } | |
115 | |
116 } | |
117 | |
118 static class NodeWithArray extends EmptyNode { | |
119 | |
120 @Children private final Node[] childNodes; | |
121 | |
122 NodeWithArray(Node[] children) { | |
123 this.childNodes = adoptChildren(children); | |
124 } | |
125 | |
126 Node[] getChildNodes() { | |
127 return childNodes; | |
128 } | |
129 } | |
130 | |
131 static class NodeWithTwoArray extends EmptyNode { | |
132 | |
133 @Children private final Node[] childNodes1; | |
134 @Children private final Node[] childNodes2; | |
135 | |
136 NodeWithTwoArray(Node[] childs1, Node[] childs2) { | |
137 this.childNodes1 = adoptChildren(childs1); | |
138 this.childNodes2 = adoptChildren(childs2); | |
139 } | |
140 | |
141 Node[] getChildNodes1() { | |
142 return childNodes1; | |
143 } | |
144 | |
145 Node[] getChildNodes2() { | |
146 return childNodes2; | |
147 } | |
148 } | |
149 | |
150 static class NodeWithFields extends EmptyNode { | |
151 | |
152 String stringField; | |
153 int integerField; | |
154 Integer integerObjectField; | |
155 long longField; | |
156 Long longObjectField; | |
157 float floatField; | |
158 Float floatObjectField; | |
159 double doubleField; | |
160 Double doubleObjectField; | |
161 char charField; | |
162 Character charObjectField; | |
163 short shortField; | |
164 Short shortObjecField; | |
165 byte byteField; | |
166 Byte byteObjectField; | |
167 boolean booleanField; | |
168 Boolean booleanObjectfield; | |
169 | |
170 public NodeWithFields(String stringField, int integerField, Integer integerObjectField, long longField, Long longObjectField, float floatField, Float floatObjectField, double doubleField, | |
171 Double doubleObjectField, char charField, Character charObjectField, short shortField, Short shortObjecField, byte byteField, Byte byteObjectField, boolean booleanField, | |
172 Boolean booleanObjectfield) { | |
173 this.stringField = stringField; | |
174 this.integerField = integerField; | |
175 this.integerObjectField = integerObjectField; | |
176 this.longField = longField; | |
177 this.longObjectField = longObjectField; | |
178 this.floatField = floatField; | |
179 this.floatObjectField = floatObjectField; | |
180 this.doubleField = doubleField; | |
181 this.doubleObjectField = doubleObjectField; | |
182 this.charField = charField; | |
183 this.charObjectField = charObjectField; | |
184 this.shortField = shortField; | |
185 this.shortObjecField = shortObjecField; | |
186 this.byteField = byteField; | |
187 this.byteObjectField = byteObjectField; | |
188 this.booleanField = booleanField; | |
189 this.booleanObjectfield = booleanObjectfield; | |
190 } | |
191 | |
192 @Override | |
193 public int hashCode() { | |
194 return Objects.hash(stringField, integerField, integerObjectField, longField, longObjectField, floatField, floatObjectField, doubleField, doubleObjectField, charField, charObjectField, | |
195 shortField, shortObjecField, byteField, byteObjectField, booleanField, booleanObjectfield); | |
196 } | |
197 | |
198 @Override | |
199 public boolean equals(Object obj) { | |
200 if (this == obj) { | |
201 return true; | |
202 } | |
203 if (obj.getClass() != getClass()) { | |
204 return false; | |
205 } | |
206 NodeWithFields o = (NodeWithFields) obj; | |
207 return Objects.deepEquals(fieldArray(), o.fieldArray()); | |
208 } | |
209 | |
210 private Object[] fieldArray() { | |
211 return array(stringField, integerField, integerObjectField, longField, longObjectField, floatField, floatObjectField, doubleField, doubleObjectField, charField, charObjectField, | |
212 shortField, shortObjecField, byteField, byteObjectField, booleanField, booleanObjectfield); | |
213 } | |
214 | |
215 private static Object[] array(Object... values) { | |
216 return values; | |
217 } | |
218 | |
219 } | |
220 | |
221 } |