aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2015-06-20 12:13:34 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2015-06-20 12:13:34 +0200
commit59174889aba82c64ae63e0a5622d6cbcab63dc39 (patch)
treebd3575169e68d0582a3244b3009e30c4df348394 /src
parent46c25bd120e853834e61cb321a4f75e3e71aa21d (diff)
Refactored hash, fixed ant build script
Diffstat (limited to 'src')
-rw-r--r--src/eu/equalparts/cardbase/Cardbase.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java
index 9251d4c..211f865 100644
--- a/src/eu/equalparts/cardbase/Cardbase.java
+++ b/src/eu/equalparts/cardbase/Cardbase.java
@@ -34,6 +34,11 @@ public class Cardbase {
public static final boolean DEBUG = System.getenv("CB_DEBUG") != null;
/**
+ * Used in the hash generation.
+ */
+ private static final String HASH_DIVIDER = "~";
+
+ /**
* Creates an empty cardbase.
*/
public Cardbase() {
@@ -134,7 +139,7 @@ public class Cardbase {
*
* @param setCode the set to which the requested card belongs.
* @param number the requested card's set number.
- *
+ * key
* @return the requested {@code Card} or null if no card is found.
*/
public Card getCard(String setCode, String number) {
@@ -142,14 +147,27 @@ public class Cardbase {
}
/**
+ * Returns a card from the cardbase by hash. The card's hash
+ * can be generated using {@code Cardbase.makeHash()}.
+ * If no such card is in the cardbase, returns null.
+ *
+ * @param hash the Cardbase hash of the requested card.
+ *
+ * @return the requested {@code Card} or null if no card is found.
+ */
+ public Card getCardFromHash(String hash) {
+ return cards.get(hash);
+ }
+
+ /**
* Generate the hash used as a key in the storage map.
*
* @param setCode the card's set code.
* @param number the card's set number.
* @return the generated hash.
*/
- private String makeHash(String setCode, String number) {
- return setCode + number;
+ public static String makeHash(String setCode, String number) {
+ return setCode + HASH_DIVIDER + number;
}
/**
@@ -158,7 +176,7 @@ public class Cardbase {
* @param the {@code Card} whose hash is desired.
* @return the generated hash.
*/
- private String makeHash(Card card) {
- return card.setCode + card.number;
+ public static String makeHash(Card card) {
+ return card.setCode + HASH_DIVIDER + card.number;
}
}