| 10 | import java.util.Locale; |
| 11 | |
| 12 | public class PaperToken implements InventoryItemFromSet, IPaperCard { |
| 13 | private static final long serialVersionUID = 1L; |
| 14 | private String name; |
| 15 | private String collectorNumber; |
| 16 | private String artist; |
| 17 | private transient CardEdition edition; |
| 18 | private ArrayList<String> imageFileName = new ArrayList<>(); |
| 19 | private transient CardRules cardRules; |
| 20 | private int artIndex = 1; |
| 21 | |
| 22 | // takes a string of the form "<colors> <power> <toughness> <name>" such as: "B 0 0 Germ" |
| 23 | public static String makeTokenFileName(String in) { |
| 24 | StringBuffer out = new StringBuffer(); |
| 25 | char c; |
| 26 | for (int i = 0; i < in.length(); i++) { |
| 27 | c = in.charAt(i); |
| 28 | if ((c == ' ') || (c == '-') || (c == '_')) { |
| 29 | out.append('_'); |
| 30 | } else if (Character.isLetterOrDigit(c)) { |
| 31 | out.append(c); |
| 32 | } |
| 33 | } |
| 34 | return out.toString().toLowerCase(Locale.ENGLISH); |
| 35 | } |
| 36 | |
| 37 | public static String makeTokenFileName(String colors, String power, String toughness, String types) { |
| 38 | return makeTokenFileName(null, colors, power, toughness, types); |
| 39 | } |
| 40 | |
| 41 | public static String makeTokenFileName(String name, String colors, String power, String toughness, String types) { |
| 42 | ArrayList<String> build = new ArrayList<>(); |
| 43 | if (name != null) { |
| 44 | build.add(name); |
| 45 | } |
| 46 | |
| 47 | build.add(colors); |
| 48 | |
| 49 | if (power != null && toughness != null) { |
| 50 | build.add(power); |
| 51 | build.add(toughness); |
| 52 | } |
| 53 | build.add(types); |
| 54 | |
| 55 | String fileName = StringUtils.join(build, "_"); |
| 56 | return makeTokenFileName(fileName); |
| 57 | } |
| 58 | |
| 59 | public PaperToken(final CardRules c, CardEdition edition0, String imageFileName, String collectorNumber, String artist) { |
| 60 | this.cardRules = c; |
| 61 | this.name = c.getName(); |
| 62 | this.edition = edition0; |
| 63 | this.collectorNumber = collectorNumber; |
| 64 | this.artist = artist; |
| 65 | |
| 66 | if (collectorNumber != null && !collectorNumber.isEmpty() && edition != null && edition.getTokens().containsKey(imageFileName)) { |
| 67 | int idx = 0; |
| 68 | // count the one with the same collectorNumber |
| 69 | for (CardEdition.EditionEntry t : edition.getTokens().get(imageFileName)) { |
nothing calls this directly
no outgoing calls
no test coverage detected