source: trunk/src/org/expeditee/simple/Variables.java@ 309

Last change on this file since 309 was 282, checked in by ra33, 16 years ago
File size: 1.7 KB
Line 
1package org.expeditee.simple;
2
3import java.util.ArrayList;
4
5import org.expeditee.gui.MessageBay;
6
7public abstract class Variables<T extends SVariable<?>> {
8
9 protected ArrayList<T> list_;
10
11 public Variables() {
12 list_ = new ArrayList<T>();
13 }
14
15 public int size() {
16 return list_.size();
17 }
18
19 public void clear() {
20 list_.clear();
21 }
22
23 public void display() {
24 for (T v : list_) {
25 MessageBay.displayMessage(v.getName() + ": " + v.stringValue());
26 }
27 }
28
29 public T getVariable(String name) throws VariableNotFoundException {
30 for (T v : list_) {
31 if (v.getName().equalsIgnoreCase(name)) {
32 return v;
33 }
34 }
35 throw new VariableNotFoundException(name + " is not an existing "
36 + getType());
37 }
38
39 /**
40 * Sets the value of variable1 to value of variable2. If variable1 doesnt
41 * exist then it is created.
42 *
43 * @param variableToSet-
44 * the variable whos value will be modified.
45 * @param variableWithNewValue-
46 * the variable to get the new value from.
47 */
48 public void set(String variableToSet, String variableWithNewValue)
49 throws Exception {
50 // If the variables are the same then do nothing
51 if (variableToSet.equalsIgnoreCase(variableWithNewValue))
52 return;
53
54 T toGetValueFrom = getVariable(variableWithNewValue);
55 T toSet = null;
56 try {
57 toSet = getVariable(variableToSet);
58 } catch (Exception e) {
59 // if the variable to be set doesnt exist and exception is
60 // thrown So it will be added
61 add(variableToSet, toGetValueFrom);
62 return;
63 }
64 //TODO:figure out how to fix the ANT build error
65 ((SVariable)toSet).setValue(toGetValueFrom);
66 }
67
68 public abstract void add(String name, T value) throws Exception;
69
70 protected abstract String getType();
71}
Note: See TracBrowser for help on using the repository browser.