Skip to content

Commit

Permalink
fix a few SpotBugs warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspayette committed Feb 4, 2025
1 parent f97aed7 commit 503b369
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package uk.ac.ox.poseidon.agents.behaviours.fishing;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.Getter;
import sim.util.Int2D;
import uk.ac.ox.poseidon.agents.behaviours.AbstractAction;
Expand All @@ -29,6 +30,7 @@
import java.time.LocalDateTime;

@Getter
@SuppressFBWarnings(value = "EI2", justification = "Int2D is actually immutable.")
public class DummyFishingAction extends AbstractAction implements FishingAction {

private final Int2D cell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

import javax.measure.Quantity;
import javax.measure.Unit;
import java.util.Map.Entry;

import static java.util.Map.entry;

@Getter
@Setter
Expand All @@ -51,14 +54,15 @@ public abstract class AbstractQuantityFactory<Q extends Quantity<Q>>
private double value;
private String unitString;

public AbstractQuantityFactory(
static <Q extends Quantity<Q>> Entry<String, Double> parse(
final Class<Q> type,
final String quantity
) {
this.type = type;
final Quantity<Q> q = SimpleQuantityFormat.getInstance().parse(quantity).asType(type);
this.value = q.getValue().doubleValue();
this.unitString = q.getUnit().toString();
return entry(
q.getUnit().toString(),
q.getValue().doubleValue()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public MassFactory() {
super(Mass.class);
}

public MassFactory(
final String quantity
) {
super(Mass.class, quantity);
}

public MassFactory(
final double value,
final String unitString
Expand All @@ -47,4 +41,10 @@ public MassFactory(
) {
super(Mass.class, value, unit.toString());
}

public static MassFactory of(final String quantity) {
final var entry = parse(Mass.class, quantity);
return new MassFactory(entry.getValue(), entry.getKey());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public SpeedFactory() {
super(Speed.class);
}

public SpeedFactory(
final String quantity
) {
super(Speed.class, quantity);
}

public SpeedFactory(
final double value,
final String unitString
Expand All @@ -48,4 +42,9 @@ public SpeedFactory(
super(Speed.class, value, unit.toString());
}

public static SpeedFactory of(final String quantity) {
final var entry = parse(Speed.class, quantity);
return new SpeedFactory(entry.getValue(), entry.getKey());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public class BasicScenario extends Scenario {
private Factory<? extends CarryingCapacityGrid> carryingCapacityGrid =
new UniformCarryingCapacityGridFactory(
bathymetricGrid,
new MassFactory(CARRYING_CAPACITY)
MassFactory.of(CARRYING_CAPACITY)
);
private Factory<? extends BiomassAllocator> biomassAllocator =
new FullBiomassAllocatorFactory(carryingCapacityGrid);
Expand Down Expand Up @@ -245,8 +245,8 @@ public class BasicScenario extends Scenario {
0
);
private VesselScopeFactory<? extends Hold<Biomass>> hold = new StandardBiomassHoldFactory(
new MassFactory(VESSEL_HOLD_CAPACITY),
new MassFactory("1 kg"),
MassFactory.of(VESSEL_HOLD_CAPACITY),
MassFactory.of("1 kg"),
new ProportionalBiomassOvercapacityDiscardingStrategyFactory()
);
private VesselScopeFactory<? extends MutableOptionValues<Int2D>> optionValues =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class ExternalScenario extends Scenario {
private Factory<? extends CarryingCapacityGrid> carryingCapacityGrid =
new UniformCarryingCapacityGridFactory(
bathymetricGrid,
new MassFactory("5000 kg")
MassFactory.of("5000 kg")
);
private Factory<? extends BiomassAllocator> biomassAllocator =
new FullBiomassAllocatorFactory(carryingCapacityGrid);
Expand Down Expand Up @@ -274,7 +274,7 @@ public class ExternalScenario extends Scenario {
vesselField,
new RandomHomePortFactory(portGrid),
portGrid,
new SpeedFactory("15 km/h")
SpeedFactory.of("15 km/h")
)
);

Expand Down

0 comments on commit 503b369

Please sign in to comment.