From 72fef1f9bcac0c980bfae6dde53358d9cba12901 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Mon, 13 Jul 2015 11:04:56 +0200 Subject: Cleaned up a bit, finished sort tests, refactored cardbase adding and removing, need to write tests urgently --- src/eu/equalparts/cardbase/Cardbase.java | 18 ++++----- src/eu/equalparts/cardbase/cards/Card.java | 2 - src/eu/equalparts/cardbase/cli/CardbaseCLI.java | 45 +++++++++------------- .../cardbase/comparator/CardComparator.java | 4 -- 4 files changed, 27 insertions(+), 42 deletions(-) (limited to 'src/eu/equalparts') diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java index 04a2760..f95e19b 100644 --- a/src/eu/equalparts/cardbase/Cardbase.java +++ b/src/eu/equalparts/cardbase/Cardbase.java @@ -83,15 +83,15 @@ public class Cardbase { * If the card is not already in the cardbase, it is added. * If it is already present, the count is simply updated. * - * @param cardToAdd the card to be added. - * @param count the amount of the card to be added. + * @param cardToAdd the card to be added. The count value + * of this object is added to the existing count if the card + * already exists. */ - public void addCard(Card cardToAdd, Integer count) { + public void addCard(Card cardToAdd) { Card card = getCard(cardToAdd.setCode, cardToAdd.number); if (card != null) { - card.count += count; + card.count += cardToAdd.count; } else { - cardToAdd.count = count; cards.put(UID.makeHash(cardToAdd), cardToAdd); } } @@ -112,16 +112,16 @@ public class Cardbase { * @param count the amount of the card to be removed. * @return the number of cards actually removed. */ - public Integer removeCard(Card cardToRemove, Integer count) { + public Integer removeCard(Card cardToRemove) { Card card = getCard(cardToRemove.setCode, cardToRemove.number); Integer removed = 0; if (card != null) { - if (card.count <= count) { + if (card.count <= cardToRemove.count) { cards.remove(UID.makeHash(card)); removed = card.count; } else { - card.count -= count; - removed = count; + card.count -= cardToRemove.count; + removed = cardToRemove.count; } } return removed; diff --git a/src/eu/equalparts/cardbase/cards/Card.java b/src/eu/equalparts/cardbase/cards/Card.java index 6afdff8..419861b 100644 --- a/src/eu/equalparts/cardbase/cards/Card.java +++ b/src/eu/equalparts/cardbase/cards/Card.java @@ -24,7 +24,6 @@ public class Card { public Integer loyalty; public Integer multiverseid; public String imageName; - public String border; public String watermark; // Not part of upstream JSON @@ -51,7 +50,6 @@ public class Card { clone.loyalty = this.loyalty; clone.multiverseid = this.multiverseid; clone.imageName = this.imageName; - clone.border = this.border; clone.watermark = this.watermark; clone.setCode = this.setCode; clone.imageCode = this.imageCode; diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java index 4d72d5b..bbc0089 100644 --- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java +++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java @@ -33,17 +33,6 @@ public class CardbaseCLI { private enum Action { ADD, REMOVE; public Card card; - public Integer count; - /** - * Sets both fields at once. - * - * @param card the card last modified. - * @param count the amount that was added or removed. - */ - public void set(Card card, Integer count) { - this.card = card; - this.count = count; - } } /** @@ -347,9 +336,9 @@ public class CardbaseCLI { public void undo() { if (lastAction != null) { if (lastAction == Action.ADD) { - removeCard(lastAction.card, lastAction.count); + removeCard(lastAction.card); } else if (lastAction == Action.REMOVE) { - addCard(lastAction.card, lastAction.count); + addCard(lastAction.card); } // can only undo once lastAction = null; @@ -376,7 +365,8 @@ public class CardbaseCLI { return; } } - removeCard(cardToRemove, count); + cardToRemove.count = count; + removeCard(cardToRemove); } else { System.out.println(args[0] + " does not correspond to a card in " + selectedSet.name + "."); } @@ -399,7 +389,7 @@ public class CardbaseCLI { // a blank line after adding a card repeats the addition unlimitedly if (number.isEmpty()) { if (lastAction == Action.ADD) - addCard(lastAction.card, lastAction.count); + addCard(lastAction.card); } else { Card cardToAdd = selectedSet.getCardByNumber(number); if (cardToAdd != null) { @@ -411,7 +401,8 @@ public class CardbaseCLI { return; } } - addCard(cardToAdd, count); + cardToAdd.count = count; + addCard(cardToAdd); } else { System.out.println(number + " does not correspond to a card in " + selectedSet.name + "."); } @@ -425,31 +416,31 @@ public class CardbaseCLI { * Add the specified count of the specified card * to the cardbase. * - * @param card the card to add. - * @param count the number of times to add it. + * @param card the card to add, set this object's + * count field to determine the count to add. */ - private void addCard(Card card, Integer count) { - cardbase.addCard(card, count); - System.out.println("Added " + count + "x " + card.name + "."); + private void addCard(Card card) { + cardbase.addCard(card); + System.out.println("Added " + card.count + "x " + card.name + "."); savePrompt = true; lastAction = Action.ADD; - lastAction.set(card, count); + lastAction.card = card; } /** * Remove the specified count of the specified card * from the cardbase. * - * @param card the card to remove. - * @param count the number of times to remove it. + * @param card the card to remove, set this object's count field + * to determine how many of the card to remove. */ - private void removeCard(Card card, Integer count) { - Integer removed = cardbase.removeCard(card, count); + private void removeCard(Card card) { + Integer removed = cardbase.removeCard(card); if (removed > 0) { System.out.println("Removed " + removed + "x " + card.name + "."); savePrompt = true; lastAction = Action.REMOVE; - lastAction.set(card, removed); + lastAction.card = card; } else { System.out.println(card.name + " is not in the cardbase."); } diff --git a/src/eu/equalparts/cardbase/comparator/CardComparator.java b/src/eu/equalparts/cardbase/comparator/CardComparator.java index 9cb72b4..9f90e00 100644 --- a/src/eu/equalparts/cardbase/comparator/CardComparator.java +++ b/src/eu/equalparts/cardbase/comparator/CardComparator.java @@ -29,10 +29,6 @@ import eu.equalparts.cardbase.comparator.SpecialFields.Rarity; */ @SuppressWarnings({"rawtypes", "unchecked"}) public class CardComparator implements Comparator { - - public enum Order { - NATURAL, REVERSE; - } /** * The field being compared. -- cgit v1.2.3