All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.openservices.eas.predict.response.BladeResponse Maven / Gradle / Ivy

package com.aliyun.openservices.eas.predict.response;

import com.aliyun.openservices.eas.predict.proto.BladeProtos.Response;
import shade.blade.protobuf.ByteString;
import shade.blade.protobuf.InvalidProtocolBufferException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;

public class BladeResponse {
    private static Log log = LogFactory.getLog(BladeResponse.class);
    private Response response = null;

    public void setContentValues(byte[] content) {
        try {
            response = Response.parseFrom(content);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    public List getShapeByNameInDlModel(String nameInDlModel) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getNameInDlModel().equals(nameInDlModel)) {
                    return response.getOutputs(i).getShape().getDimList();
                }
            }
            log.error("request failed: can't get response by NameInDlModel " + nameInDlModel);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response by NameInDlModel " + nameInDlModel);
            return new ArrayList();
        }
    }

    public List getShapeByBladeBlobName(String bladeBlobName) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getBladeBlobName().equals(bladeBlobName)) {
                    return response.getOutputs(i).getShape().getDimList();
                }
            }
            log.error("request failed: can't get response by BladeBlobName " + bladeBlobName);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response by BladeBlobName " + bladeBlobName);
            return new ArrayList();
        }
    }

    public List getFloatValsByNameInDlModel(String nameInDlModel) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getNameInDlModel().equals(nameInDlModel)) {
                    return response.getOutputs(i).getFloatValList();
                }
            }
            log.error("Not Found output name : " + nameInDlModel);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getFloatValsByBladeBlobName(String bladeBlobName) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getBladeBlobName().equals(bladeBlobName)) {
                    return response.getOutputs(i).getFloatValList();
                }
            }
            log.error("Not Found output name : " + bladeBlobName);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getInt32ValsByNameInDlModel(String nameInDlModel) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getNameInDlModel().equals(nameInDlModel)) {
                    return response.getOutputs(i).getIntValList();
                }
            }
            log.error("Not Found output name : " + nameInDlModel);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getInt32ValsByBladeBlobName(String bladeBlobName) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getBladeBlobName().equals(bladeBlobName)) {
                    return response.getOutputs(i).getIntValList();
                }
            }
            log.error("Not Found output name : " + bladeBlobName);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getInt64ValsByNameInDlModel(String nameInDlModel) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getNameInDlModel().equals(nameInDlModel)) {
                    return response.getOutputs(i).getInt64ValList();
                }
            }
            log.error("Not Found output name : " + nameInDlModel);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getInt64ValsByBladeBlobName(String bladeBlobName) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getBladeBlobName().equals(bladeBlobName)) {
                    return response.getOutputs(i).getInt64ValList();
                }
            }
            log.error("Not Found output name : " + bladeBlobName);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getStringValsByNameInDlModel(String nameInDlModel) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getNameInDlModel().equals(nameInDlModel)) {
                    List res = response.getOutputs(i).getStringValList();
                    List result = new ArrayList();
                    for (int j = 0; j < res.size(); j++) {
                        result.add(res.get(j).toStringUtf8());
                    }
                    return result;
                }
            }
            log.error("Not Found output with NameInDlModel: " + nameInDlModel);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

    public List getStringValsByBladeBlobName(String bladeBlobName) {
        if (response != null) {
            for (int i = 0; i < response.getOutputsCount(); ++i) {
                if (response.getOutputs(i).getBladeBlobName().equals(bladeBlobName)) {
                    List res = response.getOutputs(i).getStringValList();
                    List result = new ArrayList();
                    for (int j = 0; j < res.size(); j++) {
                        result.add(res.get(j).toStringUtf8());
                    }
                    return result;
                }
            }
            log.error("Not Found output with BladeBlobName: " + bladeBlobName);
            return new ArrayList();
        } else {
            log.error("request failed: can't get response");
            return new ArrayList();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy