1
2
3
4
5
6
7 package net.kwfgrid.gworkflowdl.structure;
8
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Arrays;
13
14 /***
15 * implementation of Place with ArrayList container for tokens.
16 */
17 public final class ArrayListPlace extends ArrayListOwls implements Place {
18 private String id;
19 private final List<Token> tokens;
20 private int capacity;
21 private String description;
22 private String tokenType;
23 private GenericProperties properties;
24
25 /***
26 * default construction of ArrayListPlace.
27 */
28 public ArrayListPlace() {
29 id = Place.DEFAULT_ID;
30 tokens = new ArrayList<Token>();
31 capacity = Place.DEFAULT_CAPACITY;
32 description = Place.DEFAULT_DESCRIPTION;
33 tokenType = Place.DEFAULT_TOKENCLASS_TYPE;
34 properties = Factory.newProperties();
35 }
36
37 public void setID(final String idString) {
38 id = idString;
39 }
40
41 public String getID() {
42 return id;
43 }
44
45 public void setTokenType(final String type) {
46 tokenType = type;
47 }
48
49 public String getTokenType() {
50 return tokenType;
51 }
52
53 public boolean isEmpty() {
54 return tokens.size() == 0;
55 }
56
57 public void addToken(Token t) throws CapacityException {
58 if (tokens.size() < capacity) {
59 tokens.add(t);
60 } else {
61 throw new CapacityException("Too many tokens on place " + getID());
62 }
63 }
64
65 public void setTokens(Token[] tokenarray) throws CapacityException {
66 tokens.clear();
67 if (tokenarray.length > capacity) throw new CapacityException("Too many tokens on place " + getID());
68 tokens.addAll(Arrays.asList(tokenarray));
69 }
70
71 public void removeToken(final int i) {
72 tokens.remove(i);
73 }
74
75 public Token[] getTokens() {
76 final Token[] ts = new Token[tokens.size()];
77 for (int i = 0; i < tokens.size(); i++) {
78 ts[i] = tokens.get(i);
79 }
80 return ts;
81 }
82
83 public void removeToken(final Token t) {
84 final int i = tokens.indexOf(t);
85 if (i != -1) {
86 tokens.remove(i);
87 }
88 }
89
90 public void removeAllTokens() {
91 tokens.clear();
92 }
93
94
95 public void setCapacity(final int capa) throws CapacityException {
96 if (capa >= tokens.size()) {
97 capacity = capa;
98 } else {
99 throw new CapacityException("Too many tokens on place " + getID());
100 }
101 }
102
103 public int getCapacity() {
104 return capacity;
105 }
106
107 public int getTokenNumber() {
108 return tokens.size();
109 }
110
111
112 public String getDescription() {
113 return description;
114 }
115
116 public void setDescription(final String d) {
117 description = d;
118 }
119
120 public GenericProperties getProperties() {
121 return properties;
122 }
123
124 public void setProperties(final GenericProperties props) {
125 properties = props;
126 }
127
128
129
130
131 }