summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/CallbackPropertyOperator.java
blob: 55c24189563ce8bc72b782dea1f7134ed6b567ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package NET.worlds.scape;

import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;

public class CallbackPropertyOperator implements MainCallback {
   private Property prop;
   private int func;
   private Object value;
   private boolean done;

   CallbackPropertyOperator(Property prop, int func, Object value) {
      this.prop = prop;
      this.func = func;
      this.value = value;

      assert !Main.isMainThread();

      Main.register(this);
   }

   synchronized Object getValue() {
      while (!this.done) {
         try {
            this.wait();
         } catch (InterruptedException var2) {
         }
      }

      return this.value;
   }

   @Override
   public synchronized void mainCallback() {
      this.modify();
      Main.unregister(this);
      this.notify();
   }

   private void modify() {
      this.value = this.prop.safeOperate(this.func, this.value);
      this.done = true;
   }
}