|
| 1 | +package uk.ac.ox.oxfish.fisher.purseseiner.regulations; |
| 2 | + |
| 3 | +import uk.ac.ox.oxfish.regulations.ForbiddenIf; |
| 4 | +import uk.ac.ox.oxfish.regulations.conditions.*; |
| 5 | +import uk.ac.ox.oxfish.regulations.quantities.NumberOfActiveFads; |
| 6 | +import uk.ac.ox.oxfish.utility.AlgorithmFactory; |
| 7 | +import uk.ac.ox.poseidon.regulations.api.Regulations; |
| 8 | + |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +public class ActiveFadLimits implements RegulationFactory { |
| 12 | + |
| 13 | + private Map<Integer, ? extends Map<String, Integer>> limitsPerYearAndClass; |
| 14 | + |
| 15 | + @SuppressWarnings("unused") |
| 16 | + public ActiveFadLimits() { |
| 17 | + } |
| 18 | + |
| 19 | + @SuppressWarnings({"unused", "WeakerAccess"}) |
| 20 | + public ActiveFadLimits( |
| 21 | + final Map<Integer, ? extends Map<String, Integer>> limitsPerYearAndClass |
| 22 | + ) { |
| 23 | + this.limitsPerYearAndClass = limitsPerYearAndClass; |
| 24 | + } |
| 25 | + |
| 26 | + @SuppressWarnings("unused") |
| 27 | + public Map<Integer, ? extends Map<String, Integer>> getLimitsPerYearAndClass() { |
| 28 | + return limitsPerYearAndClass; |
| 29 | + } |
| 30 | + |
| 31 | + @SuppressWarnings("unused") |
| 32 | + public void setLimitsPerYearAndClass(final Map<Integer, ? extends Map<String, Integer>> limitsPerYearAndClass) { |
| 33 | + this.limitsPerYearAndClass = limitsPerYearAndClass; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public AlgorithmFactory<Regulations> get() { |
| 38 | + return new ForbiddenIf( |
| 39 | + new AllOf( |
| 40 | + new ActionCodeIs("DPL"), |
| 41 | + new AnyOf( |
| 42 | + limitsPerYearAndClass.entrySet().stream().map(yearAndLimits -> |
| 43 | + new AllOf( |
| 44 | + new InYear(yearAndLimits.getKey()), |
| 45 | + new AnyOf( |
| 46 | + yearAndLimits.getValue().entrySet().stream().map(classAndLimit -> |
| 47 | + new AllOf( |
| 48 | + new AgentHasTag("class " + classAndLimit.getKey()), |
| 49 | + new NotBelow(new NumberOfActiveFads(), classAndLimit.getValue()) |
| 50 | + ) |
| 51 | + ) |
| 52 | + ) |
| 53 | + ) |
| 54 | + ) |
| 55 | + ) |
| 56 | + ) |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments