View Javadoc
1   package net.sourceforge.rpgee.dice;
2   
3   import net.sourceforge.rpgee.dice.exceptions.InvalidParameterException;
4   
5   public abstract class AbstractRandomValue implements RandomValue {
6       private int sides = 0;
7       private int value = 0;
8       private RandomValueResultMapper mapper;
9       private RandomValue original;
10      
11      public AbstractRandomValue(Integer _sides, RandomValueResultMapper _mapper) {
12          this(_sides, _mapper, null);
13      }
14      
15      public AbstractRandomValue(Integer _sides, RandomValueResultMapper _mapper, RandomValue _original) {
16          mapper = _mapper; 
17          sides = _sides;
18          if (_original == null)
19              _original = this;
20          original = _original;
21      }
22      
23  
24      public int getValue() {
25          return value;
26      }
27  
28      public String getValueAsString() {
29          if (mapper == null)
30              return value + "";
31          try {
32              return mapper.getMappedValue(value);
33          } catch (InvalidParameterException e) {
34              return "[ERROR]";
35          }
36      }
37  
38      public int getSides() {
39          return sides;
40      }
41  
42      public void setValue(int _value) throws InvalidParameterException {
43          this.value = _value;
44      }
45      
46      public String getHTMLDescription() {
47          return CODE_HEADER + getDescription() + CODE_FOOTER;
48      }
49  
50      public RandomValueResultMapper getMapper() {
51          return this.mapper;
52      }
53      
54      public RandomValue getOriginalValue() {
55          return original;
56      }
57  
58      public boolean isOriginalValue() {
59          return getOriginalValue() == this;
60      }
61  
62  }