@@ -13,39 +13,82 @@ class Java extends LanguageMeta {
13
13
type = "String";
14
14
break;
15
15
case AttributeType.INTEGER:
16
- type = "Int ";
16
+ type = "Integer ";
17
17
break;
18
18
case AttributeType.FLOAT:
19
- type = "Float ";
19
+ type = "Double ";
20
20
break;
21
21
case AttributeType.BOOLEAN:
22
22
type = "Boolean";
23
23
break;
24
24
case AttributeType.RELATIONSHIP:
25
- type = "Map<String , Any >";
25
+ type = "Map<String , Object >";
26
26
break;
27
27
default:
28
28
throw new Error(`Unknown attribute type: ${attribute.type}`);
29
29
}
30
30
if (attribute.array) {
31
31
type = "List< " + type + ">";
32
32
}
33
- if (attribute.required) {
34
- type += "?";
35
- }
36
33
return type;
37
34
}
38
35
39
36
getTemplate() {
40
37
return `package io.appwrite.models;
41
38
42
39
import java.util.*;
43
-
44
- public record <% - toPascalCase(collection.name) %> (
40
+
41
+ public class <% - toPascalCase(collection.name) %> {
42
+ <% for (const attribute of collection.attributes) { -%>
43
+ private <%= getType(attribute) %> <%= toCamelCase(attribute.key) %> ;
44
+ <% } -%>
45
+
46
+ public <% - toPascalCase(collection.name) %> () {
47
+ }
48
+
49
+ public <% - toPascalCase(collection.name) %> (
50
+ <% for (const [index, attribute] of Object .entries(collection.attributes)) { -%>
51
+ <%= getType(attribute) %> <%= toCamelCase(attribute.key) %><% - index < collection.attributes.length - 1 ? ' ,' : ' ' %>
52
+ <% } -%>
53
+ ) {
54
+ <% for (const attribute of collection.attributes) { -%>
55
+ this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %> ;
56
+ <% } -%>
57
+ }
58
+
59
+ <% for (const attribute of collection.attributes) { -%>
60
+ public <%= getType(attribute) %> get<% - toPascalCase(attribute.key) %> () {
61
+ return <%= toCamelCase(attribute.key) %> ;
62
+ }
63
+
64
+ public void set<% - toPascalCase(attribute.key) %> (<%= getType(attribute) %> <%= toCamelCase(attribute.key) %> ) {
65
+ this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %> ;
66
+ }
67
+
68
+ <% } -%>
69
+ @Override
70
+ public boolean equals(Object obj) {
71
+ if (this == obj) return true;
72
+ if (obj == null || getClass() != obj.getClass()) return false;
73
+ <% - toPascalCase(collection.name) %> that = (<% - toPascalCase(collection.name) %> ) obj;
74
+ return Objects.equals(<%= collection.attributes.map(attr => toCamelCase(attr .key)).join(' , ' ) %><% - collection.attributes.length > 1 ? ' , that.' + collection.attributes.map(attr => toCamelCase(attr .key)).join(' , that.' ) : collection.attributes.length === 1 ? ' , that.' + toCamelCase(collection.attributes[0 ].key) : ' ' %> );
75
+ }
76
+
77
+ @Override
78
+ public int hashCode() {
79
+ return Objects.hash(<%= collection.attributes.map(attr => toCamelCase(attr .key)).join(' , ' ) %> );
80
+ }
81
+
82
+ @Override
83
+ public String toString() {
84
+ return "<% - toPascalCase(collection.name) %> {" +
45
85
<% for (const [index, attribute] of Object .entries(collection.attributes)) { -%>
46
- <%= getType (attribute) %> <%= toCamelCase(attribute.key) %><% - index < collection.attributes.length - 1 ? ' , ' : ' ' %>
86
+ " <%= toCamelCase (attribute.key ) %> =" + <%= toCamelCase(attribute.key) %> +
47
87
<% } -%>
48
- ) { }`;
88
+ '}';
89
+ }
90
+ }
91
+ `;
49
92
}
50
93
51
94
getFileName(collection) {
0 commit comments