aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build/cardbasecli.xml5
-rw-r--r--src/eu/equalparts/cardbase/Cardbase.java28
2 files changed, 24 insertions, 9 deletions
diff --git a/build/cardbasecli.xml b/build/cardbasecli.xml
index 6490ae6..90b8b47 100644
--- a/build/cardbasecli.xml
+++ b/build/cardbasecli.xml
@@ -8,7 +8,7 @@
<property name="dist.dir" location="dist" />
<property name="lib.dir" value="lib" />
<property name="res.dir" value="res" />
- <property name="main-class" value="eu.equalparts.cardbase.standalone.CardbaseCLI" />
+ <property name="main-class" value="eu.equalparts.cardbase.cli.CardbaseCLI" />
<!-- Clean up temporary directories -->
<target name="clean" description="clean up">
@@ -71,7 +71,4 @@
<!-- Produce a standalone, runnable jar -->
<target name="deploy" depends="clean, compile, jar" />
- <!-- Deploy, add header and set permission to run on Linux -->
- <target name="cli" depends="deploy, shebang" />
-
</project> \ No newline at end of file
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;
}
}