summaryrefslogtreecommitdiff
path: root/dice/src/example/java/bjc/dicelang/neodice/statements/DieStatementValue.java
blob: 5662a59764e284cde44b5719d46e149613d4ce01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package bjc.dicelang.neodice.statements;

import static bjc.dicelang.neodice.statements.StatementValue.Type.*;

import java.util.*;

import bjc.dicelang.neodice.*;

/**
 * A StatementValue that represents a die.
 * @author Ben Culkin
 *
 */
public class DieStatementValue extends StatementValue {
    /** The type of values this die rolls. */
	public final Type sideType;
	/** The die itself. */
	public final Die<StatementValue> value;
	
	/**
	 * Create a new die StatementValue.
	 * 
	 * @param sideType The type of value this die rolls.
	 * @param value The die itself.
	 */
	public DieStatementValue(Type sideType, Die<StatementValue> value) {
		super(DIE);
		
		this.sideType = sideType;
		this.value = value;
	}
	
	@Override
	public String toString() {
		return "(" + value.toString() + ")";
	}

	@Override
	public int hashCode() {
		return Objects.hash(value);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)                  return true;
		if (obj == null)                  return false;
		if (getClass() != obj.getClass()) return false;

		DieStatementValue other = (DieStatementValue) obj;
		
		return Objects.equals(value, other.value);
	}
}