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