The Class PreCampaignTester is responsible for testing if the currently loaded sources satisfy the campaign prerequisite.
| 44 | * |
| 45 | */ |
| 46 | public class PreCampaignTester extends AbstractDisplayPrereqTest implements PrerequisiteTest |
| 47 | { |
| 48 | |
| 49 | @Override |
| 50 | public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) |
| 51 | throws PrerequisiteException |
| 52 | { |
| 53 | final int number; |
| 54 | try |
| 55 | { |
| 56 | number = Integer.parseInt(prereq.getOperand()); |
| 57 | } |
| 58 | catch (NumberFormatException exceptn) |
| 59 | { |
| 60 | throw new PrerequisiteException( |
| 61 | LanguageBundle.getFormattedString("PreFeat.error", prereq.toString()), exceptn); //$NON-NLS-1$ |
| 62 | } |
| 63 | |
| 64 | int runningTotal = 0; |
| 65 | if (prereq.getKey().startsWith("BOOKTYPE=")) |
| 66 | { |
| 67 | runningTotal += countCampaignByBookType(prereq.getKey().substring(9), false); |
| 68 | } |
| 69 | else if (prereq.getKey().startsWith("INCLUDESBOOKTYPE=")) |
| 70 | { |
| 71 | runningTotal += countCampaignByBookType(prereq.getKey().substring(17), true); |
| 72 | } |
| 73 | else if (prereq.getKey().startsWith("INCLUDES=")) |
| 74 | { |
| 75 | runningTotal += countCampaignByName(prereq.getKey().substring(9), source, true); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | runningTotal += countCampaignByName(prereq.getKey(), source, false); |
| 80 | } |
| 81 | |
| 82 | runningTotal = prereq.getOperator().compare(runningTotal, number); |
| 83 | return countedTotal(prereq, runningTotal); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Count the number of campaign currently loaded or selected that |
| 88 | * are of the book type. |
| 89 | * |
| 90 | * @param bookType the book type |
| 91 | * @param includeSubCampaigns Should we count included sub campaigns that match |
| 92 | * |
| 93 | * @return the number of matching campaigns |
| 94 | */ |
| 95 | private int countCampaignByBookType(String bookType, boolean includeSubCampaigns) |
| 96 | { |
| 97 | Set<Campaign> matchingCampaigns = new HashSet<>(); |
| 98 | PersistenceManager pMan = PersistenceManager.getInstance(); |
| 99 | List<URI> selCampaigns = pMan.getChosenCampaignSourcefiles(); |
| 100 | for (URI element : selCampaigns) |
| 101 | { |
| 102 | final Campaign aCampaign = Globals.getCampaignByURI(element, false); |
| 103 | List<Campaign> fullCampList; |
nothing calls this directly
no outgoing calls
no test coverage detected