3
3
import javaxt .json .*;
4
4
5
5
6
- public class Class implements Member {
6
+ public class Class implements Member , Comparable {
7
7
private String name ;
8
8
private String description ;
9
9
private Class parent ;
@@ -13,74 +13,74 @@ public class Class implements Member {
13
13
private ArrayList <String > extensions ;
14
14
private ArrayList <String > interfaces ;
15
15
16
-
16
+
17
17
public Class (String name ){
18
18
this .name = name ;
19
19
this .members = new ArrayList <>();
20
20
this .extensions = new ArrayList <>();
21
21
this .interfaces = new ArrayList <>();
22
22
}
23
-
23
+
24
24
public String getName (){
25
25
return name ;
26
26
}
27
-
27
+
28
28
public void setDescription (String description ){
29
29
this .description = description ;
30
30
}
31
-
31
+
32
32
public String getDescription (){
33
33
return description ;
34
34
}
35
-
35
+
36
36
public boolean isPublic (){
37
37
return isPublic ;
38
38
}
39
-
39
+
40
40
public void setPublic (boolean isPublic ){
41
41
this .isPublic = isPublic ;
42
42
}
43
-
43
+
44
44
public void setNamespace (String namespace ){
45
45
this .namespace = namespace ;
46
46
}
47
-
47
+
48
48
public String getNamespace (){
49
49
return namespace ;
50
50
}
51
-
51
+
52
52
public void addSuper (String className ){
53
53
extensions .add (className );
54
54
}
55
-
55
+
56
56
public ArrayList <String > getSuper (){
57
57
return extensions ;
58
58
}
59
-
59
+
60
60
public void addInterface (String className ){
61
61
interfaces .add (className );
62
62
}
63
-
63
+
64
64
public ArrayList <String > getInterfaces (){
65
65
return interfaces ;
66
66
}
67
-
67
+
68
68
public void addMember (Member member ){
69
69
members .add (member );
70
70
}
71
-
71
+
72
72
public ArrayList <Member > getMembers (){
73
73
return members ;
74
74
}
75
-
75
+
76
76
public ArrayList <Class > getClasses (){
77
77
ArrayList <Class > classes = new ArrayList <>();
78
78
for (Member member : members ){
79
79
if (member instanceof Class ) classes .add ((Class ) member );
80
80
}
81
81
return classes ;
82
82
}
83
-
83
+
84
84
public ArrayList <Constructor > getConstructors (){
85
85
ArrayList <Constructor > constructors = new ArrayList <>();
86
86
for (Member member : members ){
@@ -93,7 +93,7 @@ public ArrayList<Constructor> getConstructors(){
93
93
}
94
94
return constructors ;
95
95
}
96
-
96
+
97
97
public ArrayList <Method > getMethods (){
98
98
ArrayList <Method > methods = new ArrayList <>();
99
99
for (Member member : members ){
@@ -109,23 +109,23 @@ public ArrayList<Method> getMethods(){
109
109
}
110
110
return methods ;
111
111
}
112
-
112
+
113
113
public ArrayList <Property > getProperties (){
114
114
ArrayList <Property > properties = new ArrayList <>();
115
115
for (Member member : members ){
116
116
if (member instanceof Property ) properties .add ((Property ) member );
117
117
}
118
118
return properties ;
119
119
}
120
-
120
+
121
121
public void setParent (Class parent ){
122
122
this .parent = parent ;
123
123
}
124
-
124
+
125
125
public Class getParent (){
126
126
return parent ;
127
127
}
128
-
128
+
129
129
public JSONObject toJson (){
130
130
JSONObject json = new JSONObject ();
131
131
json .set ("name" , name );
@@ -147,4 +147,29 @@ public JSONObject toJson(){
147
147
json .set ("classes" , classes );
148
148
return json ;
149
149
}
150
+
151
+ public String toString (){
152
+ if (namespace ==null || namespace .isBlank ()) return name ;
153
+ return namespace + "." + name ;
154
+ }
155
+
156
+ public int hashCode (){
157
+ return toString ().hashCode ();
158
+ }
159
+
160
+ public boolean equals (Object obj ){
161
+ if (obj !=null ){
162
+ if (obj instanceof Class ){
163
+ return toString ().equals (obj .toString ());
164
+ }
165
+ }
166
+ return false ;
167
+ }
168
+
169
+ public int compareTo (Object obj ){
170
+ if (obj instanceof Class ){
171
+ return toString ().compareTo (obj .toString ());
172
+ }
173
+ return -1 ;
174
+ }
150
175
}
0 commit comments