Skip to content

Commit f9e5201

Browse files
committed
Implemented Comparable interface in the Class class
1 parent 468d5dd commit f9e5201

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

src/javaxt/utils/src/Class.java

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javaxt.json.*;
44

55

6-
public class Class implements Member {
6+
public class Class implements Member, Comparable {
77
private String name;
88
private String description;
99
private Class parent;
@@ -13,74 +13,74 @@ public class Class implements Member {
1313
private ArrayList<String> extensions;
1414
private ArrayList<String> interfaces;
1515

16-
16+
1717
public Class(String name){
1818
this.name = name;
1919
this.members = new ArrayList<>();
2020
this.extensions = new ArrayList<>();
2121
this.interfaces = new ArrayList<>();
2222
}
23-
23+
2424
public String getName(){
2525
return name;
2626
}
27-
27+
2828
public void setDescription(String description){
2929
this.description = description;
3030
}
31-
31+
3232
public String getDescription(){
3333
return description;
3434
}
35-
35+
3636
public boolean isPublic(){
3737
return isPublic;
3838
}
39-
39+
4040
public void setPublic(boolean isPublic){
4141
this.isPublic = isPublic;
4242
}
43-
43+
4444
public void setNamespace(String namespace){
4545
this.namespace = namespace;
4646
}
47-
47+
4848
public String getNamespace(){
4949
return namespace;
5050
}
51-
51+
5252
public void addSuper(String className){
5353
extensions.add(className);
5454
}
55-
55+
5656
public ArrayList<String> getSuper(){
5757
return extensions;
5858
}
59-
59+
6060
public void addInterface(String className){
6161
interfaces.add(className);
6262
}
63-
63+
6464
public ArrayList<String> getInterfaces(){
6565
return interfaces;
6666
}
67-
67+
6868
public void addMember(Member member){
6969
members.add(member);
7070
}
71-
71+
7272
public ArrayList<Member> getMembers(){
7373
return members;
7474
}
75-
75+
7676
public ArrayList<Class> getClasses(){
7777
ArrayList<Class> classes = new ArrayList<>();
7878
for (Member member : members){
7979
if (member instanceof Class) classes.add((Class) member);
8080
}
8181
return classes;
8282
}
83-
83+
8484
public ArrayList<Constructor> getConstructors(){
8585
ArrayList<Constructor> constructors = new ArrayList<>();
8686
for (Member member : members){
@@ -93,7 +93,7 @@ public ArrayList<Constructor> getConstructors(){
9393
}
9494
return constructors;
9595
}
96-
96+
9797
public ArrayList<Method> getMethods(){
9898
ArrayList<Method> methods = new ArrayList<>();
9999
for (Member member : members){
@@ -109,23 +109,23 @@ public ArrayList<Method> getMethods(){
109109
}
110110
return methods;
111111
}
112-
112+
113113
public ArrayList<Property> getProperties(){
114114
ArrayList<Property> properties = new ArrayList<>();
115115
for (Member member : members){
116116
if (member instanceof Property) properties.add((Property) member);
117117
}
118118
return properties;
119119
}
120-
120+
121121
public void setParent(Class parent){
122122
this.parent = parent;
123123
}
124-
124+
125125
public Class getParent(){
126126
return parent;
127127
}
128-
128+
129129
public JSONObject toJson(){
130130
JSONObject json = new JSONObject();
131131
json.set("name", name);
@@ -147,4 +147,29 @@ public JSONObject toJson(){
147147
json.set("classes", classes);
148148
return json;
149149
}
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+
}
150175
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy