Commit d9b85e39 authored by mey's avatar mey
Browse files

Storage.java: now implements Valuable to use MASON's charting capabilities

    updated implementing classes AbstractLimitedStoragePipeline,
            BaseStorage, ConfigurableStorage.java
added ValuableAmountAdapter.java
    to wrap Amount objects into Valuable interface
parent f9d9a68c
......@@ -142,6 +142,11 @@ public abstract class AbstractLimitedStoragePipeline<Q extends Quantity>
return sum.getAmount();
}
@Override
public double doubleValue() {
return sum.doubleValue();
}
@Override
public Object propertiesProxy() {
return new MyPropertiesProxy();
......
......@@ -4,6 +4,8 @@ import javax.measure.quantity.Quantity;
import org.jscience.physics.amount.Amount;
import sim.util.Valuable;
/**
* Basic implementation of {@link Storage}.
*
......@@ -13,7 +15,7 @@ import org.jscience.physics.amount.Amount;
* <Q>
* type of {@link Quantity}
*/
class BaseStorage<Q extends Quantity> implements Storage<Q> {
class BaseStorage<Q extends Quantity> implements Storage<Q>, Valuable {
private static final long serialVersionUID = 1L;
private Amount<Q> amount;
......@@ -31,4 +33,9 @@ class BaseStorage<Q extends Quantity> implements Storage<Q> {
public String toString() {
return getClass().getSimpleName() + "[amount=" + getAmount() + "]";
}
@Override
public double doubleValue() {
return amount.getEstimatedValue();
}
}
\ No newline at end of file
......@@ -5,8 +5,8 @@ import javax.measure.unit.Unit;
import org.jscience.physics.amount.Amount;
import de.zmt.util.AmountUtil;
import sim.util.Proxiable;
import de.zmt.util.*;
import sim.util.*;
/**
* A {@link MutableStorage} that rejects any amount exceeding its limits. Apart
......@@ -203,16 +203,16 @@ public class ConfigurableStorage<Q extends Quantity> extends BaseStorage<Q> impl
}
public class MyPropertiesProxy {
public Amount<Q> getAmount() {
return ConfigurableStorage.this.getAmount();
public Valuable getAmount() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getAmount());
}
public Amount<Q> getLowerLimit() {
return ConfigurableStorage.this.getLowerLimit();
public Valuable getLowerLimit() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getLowerLimit());
}
public Amount<Q> getUpperLimit() {
return ConfigurableStorage.this.getUpperLimit();
public Valuable getUpperLimit() {
return new ValuableAmountAdapter(ConfigurableStorage.this.getUpperLimit());
}
public double getFactorIn() {
......
......@@ -6,6 +6,8 @@ import javax.measure.quantity.Quantity;
import org.jscience.physics.amount.Amount;
import sim.util.Valuable;
/**
* Interface for a simple storage containing an {@link Amount}.
*
......@@ -15,7 +17,7 @@ import org.jscience.physics.amount.Amount;
* <Q>
* type of {@link Quantity}
*/
public interface Storage<Q extends Quantity> extends Serializable {
public interface Storage<Q extends Quantity> extends Serializable, Valuable {
/**
*
* @return stored amount
......
package de.zmt.util;
import org.jscience.physics.amount.Amount;
import sim.util.Valuable;
/**
* Simple adapter class wrapping around an {@link Amount} to be used as a
* {@link Valuable}.
*
* @author mey
*/
public class ValuableAmountAdapter implements Valuable {
private final Amount<?> amount;
public ValuableAmountAdapter(Amount<?> amount) {
super();
this.amount = amount;
}
@Override
public double doubleValue() {
return amount.getEstimatedValue();
}
@Override
public String toString() {
return amount.toString();
}
}
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