<commit_before>/*
 * Copyright ©1998-2021 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.attribute;

import com.trollworks.gcs.character.GURPSCharacter;
import com.trollworks.gcs.expression.EvaluationException;
import com.trollworks.gcs.expression.Evaluator;
import com.trollworks.gcs.expression.VariableResolver;
import com.trollworks.gcs.utility.I18n;
import com.trollworks.gcs.utility.ID;
import com.trollworks.gcs.utility.Log;
import com.trollworks.gcs.utility.json.JsonArray;
import com.trollworks.gcs.utility.json.JsonMap;
import com.trollworks.gcs.utility.json.JsonWriter;
import com.trollworks.gcs.utility.text.Enums;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class AttributeDef implements Cloneable, Comparable<AttributeDef> {
    private static final String KEY_ID                      = "id";
    private static final String KEY_TYPE                    = "type";
    private static final String KEY_SHORT_NAME              = "name";
    private static final String KEY_FULL_NAME               = "full_name";
    private static final String KEY_ATTRIBUTE_BASE          = "attribute_base";
    private static final String KEY_COST_PER_POINT          = "cost_per_point";
    private static final String KEY_COST_ADJ_PERCENT_PER_SM = "cost_adj_percent_per_sm";
    private static final String KEY_THRESHOLDS              = "thresholds";

    public static final Set<String> RESERVED = new HashSet<>();

    private String              mID;
    private AttributeType       mType;
    private String              mName;
    private String              mFullName;
    private String              mAttributeBase;
    private int                 mOrder;
    private int                 mCostPerPoint;
    private int                 mCostAdjPercentPerSM;
    private List<PoolThreshold> mThresholds;

    static {
        RESERVED.add("skill");
        RESERVED.add("parry");
        RESERVED.add("block");
        RESERVED.add("dodge");
        RESERVED.add("sm");
    }

    public static final Map<String, AttributeDef> cloneMap(Map<String, AttributeDef> m) {
        Map<String, AttributeDef> result = new HashMap<>();
        for (AttributeDef def : m.values()) {
            result.put(def.getID(), def.clone());
        }
        return result;
    }

    public static final Map<String, AttributeDef> load(JsonArray a) {
        Map<String, AttributeDef> m      = new HashMap<>();
        int                       length = a.size();
        for (int i = 0; i < length; i++) {
            AttributeDef def = new AttributeDef(a.getMap(i), i);
            m.put(def.getID(), def);
        }
        return m;
    }

    public static final List<AttributeDef> getOrdered(Map<String, AttributeDef> m) {
        List<AttributeDef> ordered = new ArrayList<>(m.values());
        Collections.sort(ordered);
        return ordered;
    }

    public static final void writeOrdered(JsonWriter w, Map<String, AttributeDef> m) throws IOException {
        w.startArray();
        for (AttributeDef def : getOrdered(m)) {
            def.toJSON(w);
        }
        w.endArray();
    }

    public static final Map<String, AttributeDef> createStandardAttributes() {
        Map<String, AttributeDef> m = new HashMap<>();<commit_msg>Make order values on load 1-based<commit_after>/*
 * Copyright ©1998-2021 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.attribute;

import com.trollworks.gcs.character.GURPSCharacter;
import com.trollworks.gcs.expression.EvaluationException;
import com.trollworks.gcs.expression.Evaluator;
import com.trollworks.gcs.expression.VariableResolver;
import com.trollworks.gcs.utility.I18n;
import com.trollworks.gcs.utility.ID;
import com.trollworks.gcs.utility.Log;
import com.trollworks.gcs.utility.json.JsonArray;
import com.trollworks.gcs.utility.json.JsonMap;
import com.trollworks.gcs.utility.json.JsonWriter;
import com.trollworks.gcs.utility.text.Enums;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class AttributeDef implements Cloneable, Comparable<AttributeDef> {
    private static final String KEY_ID                      = "id";
    private static final String KEY_TYPE                    = "type";
    private static final String KEY_SHORT_NAME              = "name";
    private static final String KEY_FULL_NAME               = "full_name";
    private static final String KEY_ATTRIBUTE_BASE          = "attribute_base";
    private static final String KEY_COST_PER_POINT          = "cost_per_point";
    private static final String KEY_COST_ADJ_PERCENT_PER_SM = "cost_adj_percent_per_sm";
    private static final String KEY_THRESHOLDS              = "thresholds";

    public static final Set<String> RESERVED = new HashSet<>();

    private String              mID;
    private AttributeType       mType;
    private String              mName;
    private String              mFullName;
    private String              mAttributeBase;
    private int                 mOrder;
    private int                 mCostPerPoint;
    private int                 mCostAdjPercentPerSM;
    private List<PoolThreshold> mThresholds;

    static {
        RESERVED.add("skill");
        RESERVED.add("parry");
        RESERVED.add("block");
        RESERVED.add("dodge");
        RESERVED.add("sm");
    }

    public static final Map<String, AttributeDef> cloneMap(Map<String, AttributeDef> m) {
        Map<String, AttributeDef> result = new HashMap<>();
        for (AttributeDef def : m.values()) {
            result.put(def.getID(), def.clone());
        }
        return result;
    }

    public static final Map<String, AttributeDef> load(JsonArray a) {
        Map<String, AttributeDef> m      = new HashMap<>();
        int                       length = a.size();
        for (int i = 0; i < length; i++) {
            AttributeDef def = new AttributeDef(a.getMap(i), i + 1);
            m.put(def.getID(), def);
        }
        return m;
    }

    public static final List<AttributeDef> getOrdered(Map<String, AttributeDef> m) {
        List<AttributeDef> ordered = new ArrayList<>(m.values());
        Collections.sort(ordered);
        return ordered;
    }

    public static final void writeOrdered(JsonWriter w, Map<String, AttributeDef> m) throws IOException {
        w.startArray();
        for (AttributeDef def : getOrdered(m)) {
            def.toJSON(w);
        }
        w.endArray();
    }

    public static final Map<String, AttributeDef> createStandardAttributes() {
        Map<String, AttributeDef> m = new HashMap<>();
{'fraction_non_alphanumeric': 0.09797208322359757, 'fraction_numerical': 0.00474058467210956, 'mean_word_length': 2.663772310660878, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '533902', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2165, 'n_words': 587}