You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.0 KiB
84 lines
2.0 KiB
package explicit;
|
|
|
|
import java.util.BitSet;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* An AccumulationState contains a reference to an AccumulationTracker,
|
|
* a pointer to the latest restart and the numberOfTracks in the tracker.
|
|
* It can optionally contain a BitSet marking the goodTracks.
|
|
*
|
|
* @author Sascha Wunderlich
|
|
*
|
|
*/
|
|
public class AccumulationState<Component> {
|
|
protected final int trackerId;
|
|
|
|
protected int lastRestartNr;
|
|
protected int numberOfTracks;
|
|
|
|
protected BitSet goodTracks;
|
|
|
|
public AccumulationState(int trackerId, int lastRestartNr, int numberOfTracks, BitSet goodTracks) {
|
|
this(trackerId, lastRestartNr, numberOfTracks);
|
|
this.goodTracks = goodTracks;
|
|
}
|
|
|
|
public AccumulationState(int trackerId, int lastRestartNr, int numberOfTracks) {
|
|
super();
|
|
this.trackerId = trackerId;
|
|
this.lastRestartNr = lastRestartNr;
|
|
this.numberOfTracks = numberOfTracks;
|
|
this.goodTracks = new BitSet();
|
|
}
|
|
|
|
public int getTrackerId() {
|
|
return trackerId;
|
|
}
|
|
|
|
public AccumulationTracker<Component> getTracker(StoragePool<AccumulationTracker<Component>> trackers) {
|
|
return trackers.getById(trackerId);
|
|
}
|
|
|
|
public int getNextRestartNr() {
|
|
return (lastRestartNr + 1) % numberOfTracks;
|
|
}
|
|
|
|
public boolean importantTrackIsGood() {
|
|
return goodTracks.get(getNextRestartNr());
|
|
}
|
|
|
|
public BitSet getGoodTracks() {
|
|
return goodTracks;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(goodTracks, lastRestartNr, numberOfTracks, trackerId);
|
|
}
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
return true;
|
|
if (obj == null)
|
|
return false;
|
|
if (getClass() != obj.getClass())
|
|
return false;
|
|
AccumulationState other = (AccumulationState) obj;
|
|
return Objects.equals(goodTracks, other.goodTracks) && lastRestartNr == other.lastRestartNr
|
|
&& numberOfTracks == other.numberOfTracks && trackerId == other.trackerId;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
StringBuffer result = new StringBuffer();
|
|
result.append("S");
|
|
|
|
result.append(trackerId);
|
|
|
|
return result.toString();
|
|
}
|
|
|
|
}
|