Introduce ExecutionTimeSubject
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||
import fabrik.simulator.pic16f84.interfaces.PICComponentInterface;
|
||||
|
||||
public abstract class ExecutionTimeSubject extends PICComponent implements PICComponentInterface{
|
||||
private Set<ExecutionTimeObserver> observers;
|
||||
|
||||
public ExecutionTimeSubject(){
|
||||
super();
|
||||
this.observers = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
public void registerObserver(ExecutionTimeObserver observer){
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void unregisterObserver(ExecutionTimeObserver observer){
|
||||
observers.remove(observer);
|
||||
}
|
||||
|
||||
protected void notifyObservers(){
|
||||
for (final ExecutionTimeObserver each : observers){
|
||||
notify(each);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notify(final ExecutionTimeObserver observer) {
|
||||
createNotifierFor(observer).start();
|
||||
}
|
||||
|
||||
|
||||
protected Thread createNotifierFor(ExecutionTimeObserver observer) {
|
||||
return new Thread(){
|
||||
public void run(){
|
||||
try {
|
||||
observer.executionTimeChanged();
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
ExecutionTimeSubject.this.observers.remove(observer);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public double getTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void addExecutionTime(int i){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public double getExecutionTimeMultiplier(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void setExecutionTimeMultiplier(String option){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void resetTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user