Commit 17e2a4cc authored by mey's avatar mey
Browse files

ValuableAmountAdapter.java: added factory method wrap to better handle null

    made constructor private
    updated ConfigurableStorage
parent 383263a2
......@@ -204,15 +204,15 @@ public class ConfigurableStorage<Q extends Quantity> extends BaseStorage<Q> impl
public class MyPropertiesProxy {
public Valuable getAmount() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getAmount());
return ValuableAmountAdapter.wrap(ConfigurableStorage.this.getAmount());
}
public Valuable getLowerLimit() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getLowerLimit());
return ValuableAmountAdapter.wrap(ConfigurableStorage.this.getLowerLimit());
}
public Valuable getUpperLimit() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getUpperLimit());
return ValuableAmountAdapter.wrap(ConfigurableStorage.this.getUpperLimit());
}
public double getFactorIn() {
......
......@@ -13,7 +13,7 @@ import sim.util.Valuable;
public class ValuableAmountAdapter implements Valuable {
private final Amount<?> amount;
public ValuableAmountAdapter(Amount<?> amount) {
private ValuableAmountAdapter(Amount<?> amount) {
super();
this.amount = amount;
}
......@@ -27,4 +27,18 @@ public class ValuableAmountAdapter implements Valuable {
public String toString() {
return amount.toString();
}
/**
* Returns {@code amount} wrapped into a {@link ValuableAmountAdapter} or
* <code>null</code> if {@code amount} is null.
*
* @param amount
* @return wrapped {@code amount}
*/
public static ValuableAmountAdapter wrap(Amount<?> amount) {
if (amount != null) {
return new ValuableAmountAdapter(amount);
}
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment