<commit_before>package org.commcare.cases.instance;

import org.commcare.cases.model.StorageIndexedTreeElementModel;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.model.instance.TreeElement;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

/**
 * Tracks what attributes and elements are stored in indexed columns of an
 * indexed fixture db table.
 *
 * @author <NAME> (<EMAIL>)
 */
public class FixtureIndexSchema {
    private final Set<String> indices;
    public final String fixtureName;

    public FixtureIndexSchema(TreeElement schemaTree) {
        this.fixtureName = schemaTree.getAttributeValue(null, "id");

        indices = buildIndices(schemaTree.getChildrenWithName("index"));
    }

    private static Set<String> buildIndices(Vector<TreeElement> indexElements) {
        HashSet<String> indices = new HashSet<>();
        for (TreeElement index : indexElements) {
            IAnswerData value = index.getValue();
            if (value != null) {
                indices.add(value.uncast().getString());
            }
        }
        return indices;
    }

    /**
     * Break-up composite indices into individual ones and escape index names
     * to be SQL compatible
     */
    public Set<String> getColumnIndices() {
        Set<String> columnIndices = new HashSet<>();
        for (String index : indices) {
            columnIndices.add(escapeIndex(index));
        }
        return columnIndices;
    }

    private static String escapeIndex(String index) {
        if (index.contains(",")) {
            StringBuilder compoundIndex = new StringBuilder();
            String prefix = "";
            for (String entry : index.split(",")) {
                compoundIndex.append(prefix);
                prefix = ",";
                compoundIndex.append(StorageIndexedTreeElementModel.getColFromEntry(entry));
            }
            return compoundIndex.toString();
        } else {
            return StorageIndexedTreeElementModel.getColFromEntry(index);
        }<commit_msg>make static method a class method<commit_after>package org.commcare.cases.instance;

import org.commcare.cases.model.StorageIndexedTreeElementModel;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.core.model.instance.TreeElement;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

/**
 * Tracks what attributes and elements are stored in indexed columns of an
 * indexed fixture db table.
 *
 * @author <NAME> (<EMAIL>)
 */
public class FixtureIndexSchema {
    private final Set<String> indices = new HashSet<>();
    public final String fixtureName;

    public FixtureIndexSchema(TreeElement schemaTree) {
        this.fixtureName = schemaTree.getAttributeValue(null, "id");

        setupIndices(schemaTree.getChildrenWithName("index"));
    }

    private void setupIndices(Vector<TreeElement> indexElements) {
        for (TreeElement index : indexElements) {
            IAnswerData value = index.getValue();
            if (value != null) {
                indices.add(value.uncast().getString());
            }
        }
    }

    /**
     * Break-up composite indices into individual ones and escape index names
     * to be SQL compatible
     */
    public Set<String> getColumnIndices() {
        Set<String> columnIndices = new HashSet<>();
        for (String index : indices) {
            columnIndices.add(escapeIndex(index));
        }
        return columnIndices;
    }

    private static String escapeIndex(String index) {
        if (index.contains(",")) {
            StringBuilder compoundIndex = new StringBuilder();
            String prefix = "";
            for (String entry : index.split(",")) {
                compoundIndex.append(prefix);
                prefix = ",";
                compoundIndex.append(StorageIndexedTreeElementModel.getColFromEntry(entry));
            }
            return compoundIndex.toString();
        } else {
            return StorageIndexedTreeElementModel.getColFromEntry(index);
        }
{'fraction_non_alphanumeric': 0.10254545454545455, 'fraction_numerical': 0.0, 'mean_word_length': 2.6480990274093723, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2769183', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1060, 'n_words': 257}