Mercurial > hg > Members > tatsuki > Alice
view src/alice/datasegment/ReceiveRemoteData.java @ 212:b5daccf36104 working
add Receiver state pattern
author | one |
---|---|
date | Wed, 27 Mar 2013 17:30:52 +0900 |
parents | |
children | 3f20b6401823 |
line wrap: on
line source
package alice.datasegment; import java.io.IOException; import org.msgpack.type.ArrayValue; import org.msgpack.type.Value; import org.msgpack.type.ValueType; import alice.codesegment.SingletonMessage; public class ReceiveRemoteData implements ReceiverData { public Value val; public ReceiveRemoteData() { } public ReceiveRemoteData(Value val2) { this.val = val2; } public String asString(Receiver receiver) { if (val.getType() == ValueType.RAW) { return val.asRawValue().getString(); } return null; } public int asInteger(Receiver receiver) { if (val.getType() == ValueType.INTEGER) { return val.asIntegerValue().getInt(); } return 0; } public Float asFloat(Receiver receiver) { if (val.getType() == ValueType.FLOAT) { return val.asFloatValue().getFloat(); } return 0.0f; } public ArrayValue asArray(Receiver receiver){ if (val.getType() == ValueType.ARRAY){ return val.asArrayValue(); } return null; } public <T> T asClass(Receiver receiver, Class<T> clazz) { try { return SingletonMessage.getInstance().convert(val, clazz); } catch (IOException e) { e.printStackTrace(); } return null; } }