forked from JetBrains/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tupleGen.py
48 lines (41 loc) · 1.88 KB
/
tupleGen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def generateTupleClass(i):
f = open("stdlib/src/jet/Tuple" + str(i) + ".java", "w")
f.write("package jet;\n\n")
f.write("public class Tuple" + str(i) + "<")
f.write(", ".join(("T" + str(j)) for j in range(1, i+1)))
f.write("> extends DefaultJetObject {\n")
for j in range(1, i+1):
f.write(" public final T{0} _{0};\n".format(j))
f.write("\n public Tuple" + str(i) + "(")
if i > 0:
f.write("TypeInfo typeInfo, ")
f.write(", ".join("T{0} t{0}".format(j) for j in range(1, i+1)))
f.write(") {\n")
if i > 0:
f.write(" super(typeInfo);\n")
for j in range(1, i+1):
f.write(" _{0} = t{0};\n".format(j))
f.write(" }\n\n")
f.write(" @Override\n public String toString() {\n")
f.write(' return "(" + ' + ' + ", " + '.join("_{0}".format(j) for j in range(1, i+1)) + ' + ")";\n')
f.write(" }\n")
for j in range(1, i+1):
f.write(" public final T{0} get_{0}() {{\n return _{0};\n }}\n".format(j))
f.write(" @Override\n public boolean equals(Object o) {\n")
f.write(" if (this == o) return true;\n")
f.write(" if (o == null || getClass() != o.getClass()) return false;\n\n")
f.write(" Tuple{0} t = (Tuple{0}) o;\n".format(i))
for j in range(1, i+1):
f.write(" if (_{0} != null ? !_{0}.equals(t._{0}) : t._{0} != null) return false;\n".format(j))
f.write(" return true;\n")
f.write(" }\n")
f.write(" @Override\n public int hashCode() {\n")
f.write(" int result = _1 != null ? _1.hashCode() : 0;\n")
for j in range(2, i+1):
f.write(" result = 31 * result + (_{0} != null ? _{0}.hashCode() : 0);\n".format(j))
f.write(" return result;\n")
f.write(" }\n")
f.write("}")
f.close()
for i in range(1, 23):
generateTupleClass(i)