source: trunk/src/org/expeditee/simple/Pointers.java@ 80

Last change on this file since 80 was 80, checked in by ra33, 16 years ago

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

File size: 1.8 KB
Line 
1package org.expeditee.simple;
2
3public class Pointers extends Variables<SPointer<?>> {
4
5 private static final String[] prefixes = new String[] {
6 SPointer.itemPrefix, SPointer.framePrefix, SPointer.filePrefix,
7 SPointer.associationPrefix };
8
9 public static boolean isPointer(String varName) {
10 for (String s : prefixes) {
11 if (varName.startsWith(s))
12 return true;
13 }
14 return false;
15 }
16
17 public Pointers() {
18 super();
19
20 }
21
22 protected String getType() {
23 return "pointer";
24 }
25
26 // TODO how do I put these two together without the warning
27 public void add(String name, SPointer<?> value) {
28 addT(name, value);
29 }
30
31 public <T> void addT(String name, SPointer<T> value) {
32 list_.add(new SPointer<T>(name, value.getValue()));
33 }
34
35 /**
36 * Assigns a new value to a pointer variable in the list. If the variable
37 * does not already exist the variable is created.
38 *
39 * @param <T>
40 * @param name
41 * the name of the variable which will have its value changed.
42 * @param value
43 * the new value of the variable.
44 * @throws Exception
45 * if an error occurs in changing the variables value.
46 */
47 public <T> void setObject(String name, T value) throws Exception {
48 SPointer v = null;
49 try {
50 // if it is an existing variable change the value
51 v = getVariable(name);
52 } catch (VariableNotFoundException e) {
53 // If the first variable doesnt exist then add it
54 list_.add(new SPointer<T>(name, value));
55 return;
56 }
57 // This will throw an exception if types dont match
58 v.setValue(value);
59 }
60
61 /**
62 * Deletes a variable if it exists.
63 * @param variableName name of the variable to delete
64 */
65 public void delete(String variableName) {
66 try {
67 list_.remove(getVariable(variableName));
68 } catch (VariableNotFoundException e) {
69
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.