summaryrefslogtreecommitdiff
path: root/dice/src/main/java
diff options
context:
space:
mode:
authorstudent <student@69.161.224.78>2018-02-12 16:39:15 -0500
committerstudent <student@69.161.224.78>2018-02-12 16:39:15 -0500
commitd74549cc7d871d32864d3a6dee944325a2ccc7bf (patch)
tree1b990e0b90d5166c726cd2a63db63c063a7839e5 /dice/src/main/java
parent654a69ca0a0c1ab86aea2f6be63fe60eac61105a (diff)
Add hashCode()/equals()
Diffstat (limited to 'dice/src/main/java')
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/CompoundDie.java31
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/CompoundingDie.java31
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/DiceBox.java23
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/ExplodingDice.java34
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/FudgeDie.java25
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/MathDie.java34
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/ScalarDie.java22
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/SimpleDie.java31
-rw-r--r--dice/src/main/java/bjc/dicelang/dice/SimpleDieList.java38
9 files changed, 257 insertions, 12 deletions
diff --git a/dice/src/main/java/bjc/dicelang/dice/CompoundDie.java b/dice/src/main/java/bjc/dicelang/dice/CompoundDie.java
index a06e3c4..b66022c 100644
--- a/dice/src/main/java/bjc/dicelang/dice/CompoundDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/CompoundDie.java
@@ -57,4 +57,35 @@ public class CompoundDie implements Die {
return String.format("%sc%s", leftString, rightString);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((left == null) ? 0 : left.hashCode());
+ result = prime * result + ((right == null) ? 0 : right.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompoundDie other = (CompoundDie) obj;
+ if (left == null) {
+ if (other.left != null)
+ return false;
+ } else if (!left.equals(other.left))
+ return false;
+ if (right == null) {
+ if (other.right != null)
+ return false;
+ } else if (!right.equals(other.right))
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/CompoundingDie.java b/dice/src/main/java/bjc/dicelang/dice/CompoundingDie.java
index 5ddbfda..f4ab510 100644
--- a/dice/src/main/java/bjc/dicelang/dice/CompoundingDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/CompoundingDie.java
@@ -111,4 +111,35 @@ public class CompoundingDie implements Die {
return String.format("%s!!%s", sourceString, compoundPattern);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((compoundPattern == null) ? 0 : compoundPattern.hashCode());
+ result = prime * result + ((source == null) ? 0 : source.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CompoundingDie other = (CompoundingDie) obj;
+ if (compoundPattern == null) {
+ if (other.compoundPattern != null)
+ return false;
+ } else if (!compoundPattern.equals(other.compoundPattern))
+ return false;
+ if (source == null) {
+ if (other.source != null)
+ return false;
+ } else if (!source.equals(other.source))
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/DiceBox.java b/dice/src/main/java/bjc/dicelang/dice/DiceBox.java
index 7841079..b8e1b3d 100644
--- a/dice/src/main/java/bjc/dicelang/dice/DiceBox.java
+++ b/dice/src/main/java/bjc/dicelang/dice/DiceBox.java
@@ -25,8 +25,11 @@ public class DiceBox {
return doParseExpression(expString);
} catch (Exception ex) {
/*
- * @TODO 10/08/17 Ben Culkin :DieErrors :ErrorRefactor Use different types of
- * exceptions to provide better error messages.
+ * @TODO 10/08/17 Ben Culkin :DieErrors
+ *
+ * :ErrorRefactor
+ *
+ * Use different types of exceptions to provide better error messages.
*/
String exMessage = ex.getMessage();
@@ -46,10 +49,11 @@ public class DiceBox {
if (scalarDiePattern.matcher(expString).matches()) {
/* Parse scalar die. */
/*
- * @TODO 10/08/17 Ben Culkin :SubstringIndexOf This substring/index of call
- * should be abstracted into its own method so as to make the code more
- * explanatory and ensure that things like the return code of indexOf are
- * correctly checked.
+ * @TODO 10/08/17 Ben Culkin :SubstringIndexOf
+ *
+ * This substring/index of call should be abstracted into its own method so as
+ * to make the code more explanatory and ensure that things like the return code
+ * of indexOf are correctly checked.
*/
final String dieString = expString.substring(0, expString.indexOf('s'));
@@ -171,9 +175,10 @@ public class DiceBox {
/* The strings and patterns used for matching. */
/*
- * @TODO 10/08/17 Ben Culkin :RegexResource These regexes and patterns should be
- * moved to something external, probably using the SimpleProperties-based system
- * that BJC-Utils2 uses.
+ * @TODO 10/08/17 Ben Culkin :RegexResource
+ *
+ * These regexes and patterns should be moved to something external, probably
+ * using the SimpleProperties-based system that BJC-Utils2 uses.
*/
/* Defines a comparison predicate. */
private static final String comparePoint = "[<>=]\\d+";
diff --git a/dice/src/main/java/bjc/dicelang/dice/ExplodingDice.java b/dice/src/main/java/bjc/dicelang/dice/ExplodingDice.java
index 4b92c88..2dad73a 100644
--- a/dice/src/main/java/bjc/dicelang/dice/ExplodingDice.java
+++ b/dice/src/main/java/bjc/dicelang/dice/ExplodingDice.java
@@ -117,4 +117,38 @@ public class ExplodingDice implements DieList {
return String.format("%s%s!%s", sourceString, penString, explodePattern);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((explodePattern == null) ? 0 : explodePattern.hashCode());
+ result = prime * result + (explodePenetrates ? 1231 : 1237);
+ result = prime * result + ((source == null) ? 0 : source.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExplodingDice other = (ExplodingDice) obj;
+ if (explodePattern == null) {
+ if (other.explodePattern != null)
+ return false;
+ } else if (!explodePattern.equals(other.explodePattern))
+ return false;
+ if (explodePenetrates != other.explodePenetrates)
+ return false;
+ if (source == null) {
+ if (other.source != null)
+ return false;
+ } else if (!source.equals(other.source))
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/FudgeDie.java b/dice/src/main/java/bjc/dicelang/dice/FudgeDie.java
index 4b1f281..9ebbee1 100644
--- a/dice/src/main/java/bjc/dicelang/dice/FudgeDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/FudgeDie.java
@@ -64,4 +64,29 @@ public class FudgeDie implements Die {
return String.format("%sdF", dieString);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((numDice == null) ? 0 : numDice.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ FudgeDie other = (FudgeDie) obj;
+ if (numDice == null) {
+ if (other.numDice != null)
+ return false;
+ } else if (!numDice.equals(other.numDice))
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/MathDie.java b/dice/src/main/java/bjc/dicelang/dice/MathDie.java
index 87fdfe7..348c2d3 100644
--- a/dice/src/main/java/bjc/dicelang/dice/MathDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/MathDie.java
@@ -117,4 +117,38 @@ public class MathDie implements Die {
public String toString() {
return left.toString() + " " + type.toString() + " " + right.toString();
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((left == null) ? 0 : left.hashCode());
+ result = prime * result + ((right == null) ? 0 : right.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MathDie other = (MathDie) obj;
+ if (left == null) {
+ if (other.left != null)
+ return false;
+ } else if (!left.equals(other.left))
+ return false;
+ if (right == null) {
+ if (other.right != null)
+ return false;
+ } else if (!right.equals(other.right))
+ return false;
+ if (type != other.type)
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/ScalarDie.java b/dice/src/main/java/bjc/dicelang/dice/ScalarDie.java
index 9aae256..af6fd60 100644
--- a/dice/src/main/java/bjc/dicelang/dice/ScalarDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/ScalarDie.java
@@ -44,4 +44,26 @@ public class ScalarDie implements Die {
public String toString() {
return String.format("%d", val);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (val ^ (val >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ScalarDie other = (ScalarDie) obj;
+ if (val != other.val)
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/SimpleDie.java b/dice/src/main/java/bjc/dicelang/dice/SimpleDie.java
index f598ae5..de31a6d 100644
--- a/dice/src/main/java/bjc/dicelang/dice/SimpleDie.java
+++ b/dice/src/main/java/bjc/dicelang/dice/SimpleDie.java
@@ -115,4 +115,35 @@ public class SimpleDie implements Die {
public String toString() {
return numDice + "d" + diceSize;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((diceSize == null) ? 0 : diceSize.hashCode());
+ result = prime * result + ((numDice == null) ? 0 : numDice.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SimpleDie other = (SimpleDie) obj;
+ if (diceSize == null) {
+ if (other.diceSize != null)
+ return false;
+ } else if (!diceSize.equals(other.diceSize))
+ return false;
+ if (numDice == null) {
+ if (other.numDice != null)
+ return false;
+ } else if (!numDice.equals(other.numDice))
+ return false;
+ return true;
+ }
}
diff --git a/dice/src/main/java/bjc/dicelang/dice/SimpleDieList.java b/dice/src/main/java/bjc/dicelang/dice/SimpleDieList.java
index 3516a4f..4e8c51a 100644
--- a/dice/src/main/java/bjc/dicelang/dice/SimpleDieList.java
+++ b/dice/src/main/java/bjc/dicelang/dice/SimpleDieList.java
@@ -5,9 +5,10 @@ package bjc.dicelang.dice;
*
* @author EVE
*
- * @TODO 10/08/17 Ben Culkin :DieListGeneralize DieList in general should be
- * changed to be able to be constructed from an arbitrary die using
- * rollSingle and things like that.
+ * @TODO 10/08/17 Ben Culkin :DieListGeneralize
+ *
+ * DieList in general should be changed to be able to be constructed from
+ * an arbitrary die using rollSingle and things like that.
*/
public class SimpleDieList implements DieList {
/* The number of dice to roll. */
@@ -73,4 +74,35 @@ public class SimpleDieList implements DieList {
public String toString() {
return numDice.toString() + "dl" + size.toString();
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((numDice == null) ? 0 : numDice.hashCode());
+ result = prime * result + ((size == null) ? 0 : size.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SimpleDieList other = (SimpleDieList) obj;
+ if (numDice == null) {
+ if (other.numDice != null)
+ return false;
+ } else if (!numDice.equals(other.numDice))
+ return false;
+ if (size == null) {
+ if (other.size != null)
+ return false;
+ } else if (!size.equals(other.size))
+ return false;
+ return true;
+ }
}