jp.co.acroquest.endosnipe.perfdoctor.rule.RulePreferenceUtil.java Source code

Java tutorial

Introduction

Here is the source code for jp.co.acroquest.endosnipe.perfdoctor.rule.RulePreferenceUtil.java

Source

/*******************************************************************************
 * ENdoSnipe 5.0 - (https://github.com/endosnipe)
 * 
 * The MIT License (MIT)
 * 
 * Copyright (c) 2012 Acroquest Technology Co.,Ltd.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 ******************************************************************************/
package jp.co.acroquest.endosnipe.perfdoctor.rule;

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

import jp.co.acroquest.endosnipe.perfdoctor.rule.def.RuleSetConfig;

import org.apache.commons.lang.StringUtils;

/**
 * Eclipse??
 * TODO ?
 * 
 * @author tanimoto
 *
 */
public class RulePreferenceUtil {
    /** ?ID????? */
    private static final String CONFIG_RULESET_IDS = "perfdoctor.ruleSetIds";

    /** ??????? */
    private static final String CONFIG_RULESET_NAME_PREFIX = "perfdoctor.ruleSetName_";

    /** ????????? */
    private static final String CONFIG_RULESET_FILE_PREFIX = "perfdoctor.ruleSetFile_";

    /** ?????? */
    private static final String CONFIG_ACTIVE_RULESET_ID = "perfdoctor.activeRuleSetId";

    private static Map<String, String> preferenceMap__ = new HashMap<String, String>();

    /**
     * ?(RuleSetConfig)??
     * @param ruleSetId ID
     * @return ?????????
     */
    public static RuleSetConfig loadRuleSet(final String ruleSetId) {
        String name = preferenceMap__.get(CONFIG_RULESET_NAME_PREFIX + ruleSetId);
        String fileName = preferenceMap__.get(CONFIG_RULESET_FILE_PREFIX + ruleSetId);

        RuleSetConfig config = new RuleSetConfig();
        config.setId(ruleSetId);
        config.setName(name);
        config.setFileName(fileName);

        return config;
    }

    /**
     * ???
     * @param config 
     */
    public static void saveRuleSet(final RuleSetConfig config) {
        String id = config.getId();

        preferenceMap__.put(CONFIG_RULESET_NAME_PREFIX + id, config.getName());
        preferenceMap__.put(CONFIG_RULESET_FILE_PREFIX + id, config.getFileName());
    }

    /**
     * ?ID??
     * @return ID????????0???
     */
    public static String[] loadRuleSetIds() {
        String ids = preferenceMap__.get(CONFIG_RULESET_IDS);

        if (ids == null || ids.length() == 0) {
            return new String[0];
        }

        String[] ruleIds = StringUtils.split(ids, ",");
        return ruleIds;
    }

    /**
     * ?ID??
     * @param ruleSetIds ID
     */
    public static void saveRuleSetIds(final String[] ruleSetIds) {
        String ruleIds = StringUtils.join(ruleSetIds, ",");
        preferenceMap__.put(CONFIG_RULESET_IDS, ruleIds);
    }

    /**
     * ??ID??
     * @return ID?????????
     */
    public static String loadActiveRuleSetId() {
        String str = preferenceMap__.get(CONFIG_ACTIVE_RULESET_ID);

        return str;
    }

    /**
     * ??ID??
     * @param ruleSetId ID
     */
    public static void saveActiveRuleSetId(final String ruleSetId) {
        preferenceMap__.put(CONFIG_ACTIVE_RULESET_ID, ruleSetId);
    }

    private RulePreferenceUtil() {
        // Do Nothing.
    }
}