2025-08-21 13:11:58 +02:00

24 lines
452 B
Scala

package ocelot.desktop.util
/**
* Keeps a reference to an object
* and tells whether there were any changes to the value since the last check.
*/
class Watcher[T](value: T) {
private var hash: Int = value.hashCode()
def didChange: Boolean = {
val newHash = value.hashCode()
if (hash != newHash) {
hash = newHash
true
} else {
false
}
}
}
object Watcher {
def apply[T](value: T) = new Watcher(value)
}