Tags field inside deck class

This commit is contained in:
Maxmtg
2013-02-26 11:12:29 +00:00
parent a935f63157
commit 441198c80f
2 changed files with 39 additions and 1 deletions

View File

@@ -65,6 +65,8 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
private final Map<DeckSection, CardPool> parts = new EnumMap<DeckSection, CardPool>(DeckSection.class);
private final List<String> tags = new ArrayList<String>();
// gameType is from Constant.GameType, like GameType.Regular
/**
* <p>
@@ -194,6 +196,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
final Deck d = new Deck(dh.getName());
d.setComment(dh.getComment());
d.tags.addAll(dh.getTags());
for(Entry<String, List<String>> s : sections.entrySet()) {
DeckSection sec = DeckSection.smartValueOf(s.getKey());
@@ -286,6 +289,10 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
if (this.getComment() != null) {
out.add(String.format("%s=%s", DeckFileHeader.COMMENT, this.getComment().replaceAll("\n", "")));
}
if (!this.getTags().isEmpty()) {
out.add(String.format("%s=%s", DeckFileHeader.TAGS, StringUtils.join(getTags(), DeckFileHeader.TAGS_SEPARATOR)));
}
for(Entry<DeckSection, CardPool> s : parts.entrySet()) {
out.add(String.format("[%s]", s.getKey().toString()));
@@ -322,4 +329,11 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
public Iterator<Entry<DeckSection, CardPool>> iterator() {
return parts.entrySet().iterator();
}
/**
* @return the associated tags, a writable list
*/
public List<String> getTags() {
return tags;
}
}

View File

@@ -17,6 +17,11 @@
*/
package forge.deck.io;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.StringUtils;
import forge.deck.DeckFormat;
import forge.game.player.PlayerType;
import forge.util.FileSection;
@@ -32,6 +37,9 @@ public class DeckFileHeader {
/** The Constant DECK_TYPE. */
public static final String DECK_TYPE = "Deck Type";
public static final String TAGS = "Tags";
public static final String TAGS_SEPARATOR = ",";
/** The Constant COMMENT. */
public static final String COMMENT = "Comment";
@@ -46,6 +54,8 @@ public class DeckFileHeader {
private final String name;
private final String comment;
private final Set<String> tags;
/**
* TODO: Write javadoc for Constructor.
*
@@ -59,6 +69,16 @@ public class DeckFileHeader {
this.customPool = kvPairs.getBoolean(DeckFileHeader.CSTM_POOL);
boolean isForAi = "computer".equalsIgnoreCase(kvPairs.get(DeckFileHeader.PLAYER)) || "ai".equalsIgnoreCase(kvPairs.get(DeckFileHeader.PLAYER_TYPE));
this.playerType = isForAi ? PlayerType.COMPUTER : PlayerType.HUMAN;
this.tags = new TreeSet<String>();
String rawTags = kvPairs.get(DeckFileHeader.TAGS);
if( StringUtils.isNotBlank(rawTags) ) {
for( String t: rawTags.split(TAGS_SEPARATOR))
if ( StringUtils.isNotBlank(t))
tags.add(t.trim());
}
}
/**
@@ -106,4 +126,8 @@ public class DeckFileHeader {
return this.deckType;
}
public final Set<String> getTags() {
return tags;
}
}