annotate src/main/csharp/jp.ac.u-ryukyu.ie.cr/jungle-network/operations/NetworkNodeOperation.cs @ 12:b71d9ea6bd8e

Add Network Operation Class. this codes can not test yet.
author Kazuma
date Sun, 23 Oct 2016 12:25:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
1 using UnityEngine;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
2 using System.Collections;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
3
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
4 public class NetworkNodeOperation : NodeOperation {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
5
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
6 public int Position;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
7 public string Key;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
8 public byte[] Value;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
9 public int commandType;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
10
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
11 // when switch use static readonly so, use const.
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
12 // when A code compalie, case const use is fast.
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
13 // case readonly use is bit slow.
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
14 public const int NUM_PUT_ATTRIBUTE = 1;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
15 public const int NUM_APPEND_CHILD = 2;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
16 public const int NUM_DELETE_CHILD = 3;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
17 public const int NUM_DELETE_ATTRIBUTE = 4;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
18
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
19 public NetworkNodeOperation () {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
20 this.Position = -2;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
21 this.Key = null;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
22 this.Value = null;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
23 this.commandType = 0;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
24 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
25
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
26 public NetworkNodeOperation(NodeOperation op) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
27 this.Position = op.getPosition();
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
28 this.Key = op.getKey();
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
29 this.Value = op.getValue();
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
30 this.commandType = getCommandType(op.getCommand());
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
31 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
32
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
33 public static int getCommandType (Command c) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
34 switch(c) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
35 case Command.PUT_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
36 return NUM_PUT_ATTRIBUTE;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
37 case Command.APPEND_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
38 return NUM_APPEND_CHILD;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
39 case Command.DELETE_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
40 return NUM_DELETE_CHILD;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
41 case Command.DELETE_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
42 return NUM_DELETE_ATTRIBUTE;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
43 default:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
44 break;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
45 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
46 return 0;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
47 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
48
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
49 public static Command getCommand (int num) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
50 switch(num) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
51 case NUM_PUT_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
52 return Command.PUT_ATTRIBUTE;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
53 case NUM_APPEND_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
54 return Command.APPEND_CHILD;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
55 case NUM_DELETE_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
56 return Command.DELETE_CHILD;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
57 case NUM_DELETE_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
58 return Command.DELETE_ATTRIBUTE;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
59 default:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
60 break;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
61 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
62 return Command.DEFAULT;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
63 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
64
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
65 public Command getCommand() {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
66 return getCommand(commandType);
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
67 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
68
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
69 public int getPosition () {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
70 return this.Position;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
71 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
72
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
73 public string getKey () {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
74 return this.Key;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
75 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
76
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
77 public byte[] getValue() {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
78 return this.Value;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
79 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
80
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
81 public Either<Error, TreeNode> invoke (TreeNode target) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
82 switch(getCommand(commandType)) {
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
83 case Command.PUT_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
84 return target.getAttributes().put(this.Key, this.Value);
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
85 case Command.APPEND_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
86 return target.getChildren().addNewChildAt(this.Position);
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
87 case Command.DELETE_CHILD:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
88 return target.getChildren().deleteChildAt(this.Position);
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
89 case Command.DELETE_ATTRIBUTE:
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
90 return target.getAttributes().delete(this.Key);
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
91 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
92 return null;
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
93 }
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
94
b71d9ea6bd8e Add Network Operation Class. this codes can not test yet.
Kazuma
parents:
diff changeset
95 }