package com.foreverwin.mesnac.common.util;

public class HandleUtil {
    public static final String BO_TOOL_GROUP = "ToolGroupBO:";
    public static final String BO_TOOL_NUMBER = "ToolNumberBO:";
    public static final String BO_STATUS = "StatusBO:";
    public static final String BO_SITE = "SiteBO:";
    public static final String BO_RESRCE = "ResourceBO:";
    public static final String BO_USER = "UserBO:";

    public static String buildToolGroupHandle(String site, String toolGroup)
    {
        return BO_TOOL_GROUP + site + "," + toolGroup;
    }

    public static String buildToolNumberHandle(String site, String toolNumber)
    {
        return BO_TOOL_NUMBER + site + "," + toolNumber;
    }

    public static String buildStatusHandle(String site, String status)
    {
        return BO_STATUS + site + "," + status;
    }

    public static String buildSiteHandle(String site)
    {
        return BO_SITE + site;
    }

    public static String buildUserHandle(String site, String userId)
    {
        return BO_USER + site + "," + userId;
    }

    public static String buildResourceHandle(String site, String resource)
    {
        return BO_RESRCE + site + "," + resource;
    }

    public static String getPart(String handle, int position)
    {
        String prefix = "";
        int index = StringUtil.toString(handle).indexOf(":");
        if (index > -1 ) prefix = StringUtil.toString(handle).substring(0, index+1);
        //----------------------------------------------------------------------------------------------------------------------------------
        String handleParts = handle.replace( prefix, "" );
        String[] parts = handleParts.split("," );
        //----------------------------------------------------------------------------------------------------------------------------------
        if (position >= parts.length ) {
            return "";
        } else {
            return parts[position];
        }
    }

    public static void main(String[] args) {

    }
}
