1 package cz.cuni.amis.pogamut.sposh.executor;
2
3 import cz.cuni.amis.pogamut.sposh.executor.IAction;
4 import cz.cuni.amis.pogamut.sposh.executor.ISense;
5 import cz.cuni.amis.pogamut.sposh.executor.ParamInfo;
6 import cz.cuni.amis.pogamut.sposh.executor.PrimitiveInfo;
7 import java.util.Collections;
8 import java.util.HashSet;
9 import java.util.Set;
10
11
12
13
14
15
16
17
18 public final class PrimitiveData implements Comparable<PrimitiveData> {
19
20
21
22
23 public final String classFQN;
24
25
26
27
28 public final String name;
29
30
31
32
33 public final String description;
34
35
36
37 public final String[] tags;
38
39
40
41 public final Set<ParamInfo> params;
42
43
44
45
46
47
48
49 public PrimitiveData(String classFQN) {
50 this(classFQN, null, null, new String[0], Collections.<ParamInfo>emptySet());
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public PrimitiveData(String classFQN, String name, String description, String[] tags, Set<ParamInfo> parameters) {
64 this.classFQN = classFQN;
65 this.name = name;
66 this.description = description;
67 this.tags = tags;
68 this.params = Collections.unmodifiableSet(new HashSet<ParamInfo>(parameters));
69 }
70
71
72
73
74
75
76 public String getClassName() {
77 return classFQN.replaceFirst("^.*\\.", "");
78 }
79
80
81
82
83
84
85
86
87 @Override
88 public int compareTo(PrimitiveData o) {
89 if (this == o) {
90 return 0;
91 }
92
93 String myName = name != null ? name : getClassName();
94 String oName = o.name != null ? o.name : o.getClassName();
95
96 int nameComparison = myName.toLowerCase().compareTo(oName.toLowerCase());
97 if (nameComparison != 0) {
98 return nameComparison;
99 }
100
101 return classFQN.compareTo(o.classFQN);
102 }
103
104 @Override
105 public String toString() {
106 return (name != null ? name : getClassName()) + "(" + classFQN + ")";
107 }
108
109
110
111
112
113 public String getHtmlDescription() {
114 StringBuilder info = new StringBuilder();
115 info.append("<html><b>Class:</b> ");
116 info.append(classFQN);
117 if (name != null) {
118 info.append("<br/><b>Name:</b> ");
119 info.append(name);
120 }
121 if (description != null) {
122 info.append("<br/><b>Description:</b> ");
123 info.append(description);
124 }
125 if (tags.length > 0) {
126 info.append("<br/><b>Tags:</b> ");
127 for (int tagIndex = 0; tagIndex < tags.length; ++tagIndex) {
128 info.append(tags[tagIndex]);
129 if (tagIndex != tags.length - 1) {
130 info.append(',');
131 info.append(' ');
132 }
133 }
134 }
135 info.append("</html>");
136 return info.toString();
137 }
138 }