Mercurial > hg > Members > tatsuki > Alice
annotate src/alice/datasegment/Receiver.java @ 100:b01fb5090e28 working
add default code to each case statements
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Jun 2012 01:50:29 +0900 |
parents | 33a19ca88e43 |
children | bddb8be357f6 |
rev | line source |
---|---|
3 | 1 package alice.datasegment; |
2 | |
34
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
3 import java.io.IOException; |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
4 |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
5 import org.msgpack.MessagePack; |
18 | 6 import org.msgpack.type.Value; |
30 | 7 import org.msgpack.type.ValueType; |
18 | 8 |
9 import alice.codesegment.InputDataSegment; | |
10 | |
57 | 11 /** |
12 * MessagePack implementation and DataSegment Receiver | |
13 * @author kazz | |
14 * | |
15 */ | |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
16 public class Receiver { |
18 | 17 public InputDataSegment ids; |
18 public int index; | |
19 public Value val; | |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
20 public String from; |
18 | 21 public CommandType type; |
22 | |
57 | 23 public String managerKey; // for debugging |
24 public String key; // for debugging | |
44 | 25 |
33
20c67f673224
change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
26 public Receiver(InputDataSegment ids, CommandType type) { |
18 | 27 this.ids = ids; |
28 this.type = type; | |
19 | 29 ids.regist(); |
18 | 30 } |
31 | |
32 public void setKey(String managerKey, String key) { | |
57 | 33 this.managerKey = managerKey; |
34 this.key = key; | |
18 | 35 setKey(managerKey, key, 0); |
36 } | |
3 | 37 |
18 | 38 public void setKey(String managerKey, String key, int index) { |
39 switch (type) { | |
40 case PEEK: | |
41 ids.peek(this, managerKey, key, index); | |
42 break; | |
43 case TAKE: | |
44 ids.take(this, managerKey, key, index); | |
45 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
46 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
47 break; |
18 | 48 } |
19 | 49 ids.setKey(); |
18 | 50 } |
51 | |
65 | 52 public void setKey(String key) { |
53 this.key = key; | |
54 setKey(key, 0); | |
55 } | |
56 | |
57 public void setKey(String key, int index) { | |
58 switch (type) { | |
59 case PEEK: | |
60 ids.peek(this, key, index); | |
61 break; | |
62 case TAKE: | |
63 ids.take(this, key, index); | |
64 break; | |
100
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
65 default: |
b01fb5090e28
add default code to each case statements
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
88
diff
changeset
|
66 break; |
65 | 67 } |
68 ids.setKey(); | |
69 } | |
70 | |
30 | 71 public String asString() { |
72 if (val.getType() == ValueType.RAW) { | |
73 return val.asRawValue().getString(); | |
74 } | |
75 return null; | |
76 } | |
77 | |
78 public int asInteger() { | |
79 if (val.getType() == ValueType.INTEGER) { | |
80 return val.asIntegerValue().getInt(); | |
81 } | |
82 return 0; | |
83 } | |
84 | |
88 | 85 public Float asFloat() { |
86 if (val.getType() == ValueType.FLOAT) { | |
87 return val.asFloatValue().getFloat(); | |
88 } | |
89 return 0.0f; | |
90 } | |
91 | |
34
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
92 public <T> T asClass(Class<T> clazz) { |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
93 MessagePack msgpack = new MessagePack(); |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
94 try { |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
95 return msgpack.convert(val, clazz); |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
96 } catch (IOException e) { |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
97 e.printStackTrace(); |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
98 } |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
99 return null; |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
100 } |
ca079a730d0b
added method to OutputDataSegment and Receiver, to convert type from Value to Class<?> without MessagePack
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
101 |
3 | 102 } |