Commit 383263a2 authored by mey's avatar mey
Browse files

refactorings and minor changes in de.zmt.storage

renamed StoragePipelineTest to AbstractLimitedStoragePipelineTest.java
    and changed package to de.zmt.storage
moved StoragePipeline.DelayedStorage to AbstractLimitedStoragePipeline
BaseStorage.java
    made class public
MutableStorage.java
    made nested class ChangeResult explicitly public
parent d9b85e39
......@@ -13,9 +13,8 @@ import sim.util.Proxiable;
/**
* Implementation of {@link StoragePipeline} with a {@link DelayQueue} as the
* pipeline. Storage capacity and change factors are given by a
* {@link LimitedStorage} that stores the sum of all
* {@link de.zmt.storage.StoragePipeline.DelayedStorage}s queued up there. Only
* the amount from expired objects can be removed.
* {@link LimitedStorage} that stores the sum of all {@link DelayedStorage}s
* queued up there. Only the amount from expired objects can be removed.
*
* @author mey
* @param
......@@ -59,8 +58,7 @@ public abstract class AbstractLimitedStoragePipeline<Q extends Quantity>
* used within the pipeline.
*
* @param storedAmount
* @return {@link de.zmt.storage.StoragePipeline.DelayedStorage} which will
* be added to pipeline.
* @return {@link DelayedStorage} which will be added to pipeline.
*/
protected abstract DelayedStorage<Q> createDelayedStorage(Amount<Q> storedAmount);
......@@ -157,6 +155,31 @@ public abstract class AbstractLimitedStoragePipeline<Q extends Quantity>
return getClass().getSimpleName() + "[sum=" + sum + "]";
}
/**
* {@link Storage} implementing {@link Delayed}. {@link #getDelay(TimeUnit)}
* is passed and should be implemented in child class.
*
* @author mey
* @param
* <Q>
* the stored {@link Quantity}
*
*/
public static abstract class DelayedStorage<Q extends Quantity> extends BaseStorage<Q> implements Delayed {
private static final long serialVersionUID = 1L;
public DelayedStorage(Amount<Q> amount) {
this.setAmount(amount);
}
@Override
public int compareTo(Delayed o) {
// from TimerQueue#DelayedTimer
long diff = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
return (diff == 0) ? 0 : ((diff < 0) ? -1 : 1);
}
}
/**
* A queue that stores {@link Delayed} elements in order and only returns
* elements that are expired. Unlike the more complex {@link DelayQueue}
......
......@@ -15,7 +15,7 @@ import sim.util.Valuable;
* <Q>
* type of {@link Quantity}
*/
class BaseStorage<Q extends Quantity> implements Storage<Q>, Valuable {
public class BaseStorage<Q extends Quantity> implements Storage<Q>, Valuable {
private static final long serialVersionUID = 1L;
private Amount<Q> amount;
......
......@@ -37,7 +37,7 @@ public interface MutableStorage<Q extends Quantity> extends Storage<Q> {
* the {@link Quantity} of this ChangeResult
*
*/
class ChangeResult<Q extends Quantity> {
public class ChangeResult<Q extends Quantity> {
private final Amount<Q> stored;
private final Amount<Q> rejected;
......
package de.zmt.storage;
import java.util.Collection;
import java.util.concurrent.*;
import javax.measure.quantity.Quantity;
import org.jscience.physics.amount.Amount;
/**
* Pipeline containing storage objects with an expiration delay.
* Pipeline containing storage objects which can be drained when expired.
*
* @see AbstractLimitedStoragePipeline
* @author mey
......@@ -28,29 +27,4 @@ public interface StoragePipeline<Q extends Quantity> extends MutableStorage<Q> {
/** @return content of pipeline as {@link Collection} */
Collection<? extends Storage<Q>> getContent();
/**
* {@link Storage} implementing {@link Delayed}. {@link #getDelay(TimeUnit)}
* is passed and should be implemented in child class.
*
* @author mey
* @param
* <Q>
* the stored {@link Quantity}
*
*/
public static abstract class DelayedStorage<Q extends Quantity> extends BaseStorage<Q> implements Delayed {
private static final long serialVersionUID = 1L;
public DelayedStorage(Amount<Q> amount) {
this.setAmount(amount);
}
@Override
public int compareTo(Delayed o) {
// from TimerQueue#DelayedTimer
long diff = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
return (diff == 0) ? 0 : ((diff < 0) ? -1 : 1);
}
}
}
\ No newline at end of file
package de.zmt.storage.pipeline;
package de.zmt.storage;
import static org.junit.Assert.*;
......@@ -12,14 +12,11 @@ import javax.measure.unit.Unit;
import org.jscience.physics.amount.Amount;
import org.junit.*;
import de.zmt.storage.*;
import de.zmt.storage.StoragePipeline.DelayedStorage;
public class StoragePipelineTest implements Serializable {
public class AbstractLimitedStoragePipelineTest implements Serializable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(StoragePipelineTest.class.getName());
private static final Logger logger = Logger.getLogger(AbstractLimitedStoragePipelineTest.class.getName());
private static final long DURATION = 1;
......@@ -141,12 +138,12 @@ public class StoragePipelineTest implements Serializable {
}
@Override
protected DelayedStorage<Dimensionless> createDelayedStorage(Amount<Dimensionless> storedAmount) {
protected AbstractLimitedStoragePipeline.DelayedStorage<Dimensionless> createDelayedStorage(Amount<Dimensionless> storedAmount) {
return new FixedDelayStorage(storedAmount);
}
}
private class FixedDelayStorage extends DelayedStorage<Dimensionless> {
private class FixedDelayStorage extends AbstractLimitedStoragePipeline.DelayedStorage<Dimensionless> {
private static final long serialVersionUID = 1L;
private final long timeFinished;
......
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