summaryrefslogtreecommitdiff
path: root/dice-lang/src/main/java/bjc/dicelang/old/ast/nodes/VariableDiceNode.java
blob: 262f99b7fe897b2955e0e3ce053629e9933166c4 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package bjc.dicelang.old.ast.nodes;

/**
 * A node that represents a variable reference
 * 
 * @author ben
 *
 */
public class VariableDiceNode implements IDiceASTNode {
	/**
	 * The variable referenced by this node
	 */
	private String variableName;

	/**
	 * Create a new node representing the specified variable
	 * 
	 * @param varName
	 *            The name of the variable being referenced
	 */
	public VariableDiceNode(String varName) {
		this.variableName = varName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		// Handle special cases
		if (this == obj) {
			return true;
		} else if (obj == null) {
			return false;
		} else if (getClass() != obj.getClass()) {
			return false;
		} else {
			VariableDiceNode other = (VariableDiceNode) obj;

			if (variableName == null) {
				if (other.variableName != null) {
					return false;
				}
			} else if (!variableName.equals(other.variableName)) {
				return false;
			}

			return true;
		}
	}

	@Override
	public DiceASTType getType() {
		return DiceASTType.VARIABLE;
	}

	/**
	 * Get the variable referenced by this AST node
	 * 
	 * @return the variable referenced by this AST node
	 */
	public String getVariable() {
		return variableName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((variableName == null) ? 0 : variableName.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see bjc.utils.dice.ast.IDiceASTNode#isOperator()
	 */
	@Override
	public boolean isOperator() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return variableName;
	}
}