Copyright (C) 2013 Madis Pink
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...
If you think the Android project bad listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.madisp.bad.eval;
/*www.java2s.com*/import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created with IntelliJ IDEA.
* User: madis
* Date: 3/20/13
* Time: 9:04 AM
*/publicclass BadVar<T> {
private T var;
private Set<BadWatcher> watchers = new HashSet<BadWatcher>();
public BadVar() {
}
public BadVar(T value) {
this.var = value;
}
public T get() {
return var;
}
publicvoid set(T value) {
set(value, null);
}
publicvoid set(T value, BadWatcher origin) {
if (value instanceof List) {
value = (T)BadCollections.wrapList(this, (List)value);
} elseif (value instanceof Collection) {
value = (T)BadCollections.wrapCollection(this, (Collection)value);
}
this.var = value;
dispatchFire(origin);
}
publicvoid dispatchFire() {
dispatchFire(null);
}
publicvoid dispatchFire(BadWatcher origin) {
for (BadWatcher w : watchers) {
if (origin != null && origin == w) {
continue;
}
w.fire(this);
}
}
publicvoid addWatcher(BadWatcher<T> watcher) {
watchers.add(watcher);
watcher.fire(this);
}
publicvoid removeWatcher(BadWatcher<T> watcher) {
watchers.remove(watcher);
}
publicinterface BadWatcher<T> {
void fire(BadVar<T> var);
}
}