Observer Pattern für ResultSet.

This commit is contained in:
Michael Uhl 2019-01-23 22:28:07 +01:00
commit 3ad51f952e
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package de.dhbwstuttgart.typeinference.unify;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class UnifyResultEvent {
private ResultSet newTypeResult;
public UnifyResultEvent(ResultSet newTypeResult) {
this.newTypeResult = newTypeResult;
}
public ResultSet getNewTypeResult() {
return newTypeResult;
}
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.typeinference.unify;
public interface UnifyResultListener {
void onNewTypeResultFound(UnifyResultEvent evt);
}

View File

@ -0,0 +1,27 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typeinference.result.ResultSet;
public class UnifyResultModel {
private List<UnifyResultListener> listeners = new ArrayList<>();
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
listeners.add(listenerToAdd);
}
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
listeners.remove(listenerToRemove);
}
public void notify(ResultSet newResult) {
UnifyResultEvent evt = new UnifyResultEvent(newResult);
for (UnifyResultListener listener : listeners) {
listener.onNewTypeResultFound(evt);
}
}
}