]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessorBase2.java
Merge commit '12468c2'
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / ClusterUpdateProcessorBase2.java
1 package org.simantics.acorn.internal;
2
3 import org.simantics.db.service.Bytes;
4 import org.simantics.db.service.ClusterUID;
5
6 public abstract class ClusterUpdateProcessorBase2 {
7
8         final private byte[] bytes;
9         private int pos = 0;
10         final private int len;
11         final private ClusterUID uid;
12         
13         public ClusterUpdateProcessorBase2(byte[] operations) {
14                 this.bytes = operations;
15                 this.len = Bytes.readLE4(bytes, 0) + 4; // whatta?
16                 int version = Bytes.readLE4(bytes, 4);
17                 assert(version == ClusterChange2.VERSION);
18                 long cuid1 = Bytes.readLE8(bytes, 8);
19                 long cuid2 = Bytes.readLE8(bytes, 16);
20                 pos = 24;
21                 uid = ClusterUID.make(cuid1, cuid2);
22         }
23         
24         public ClusterUID getClusterUID() {
25                 return uid;
26         }
27
28         private void processSetImmutable(int op) {
29                 int value = bytes[pos++]&0xff;
30                 setImmutable(value > 0);
31         }
32
33         private void processUndoValue(int op) {
34                 Bytes.readLE4(bytes, pos);
35                 pos+=4;
36         }
37
38         public void process() {
39                 
40                 while(pos < len) {
41                 
42                         int op = bytes[pos++]&0xff;
43                         
44                         switch(op) {
45                         
46                         case ClusterChange2.SET_IMMUTABLE_OPERATION:
47                                 processSetImmutable(op);
48                                 break;
49                         case ClusterChange2.UNDO_VALUE_OPERATION:
50                                 processUndoValue(op);
51                                 break;
52                         default:
53                                 throw new IllegalStateException();
54                                 
55                         }
56                         
57                 }
58                 
59         }
60         
61         abstract void setImmutable(boolean value);
62         
63 }