view src/main/java/alice/datasegment/ReceiveRemoteData.java @ 419:aefbe41fcf12 dispose

change tab to space
author sugi
date Tue, 15 Jul 2014 16:00:22 +0900
parents 8f71c3e6f11d
children 2f2623484b77
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() {
        if (val.getType() == ValueType.RAW) {
            return val.asRawValue().getString();
        }
        return null;
    }

    public int asInteger() {
        if (val.getType() == ValueType.INTEGER) {
            return val.asIntegerValue().getInt();
        }
        return 0;
    }

    public Float asFloat() {
        if (val.getType() == ValueType.FLOAT) {
            return val.asFloatValue().getFloat();
        }
        return 0.0f;
    }

    public ArrayValue asArray(){
        if (val.getType() == ValueType.ARRAY){
            return val.asArrayValue();
        }
        return null;
    }

    public <T> T asClass(Class<T> clazz) {
        try {
            return SingletonMessage.getInstance().convert(val, clazz);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public Value getVal() {
        return val;
    }

    @Override
    public Object getObj() {
        return val;
    }

}