mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
24 lines
452 B
Scala
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)
|
|
}
|