<commit_before>package com.xpn.xwiki.objects.classes;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.StringProperty;
import com.xpn.xwiki.objects.meta.PropertyMetaClass;
import com.xpn.xwiki.web.XWikiRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.ecs.xhtml.input;
import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;
import org.dom4j.Element;

import java.util.*;

public class LevelsClass extends ListClass {
    public LevelsClass(PropertyMetaClass wclass) {
        super("levelslist", "Levels List", wclass);
        setSize(6);
    }

    public LevelsClass() {
        this(null);
    }

    public List getList(XWikiContext context) {
        List list;
        try {
            list = context.getWiki().getRightService().listAllLevels(context);
        } catch (XWikiException e) {
            // TODO add log exception
            list = new ArrayList();
        }

        XWikiRequest req = context.getRequest();
        if (("editrights".equals(req.get("xpage")) || "rights".equals(req.get("editor")))
		&&(!"1".equals(req.get("global")))) {
            list.remove("admin");
            list.remove("programming");
            list.remove("delete");
            list.remove("register");
        }
        return list;
    }

    public Map getMap(XWikiContext context) {
        return new HashMap();
    }

    public BaseProperty newProperty() {
        return new StringProperty();
    }

    public BaseProperty fromString(String value) {
        BaseProperty prop = newProperty();
        prop.setValue(value);
        return prop;
    }

    public BaseProperty fromStringArray(String[] strings) {
        List list = new ArrayList();
        for (int i = 0; i < strings.length; i++) {
            if (!strings[i].trim().equals("")) {
                list.add(strings[i]);
            }
        }
        BaseProperty prop = newProperty();
        prop.setValue(StringUtils.join(list.toArray(), ","));
        return prop;
    }

    public String getText(String value, XWikiContext context) {
        return value;
    }

    public static List getListFromString(String value) {
        List list = new ArrayList();
        if (value == null)
            return list;

        String val = StringUtils.replace(value, "\\,", "%SEP%");
        String[] result = StringUtils.split(val, ", ");
        for (int i = 0; i < result.length; i++)
            list.add(StringUtils.replace(result[i], "%SEP%", ","));
        return list;
    }

    public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
        select select = new select(prefix + name, 1);
        select.setMultiple(isMultiSelect());
        select.setSize(getSize());

        List list = getList(context);
        List selectlist;

        BaseProperty prop = (BaseProperty) object.safeget(name);
        if (prop == null) {
            selectlist = new ArrayList();
        } else {
            selectlist = getListFromString((String) prop.getValue());
        }

        // Add options from Set
        for (Iterator it = list.iterator(); it.hasNext();) {
            String value = it.next().toString();
            String display = getText(value, context);
            option option = new option(display, value);
            option.addElement(display);
            // If we don't have this option in the list then add it
            if (!list.contains(value))
                    list.add(value);
            if (selectlist.contains(value))
                option.setSelected(true);
            select.addElement(option);
        }

        buffer.append(select.toString());
        input in = new input();
        in.setType("hidden");
        in.setName(prefix + name);
        buffer.append(in.toString());
    }

    public BaseProperty newPropertyfromXML(Element ppcel) {
        String value = ppcel.getText();
        return fromString(value);
    }

}<commit_msg>[cleanup] Apply codestyle<commit_after>package com.xpn.xwiki.objects.classes;

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

import org.apache.commons.lang.StringUtils;
import org.apache.ecs.xhtml.input;
import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;
import org.dom4j.Element;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.StringProperty;
import com.xpn.xwiki.objects.meta.PropertyMetaClass;
import com.xpn.xwiki.web.XWikiRequest;

public class LevelsClass extends ListClass
{
    public LevelsClass(PropertyMetaClass wclass)
    {
        super("levelslist", "Levels List", wclass);
        setSize(6);
    }

    public LevelsClass()
    {
        this(null);
    }

    public List getList(XWikiContext context)
    {
        List list;
        try {
            list = context.getWiki().getRightService().listAllLevels(context);
        } catch (XWikiException e) {
            // TODO add log exception
            list = new ArrayList();
        }

        XWikiRequest req = context.getRequest();
        if (("editrights".equals(req.get("xpage")) || "rights".equals(req.get("editor")))
            && (!"1".equals(req.get("global")))) {
            list.remove("admin");
            list.remove("programming");
            list.remove("delete");
            list.remove("register");
        }
        return list;
    }

    public Map getMap(XWikiContext context)
    {
        return new HashMap();
    }

    public BaseProperty newProperty()
    {
        return new StringProperty();
    }

    public BaseProperty fromString(String value)
    {
        BaseProperty prop = newProperty();
        prop.setValue(value);
        return prop;
    }

    public BaseProperty fromStringArray(String[] strings)
    {
        List list = new ArrayList();
        for (int i = 0; i < strings.length; i++) {
            if (!strings[i].trim().equals("")) {
                list.add(strings[i]);
            }
        }
        BaseProperty prop = newProperty();
        prop.setValue(StringUtils.join(list.toArray(), ","));
        return prop;
    }

    public String getText(String value, XWikiContext context)
    {
        return value;
    }

    public static List getListFromString(String value)
    {
        List list = new ArrayList();
        if (value == null) {
            return list;
        }

        String val = StringUtils.replace(value, "\\,", "%SEP%");
        String[] result = StringUtils.split(val, ", ");
        for (int i = 0; i < result.length; i++) {
            list.add(StringUtils.replace(result[i], "%SEP%", ","));
        }
        return list;
    }

    public void displayEdit(StringBuffer buffer, String name, String prefix,
        BaseCollection object, XWikiContext context)
    {
        select select = new select(prefix + name, 1);
        select.setMultiple(isMultiSelect());
        select.setSize(getSize());

        List list = getList(context);
        List selectlist;

        BaseProperty prop = (BaseProperty) object.safeget(name);
        if (prop == null) {
            selectlist = new ArrayList();
        } else {
            selectlist = getListFromString((String) prop.getValue());
        }

        // Add options from Set
        for (Iterator it = list.iterator(); it.hasNext();) {
            String value = it.next().toString();
            String display = getText(value, context);
            option option = new option(display, value);
            option.addElement(display);
            // If we don't have this option in the list then add it
            if (!list.contains(value)) {
                list.add(value);
            }
            if (selectlist.contains(value)) {
                option.setSelected(true);
            }
            select.addElement(option);
        }

        buffer.append(select.toString());
        input in = new input();
        in.setType("hidden");
        in.setName(prefix + name);
        buffer.append(in.toString());
    }

    public BaseProperty newPropertyfromXML(Element ppcel)
    {
        String value = ppcel.getText();
        return fromString(value);
    }
}
{'fraction_non_alphanumeric': 0.12560672428080977, 'fraction_numerical': 0.0014206227062862555, 'mean_word_length': 2.2367816091954023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '260073', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2343, 'n_words': 532}