ToiletInfo.java 3.68 KB
Newer Older
Kim Jinsung committed
1 2 3 4 5 6
package jp.odakyu.toiletsignage.info;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

7
import jp.odakyu.toiletsignage.constants.ToiletConstants;
Kim Jinsung committed
8
import jp.odakyu.toiletsignage.json.ResultToiletJson;
9
import jp.odakyu.toiletsignage.json.USBToiletDefaultJson;
Kim Jinsung committed
10 11 12 13 14 15

/**
 * Created by agentec on 2017/12/11.
 */

public class ToiletInfo {
16
    private static ToiletInfo instance = null;
Kim Jinsung committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30

    public static final String NAME_CONNTENT_FINISH = "jp.odakyu.toiletsignage.CONNECT_FINISH";
    public static final int VALUE_SEX_MAN = 0;
    public static final int VALUE_SEX_WOMAN = 1;

    public static final int VALUE_PRIORITY_MAIN = 0;
    public static final int VALUE_PRIORITY_SUB_LEFT = 1;
    public static final int VALUE_PRIORITY_SUB_RIGHT = 2;

    public static final int VALUE_DEFAULT_TOILET_NULL = 0;
    public static final int VALUE_DEFAULT_TOILET_VALIDATION_FAIL = 1;
    public static final int VALUE_NETWORK_DIS_CONNECT = 2;
    public static final int VALUE_TOILET_SERVER_CONNECT_FAIL = 3;

31
    public static final int MAX_ERROR_COUNT = 5;
Kim Jinsung committed
32

33 34
    private ArrayList<USBToiletDefaultJson> mToiletDefaultJsonArray;
    private Map<Integer, ArrayList<ResultToiletJson>> mResultToiletJsonMap = new HashMap<>();
35
    private boolean isUsbFileCopyComplete = false;
Kim Jinsung committed
36 37 38 39 40 41 42 43

    public static synchronized ToiletInfo getInstance() {
        if (instance == null) {
            instance = new ToiletInfo();
        }
        return instance;
    }

44
    public void setToiletDefaultJsonArray(ArrayList<USBToiletDefaultJson> defaultToiletJsonArray) {
Kim Jinsung committed
45 46 47
        mToiletDefaultJsonArray = defaultToiletJsonArray;
    }

48
    public ArrayList<USBToiletDefaultJson> getToiletDefaultJsonArray() {
Kim Jinsung committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        return mToiletDefaultJsonArray;
    }

    public void setResultToiletJsonMap(int toiletId, ArrayList<ResultToiletJson> resultToiletJsonMap) {
        mResultToiletJsonMap.put(toiletId, resultToiletJsonMap);
    }

    public ArrayList<ResultToiletJson> getResultToiletJsonMap(int toiletId) {
        return mResultToiletJsonMap.get(toiletId);
    }

    public int getResultToiletJsonMapSize() {
        return mResultToiletJsonMap.size();
    }

    public void clearResultToiletJsonMap() {
        mResultToiletJsonMap.clear();
    }

    public int getToiletSex() {
        if (mToiletDefaultJsonArray != null && mToiletDefaultJsonArray.size() > 0) {
70
            USBToiletDefaultJson toiletDefaultJson = mToiletDefaultJsonArray.get(0);
Kim Jinsung committed
71 72 73 74 75 76
            return toiletDefaultJson.getToiletSex();
        }
        return -1;
    }

    public int getVacantCount(int toiletId) {
77
        if (mResultToiletJsonMap.size() > 0) {
Kim Jinsung committed
78 79 80 81 82 83 84 85 86 87 88 89 90
            ArrayList<ResultToiletJson> resultToiletJsonArray = getResultToiletJsonMap(toiletId);
            int vacantCount = 0;
            for (ResultToiletJson resultToiletJson:resultToiletJsonArray) {
                if (resultToiletJson.getStatus().equals(ResultToiletJson.VALUE_STATUS_OPEN)) {
                    vacantCount++;
                }
            }
            return vacantCount;
        }
        return -1;
    }

    public int getTotalCount(int toiletId) {
91
        if (mResultToiletJsonMap.size() > 0) {
Kim Jinsung committed
92 93 94
            ArrayList<ResultToiletJson> resultToiletJsonArray = getResultToiletJsonMap(toiletId);
            return resultToiletJsonArray.size();
        }
95
        return -1;
Kim Jinsung committed
96 97 98 99 100 101 102 103 104 105
    }

    public void setUsbFileCopyComplete(boolean usbFileCopyComplete) {
        isUsbFileCopyComplete = usbFileCopyComplete;
    }

    public boolean getUsbFileCopyComplete() {
        return isUsbFileCopyComplete;
    }

106 107 108 109 110 111
    public int getToiletGateType() {
        if (mToiletDefaultJsonArray == null) {
            return ToiletConstants.VALUE_TOILET_GATE_TYPE_0;
        }
        return mToiletDefaultJsonArray.size();
    }
Kim Jinsung committed
112
}