|
| 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.utility.AlgorithmFactory; |
| 6 | +import uk.ac.ox.oxfish.utility.parameters.IntegerParameter; |
| 7 | +import uk.ac.ox.poseidon.regulations.api.Regulations; |
| 8 | + |
| 9 | +import java.time.MonthDay; |
| 10 | + |
| 11 | +import static uk.ac.ox.oxfish.fisher.purseseiner.regulations.DefaultEpoRegulations.addDays; |
| 12 | +import static uk.ac.ox.oxfish.regulations.conditions.False.FALSE; |
| 13 | + |
| 14 | +public class Closure implements RegulationFactory { |
| 15 | + private IntegerParameter beginningDay; |
| 16 | + private IntegerParameter beginningMonth; |
| 17 | + private IntegerParameter endDay; |
| 18 | + private IntegerParameter endMonth; |
| 19 | + private IntegerParameter daysToForbidDeploymentsBefore; |
| 20 | + |
| 21 | + public Closure() { |
| 22 | + } |
| 23 | + |
| 24 | + public Closure( |
| 25 | + final MonthDay beginning, |
| 26 | + final MonthDay end, |
| 27 | + final int daysToForbidDeploymentsBefore |
| 28 | + ) { |
| 29 | + this( |
| 30 | + new IntegerParameter(beginning.getDayOfMonth()), |
| 31 | + new IntegerParameter(beginning.getMonthValue()), |
| 32 | + new IntegerParameter(end.getDayOfMonth()), |
| 33 | + new IntegerParameter(end.getMonthValue()), |
| 34 | + new IntegerParameter(daysToForbidDeploymentsBefore) |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + public Closure( |
| 39 | + final IntegerParameter beginningDay, |
| 40 | + final IntegerParameter beginningMonth, |
| 41 | + final IntegerParameter endDay, |
| 42 | + final IntegerParameter endMonth, |
| 43 | + final IntegerParameter daysToForbidDeploymentsBefore |
| 44 | + ) { |
| 45 | + this.beginningDay = beginningDay; |
| 46 | + this.beginningMonth = beginningMonth; |
| 47 | + this.endDay = endDay; |
| 48 | + this.endMonth = endMonth; |
| 49 | + this.daysToForbidDeploymentsBefore = daysToForbidDeploymentsBefore; |
| 50 | + } |
| 51 | + |
| 52 | + @SuppressWarnings("unused") |
| 53 | + public IntegerParameter getDaysToForbidDeploymentsBefore() { |
| 54 | + return daysToForbidDeploymentsBefore; |
| 55 | + } |
| 56 | + |
| 57 | + @SuppressWarnings("unused") |
| 58 | + public void setDaysToForbidDeploymentsBefore(final IntegerParameter daysToForbidDeploymentsBefore) { |
| 59 | + this.daysToForbidDeploymentsBefore = daysToForbidDeploymentsBefore; |
| 60 | + } |
| 61 | + |
| 62 | + @SuppressWarnings("unused") |
| 63 | + public IntegerParameter getBeginningDay() { |
| 64 | + return beginningDay; |
| 65 | + } |
| 66 | + |
| 67 | + @SuppressWarnings("unused") |
| 68 | + public void setBeginningDay(final IntegerParameter beginningDay) { |
| 69 | + this.beginningDay = beginningDay; |
| 70 | + } |
| 71 | + |
| 72 | + @SuppressWarnings("unused") |
| 73 | + public IntegerParameter getBeginningMonth() { |
| 74 | + return beginningMonth; |
| 75 | + } |
| 76 | + |
| 77 | + @SuppressWarnings("unused") |
| 78 | + public void setBeginningMonth(final IntegerParameter beginningMonth) { |
| 79 | + this.beginningMonth = beginningMonth; |
| 80 | + } |
| 81 | + |
| 82 | + @SuppressWarnings("unused") |
| 83 | + public IntegerParameter getEndDay() { |
| 84 | + return endDay; |
| 85 | + } |
| 86 | + |
| 87 | + @SuppressWarnings("unused") |
| 88 | + public void setEndDay(final IntegerParameter endDay) { |
| 89 | + this.endDay = endDay; |
| 90 | + } |
| 91 | + |
| 92 | + @SuppressWarnings("unused") |
| 93 | + public IntegerParameter getEndMonth() { |
| 94 | + return endMonth; |
| 95 | + } |
| 96 | + |
| 97 | + @SuppressWarnings("unused") |
| 98 | + public void setEndMonth(final IntegerParameter endMonth) { |
| 99 | + this.endMonth = endMonth; |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public AlgorithmFactory<Regulations> get() { |
| 104 | + final MonthDay beginning = getBeginning(); |
| 105 | + return new ForbiddenIf( |
| 106 | + new AnyOf( |
| 107 | + daysToForbidDeploymentsBefore.getIntValue() >= 1 |
| 108 | + ? forbidDeploymentsBefore(beginning, daysToForbidDeploymentsBefore.getIntValue()) |
| 109 | + : FALSE, |
| 110 | + new AllOf( |
| 111 | + new AgentHasTag("closure A"), |
| 112 | + new BetweenYearlyDates( |
| 113 | + beginning, |
| 114 | + getEnd() |
| 115 | + ) |
| 116 | + ) |
| 117 | + ) |
| 118 | + ); |
| 119 | + } |
| 120 | + |
| 121 | + public MonthDay getBeginning() { |
| 122 | + return makeMonthDay(beginningMonth, beginningDay); |
| 123 | + } |
| 124 | + |
| 125 | + private AllOf forbidDeploymentsBefore(final MonthDay beginning, final int numDays) { |
| 126 | + return new AllOf( |
| 127 | + new AgentHasTag("closure A"), |
| 128 | + new ActionCodeIs("DPL"), |
| 129 | + new BetweenYearlyDates( |
| 130 | + addDays(beginning, -numDays), |
| 131 | + addDays(beginning, -1) |
| 132 | + ) |
| 133 | + ); |
| 134 | + } |
| 135 | + |
| 136 | + public MonthDay getEnd() { |
| 137 | + return makeMonthDay(endMonth, endDay); |
| 138 | + } |
| 139 | + |
| 140 | + private static MonthDay makeMonthDay(final IntegerParameter month, final IntegerParameter day) { |
| 141 | + return MonthDay.of(month.getIntValue(), day.getIntValue()); |
| 142 | + } |
| 143 | +} |
0 commit comments