| 34 | import pcgen.rules.context.LoadContext; |
| 35 | |
| 36 | public class AbilitySelection extends Selection<Ability, String> implements Comparable<AbilitySelection>, Reducible |
| 37 | { |
| 38 | |
| 39 | public AbilitySelection(Ability obj, String sel) |
| 40 | { |
| 41 | super(obj, sel); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Decodes the given String into an AbilitySelection. The String format to |
| 46 | * be passed into this method is defined solely by the return result of the |
| 47 | * getPersistentFormat method. There is no guarantee that the encoding is |
| 48 | * human readable, simply that the encoding is uniquely identifying such |
| 49 | * that this method is capable of decoding the String into an |
| 50 | * AbilitySelection. |
| 51 | * |
| 52 | * @param persistentFormat |
| 53 | * The String which should be decoded to provide an |
| 54 | * AbilitySelection. |
| 55 | * |
| 56 | * @return An AbilitySelection that was encoded in the given String. |
| 57 | */ |
| 58 | public static AbilitySelection getAbilitySelectionFromPersistentFormat(LoadContext context, String persistentFormat) |
| 59 | { |
| 60 | if (!persistentFormat.contains(Constants.PIPE)) |
| 61 | { |
| 62 | return decodeFeatSelectionChoice(context, persistentFormat); |
| 63 | } |
| 64 | StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE); |
| 65 | String catString = st.nextToken(); |
| 66 | if (!catString.startsWith("CATEGORY=")) |
| 67 | { |
| 68 | throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " |
| 69 | + "must start with CATEGORY=, found: " + persistentFormat); |
| 70 | } |
| 71 | String cat = catString.substring(9); |
| 72 | AbilityCategory ac = SettingsHandler.getGameAsProperty().get().getAbilityCategory(cat); |
| 73 | if (ac == null) |
| 74 | { |
| 75 | throw new IllegalArgumentException( |
| 76 | "Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat); |
| 77 | } |
| 78 | String ab = st.nextToken(); |
| 79 | Ability a = context.getReferenceContext().getManufacturerId(ac).getActiveObject(ab); |
| 80 | if (a == null) |
| 81 | { |
| 82 | throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " |
| 83 | + "must be an Ability, but it was not found: " + persistentFormat); |
| 84 | } |
| 85 | String sel = null; |
| 86 | if (st.hasMoreTokens()) |
| 87 | { |
| 88 | /* |
| 89 | * No need to check for MULT:YES/NO here, as that is checked |
| 90 | * implicitly in the construction of AbilitySelection below |
| 91 | */ |
| 92 | sel = st.nextToken(); |
| 93 | } |
nothing calls this directly
no outgoing calls
no test coverage detected