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 package org.utgenome.gwt.utgb.client.track.lib.old;
26
27 import java.util.HashSet;
28 import java.util.Map;
29 import java.util.Set;
30
31 import org.utgenome.gwt.utgb.client.track.TrackConfig;
32 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.ColorType;
33 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.DispType;
34 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.GradationType;
35 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.LowerBoundType;
36 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.SelectType;
37 import org.utgenome.gwt.utgb.client.track.lib.old.datatype.UpperBoundType;
38
39
40
41
42
43 public abstract class OldUTGBOptionAttribute {
44
45 public abstract void setConfig(final TrackConfig trackConfig);
46
47 public abstract void setParameters(final Map<String, String> parameterMap);
48
49 private static class SelectOptionAttribute extends OldUTGBOptionAttribute {
50 private DispType dispType = null;
51 private ColorType colorType = null;
52 private SelectType selectType = null;
53
54 SelectOptionAttribute(final String parameterName, final String[] values, final String[] operations, final String prefix) {
55 for (int i = 0; i < operations.length; i++) {
56 if (operations[i].equalsIgnoreCase("disp")) {
57 dispType = new DispType(parameterName, values);
58 }
59 if (operations[i].equalsIgnoreCase("color")) {
60 colorType = new ColorType(parameterName, values, prefix);
61 }
62 if (operations[i].equalsIgnoreCase("select")) {
63 selectType = new SelectType(parameterName, values);
64 }
65 }
66 }
67
68 public void setConfig(TrackConfig trackConfig) {
69 if (dispType != null)
70 trackConfig.addConfig(dispType, "");
71 if (colorType != null)
72 trackConfig.addConfig(colorType, "");
73 if (selectType != null)
74 trackConfig.addConfig(selectType, "");
75 }
76
77 public void setParameters(Map<String, String> parameterMap) {
78 if (dispType != null)
79 dispType.setParameters(parameterMap);
80 if (colorType != null)
81 colorType.setParameters(parameterMap);
82 if (selectType != null)
83 selectType.setParameters(parameterMap);
84 }
85
86 }
87
88 private static class RealOptionAttribute extends OldUTGBOptionAttribute {
89 private GradationType gradationType = null;
90 private UpperBoundType uboundType = null;
91 private LowerBoundType lboundType = null;
92
93 RealOptionAttribute(final String parameterName, final double min, final double max, final String[] operations, final String prefix) {
94 for (int i = 0; i < operations.length; i++) {
95 if (operations[i].equalsIgnoreCase("gradation")) {
96 gradationType = new GradationType(parameterName, min, max, prefix);
97 }
98 if (operations[i].equalsIgnoreCase("ubound")) {
99 uboundType = new UpperBoundType(parameterName, min, max);
100 }
101 if (operations[i].equalsIgnoreCase("lbound")) {
102 lboundType = new LowerBoundType(parameterName, min, max);
103 }
104 }
105 }
106
107 public void setConfig(TrackConfig trackConfig) {
108 if (gradationType != null)
109 trackConfig.addConfig(gradationType, "");
110 if (uboundType != null)
111 trackConfig.addConfig(uboundType, "");
112 if (lboundType != null)
113 trackConfig.addConfig(lboundType, "");
114 }
115
116 public void setParameters(Map<String, String> parameterMap) {
117 if (gradationType != null)
118 gradationType.setParameters(parameterMap);
119 if (uboundType != null)
120 uboundType.setParameters(parameterMap);
121 if (lboundType != null)
122 lboundType.setParameters(parameterMap);
123 }
124
125 }
126
127 public static OldUTGBOptionAttribute getSelectInstance(final String parameterName, final String[] values, final String[] operations, final String prefix) {
128 final String[] uniqueValues = getUniques(values);
129 final String[] uniqueOperations = getUniques(operations);
130
131 final SelectOptionAttribute selectOptionAttribute = new SelectOptionAttribute(parameterName, uniqueValues, uniqueOperations, prefix);
132
133 return selectOptionAttribute;
134 }
135
136 public static OldUTGBOptionAttribute getRealInstance(final String parameterName, final String minValue, final String maxValue, final String[] operations,
137 final String prefix) {
138 try {
139 final String[] uniqueOperations = getUniques(operations);
140
141 final double min = Double.parseDouble(minValue);
142 final double max = Double.parseDouble(maxValue);
143
144 final RealOptionAttribute realOptionAttribute = new RealOptionAttribute(parameterName, min, max, uniqueOperations, prefix);
145
146 return realOptionAttribute;
147 }
148 catch (NumberFormatException ne) {
149 return null;
150 }
151 }
152
153 private static final String[] getUniques(final String[] inputArray) {
154 final Set<String> set = new HashSet<String>();
155
156 for (int i = 0; i < inputArray.length; i++) {
157 final String value = inputArray[i];
158
159 if (!set.contains(value))
160 set.add(value);
161 }
162
163 final String[] outputArray = new String[set.size()];
164
165 int j = 0;
166 for (int i = 0; i < inputArray.length; i++) {
167 final String value = inputArray[i];
168
169 if (set.contains(value))
170 outputArray[j++] = value;
171 }
172
173 return outputArray;
174 }
175 }