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