<commit_before>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.objects.classes;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.ecs.xhtml.div;
import org.apache.ecs.xhtml.input;
import org.apache.ecs.xhtml.label;
import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.IntegerProperty;
import com.xpn.xwiki.objects.meta.PropertyMetaClass;
import com.xpn.xwiki.web.XWikiMessageTool;

public class BooleanClass extends PropertyClass
{
    /** Other string values that might be used to represent "true" values. */
    private static final Pattern TRUE_PATTERN = Pattern.compile("yes|true", Pattern.CASE_INSENSITIVE);

    /** Other string values that might be used to represent "false" values. */
    private static final Pattern FALSE_PATTERN = Pattern.compile("no|false", Pattern.CASE_INSENSITIVE);

    public BooleanClass(PropertyMetaClass wclass)
    {
        super("boolean", "Boolean", wclass);
    }

    public BooleanClass()
    {
        this(null);
        setDisplayFormType("select");
    }

    public void setDisplayType(String type)
    {
        setStringValue("displayType", type);
    }

    public String getDisplayType()
    {
        String dtype = getStringValue("displayType");
        if ((dtype == null) || (dtype.equals(""))) {
            return "yesno";
        }
        return dtype;
    }

    public String getDisplayFormType()
    {
        String dtype = getStringValue("displayFormType");
        if ((dtype == null) || (dtype.equals(""))) {
            return "radio";
        }
        return dtype;
    }

    public void setDisplayFormType(String type)
    {
        setStringValue("displayFormType", type);
    }

    public void setDefaultValue(int dvalue)
    {
        setIntValue("defaultValue", dvalue);
    }

    public int getDefaultValue()
    {
        return getIntValue("defaultValue", -1);
    }

    @Override
    public BaseProperty fromString(String value)
    {
        BaseProperty property = newProperty();
        Number nvalue = null;
        if (StringUtils.isNotEmpty(value)) {
            if (StringUtils.isNumeric(value)) {
                nvalue = new Integer(value);
            } else if (TRUE_PATTERN.matcher(value).matches()) {
                nvalue = Integer.valueOf(1);
            } else if (FALSE_PATTERN.matcher(value).matches()) {
                nvalue = Integer.valueOf(0);
            }
        }
        if (nvalue == null) {
            // Returning null makes sure that the old value (if one exists) will not be discarded/replaced
            return null;
        }
        property.setValue(nvalue);
        return property;
    }

    @Override
    public BaseProperty newProperty()
    {
        BaseProperty property = new IntegerProperty();
        property.setName(getName());
        return property;
    }

    @Override
    public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context)
    {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        if (prop == null) {
            return;
        }

        Integer iValue = (Integer) prop.getValue();
        if (iValue != null) {
            int value = iValue.intValue();
            buffer.append(getDisplayValue(context, value));
        }
    }

    @Override<commit_msg>Attempting to fix the build.<commit_after>/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.objects.classes;

import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.ecs.xhtml.div;
import org.apache.ecs.xhtml.input;
import org.apache.ecs.xhtml.label;
import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.objects.BaseCollection;
import com.xpn.xwiki.objects.BaseProperty;
import com.xpn.xwiki.objects.IntegerProperty;
import com.xpn.xwiki.objects.meta.PropertyMetaClass;
import com.xpn.xwiki.web.XWikiMessageTool;

public class BooleanClass extends PropertyClass
{
    /** Other string values that might be used to represent "true" values. */
    private static final Pattern TRUE_PATTERN = Pattern.compile("yes|true", Pattern.CASE_INSENSITIVE);

    /** Other string values that might be used to represent "false" values. */
    private static final Pattern FALSE_PATTERN = Pattern.compile("no|false", Pattern.CASE_INSENSITIVE);

    public BooleanClass(PropertyMetaClass wclass)
    {
        super("boolean", "Boolean", wclass);
    }

    public BooleanClass()
    {
        this(null);
        setDisplayFormType("select");
    }

    public void setDisplayType(String type)
    {
        setStringValue("displayType", type);
    }

    public String getDisplayType()
    {
        String dtype = getStringValue("displayType");
        if ((dtype == null) || (dtype.equals(""))) {
            return "yesno";
        }
        return dtype;
    }

    public String getDisplayFormType()
    {
        String dtype = getStringValue("displayFormType");
        if ((dtype == null) || (dtype.equals(""))) {
            return "radio";
        }
        return dtype;
    }

    public void setDisplayFormType(String type)
    {
        setStringValue("displayFormType", type);
    }

    public void setDefaultValue(int dvalue)
    {
        setIntValue("defaultValue", dvalue);
    }

    public int getDefaultValue()
    {
        return getIntValue("defaultValue", -1);
    }

    @Override
    public BaseProperty fromString(String value)
    {
        BaseProperty property = newProperty();
        Number nvalue = null;
        if (StringUtils.isNotEmpty(value)) {
            if (StringUtils.isNumeric(value)) {
                nvalue = new Integer(value);
            } else if (TRUE_PATTERN.matcher(value).matches()) {
                nvalue = Integer.valueOf(1);
            } else if (FALSE_PATTERN.matcher(value).matches()) {
                nvalue = Integer.valueOf(0);
            }
        }
        property.setValue(nvalue);
        return property;
    }

    @Override
    public BaseProperty newProperty()
    {
        BaseProperty property = new IntegerProperty();
        property.setName(getName());
        return property;
    }

    @Override
    public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context)
    {
        IntegerProperty prop = (IntegerProperty) object.safeget(name);
        if (prop == null) {
            return;
        }

        Integer iValue = (Integer) prop.getValue();
        if (iValue != null) {
            int value = iValue.intValue();
            buffer.append(getDisplayValue(context, value));
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.09838541061679637, 'fraction_numerical': 0.003949355325821815, 'mean_word_length': 2.7386018237082066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5331081', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2323, 'n_words': 709}