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

Last change on this file since 1444 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 2.5 KB
Line 
1/**
2 * Pointers.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.simple;
20
21public class Pointers extends Variables<SPointer<?>> {
22
23 private static final String[] prefixes = new String[] {
24 SPointer.itemPrefix, SPointer.framePrefix, SPointer.filePrefix,
25 SPointer.associationPrefix };
26
27 public static boolean isPointer(String varName) {
28 for (String s : prefixes) {
29 if (varName.startsWith(s))
30 return true;
31 }
32 return false;
33 }
34
35 public Pointers() {
36 super();
37
38 }
39
40 protected String getType() {
41 return "pointer";
42 }
43
44 // TODO how do I put these two together without the warning
45 public void add(String name, SPointer<?> value) {
46 addT(name, value);
47 }
48
49 public <T> void addT(String name, SPointer<T> value) {
50 list_.add(new SPointer<T>(name, value.getValue()));
51 }
52
53 /**
54 * Assigns a new value to a pointer variable in the list. If the variable
55 * does not already exist the variable is created.
56 *
57 * @param <T>
58 * @param name
59 * the name of the variable which will have its value changed.
60 * @param value
61 * the new value of the variable.
62 * @throws Exception
63 * if an error occurs in changing the variables value.
64 */
65 public <T> void setObject(String name, T value) throws Exception {
66 SPointer v = null;
67 try {
68 // if it is an existing variable change the value
69 v = getVariable(name);
70 } catch (VariableNotFoundException e) {
71 // If the first variable doesnt exist then add it
72 list_.add(new SPointer<T>(name, value));
73 return;
74 }
75 // This will throw an exception if types dont match
76 v.setValue(value);
77 }
78
79 /**
80 * Deletes a variable if it exists.
81 * @param variableName name of the variable to delete
82 */
83 public void delete(String variableName) {
84 try {
85 list_.remove(getVariable(variableName));
86 } catch (VariableNotFoundException e) {
87
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.