com.port.ocean.shipping.data.VehicleInfoData.java Source code

Java tutorial

Introduction

Here is the source code for com.port.ocean.shipping.data.VehicleInfoData.java

Source

package com.port.ocean.shipping.data;
/**
 * Created by  on 2016/3/31.
 */

import com.port.ocean.shipping.bean.Vehicle;

import org.json.JSONArray;
import org.json.JSONObject;
import org.mobile.library.model.data.base.SimpleJsonDataModel;

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

/**
 * ???
 *
 * @author 
 * @version 1.0 2016/3/31
 * @since 1.0
 */
public class VehicleInfoData extends SimpleJsonDataModel {

    /**
     * id
     */
    private String userId = null;

    /**
     * id
     */
    private String vehicleId = null;

    /**
     * ?
     */
    private String licensePlateNumber = null;

    /**
     * ??
     */
    private List<Vehicle> dataList = null;

    /**
     * ??
     */
    private Vehicle data = null;

    /**
     * id
     *
     * @param userId id
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }

    /**
     * id
     *
     * @param vehicleId id
     */
    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }

    /**
     * ?
     *
     * @param licensePlateNumber ?
     */
    public void setLicensePlateNumber(String licensePlateNumber) {
        this.licensePlateNumber = licensePlateNumber;
    }

    /**
     * ???
     *
     * @return ?
     */
    public List<Vehicle> getDataList() {
        return dataList;
    }

    /**
     * ???
     *
     * @return ?
     */
    public Vehicle getData() {
        return data;
    }

    @Override
    protected void onExtractData(JSONObject jsonData) throws Exception {
        if (licensePlateNumber != null) {
            // ??

            JSONArray jsonArray = jsonData.getJSONArray(DATA_TAG);
            if (jsonArray.length() > 2) {
                data = new Vehicle();
                data.setId(jsonArray.getString(0));
                data.setLicensePlateNumber(jsonArray.getString(1));
                data.setAddTime(jsonArray.getString(2));
            }
        } else {
            // ????
            JSONArray jsonArray = jsonData.getJSONArray(DATA_TAG);
            dataList = new ArrayList<>();

            for (int i = 0; i < jsonArray.length(); i++) {
                JSONArray jsonRow = jsonArray.getJSONArray(i);
                if (jsonRow.length() > 2) {
                    data = new Vehicle();
                    data.setId(jsonRow.getString(0));
                    data.setLicensePlateNumber(jsonRow.getString(1));
                    data.setAddTime(jsonRow.getString(2));
                }
                dataList.add(data);
            }
        }
    }

    @Override
    protected void onFillRequestParameters(Map<String, String> dataMap) {
        dataMap.put("CodeUser", userId);
        dataMap.put("VehicleNum", licensePlateNumber);
        dataMap.put("Id", vehicleId);
    }
}