<commit_before>/*
 * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensaml.xml.schema;

import org.opensaml.xml.util.DatatypeHelper;

/**
 * A class representing a boolean attribute. This class tracks the usage of the literals {true, false, 1, 0} to ensure
 * proper roundtripping when unmarshalling/marshalling.
 */
public class XSBooleanValue {

    /** Whether to use the numeric representation of the lexical one */
    private boolean numericRepresentation;

    /** Value of this boolean */
    private Boolean value;

    /**
     * Constructor. Uses lexical representation and sets value to null.
     */
    public XSBooleanValue() {
        numericRepresentation = false;
        value = null;
    }

    /**
     * Constructor
     * 
     * @param value the value
     * @param numericRepresentation whether to use a numeric or lexical representation
     */
    public XSBooleanValue(Boolean value, boolean numericRepresentation) {
        this.numericRepresentation = numericRepresentation;
        this.value = value;
    }

    /**
     * Gets the boolean value.
     * 
     * @return the boolean value
     */
    public Boolean getValue() {
        return value;
    }

    /**
     * Sets the boolean value.
     * 
     * @param value the boolean value
     */
    public void setValue(Boolean value) {
        this.value = value;
    }

    /**
     * Gets whether to use the numeric or lexical representation.
     * 
     * @return whether to use the numeric or lexical representation
     */
    public boolean isNumericRepresentation() {
        return numericRepresentation;
    }

    /**
     * Sets whether to use the numeric or lexical representation.
     * 
     * @param numericRepresentation whether to use the numeric or lexical representation
     */
    public void setNumericRepresentation(boolean numericRepresentation) {
        this.numericRepresentation = numericRepresentation;
    }

    /**
     * Converts this to a string. See {@link #toString(Boolean, boolean)}.
     */
    public String toString() {
        return toString(value, numericRepresentation);
    }

    /**
     * Converts a boolean value into a string. If using the numeric representations and the value is true then "1" is
     * returned or "0" if the value is false. If lexical representation is used "true" and "false" will be returned. If
     * the given value is null, then "false" is returned.<commit_msg>Implement hashCode and equals methods<commit_after>/*
 * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opensaml.xml.schema;

import org.opensaml.xml.util.DatatypeHelper;

/**
 * A class representing a boolean attribute. This class tracks the usage of the literals {true, false, 1, 0} to ensure
 * proper roundtripping when unmarshalling/marshalling.
 */
public class XSBooleanValue {

    /** Whether to use the numeric representation of the lexical one */
    private boolean numericRepresentation;

    /** Value of this boolean */
    private Boolean value;

    /**
     * Constructor. Uses lexical representation and sets value to null.
     */
    public XSBooleanValue() {
        numericRepresentation = false;
        value = null;
    }

    /**
     * Constructor
     * 
     * @param value the value
     * @param numericRepresentation whether to use a numeric or lexical representation
     */
    public XSBooleanValue(Boolean value, boolean numericRepresentation) {
        this.numericRepresentation = numericRepresentation;
        this.value = value;
    }

    /**
     * Gets the boolean value.
     * 
     * @return the boolean value
     */
    public Boolean getValue() {
        return value;
    }

    /**
     * Sets the boolean value.
     * 
     * @param value the boolean value
     */
    public void setValue(Boolean value) {
        this.value = value;
    }

    /**
     * Gets whether to use the numeric or lexical representation.
     * 
     * @return whether to use the numeric or lexical representation
     */
    public boolean isNumericRepresentation() {
        return numericRepresentation;
    }

    /**
     * Sets whether to use the numeric or lexical representation.
     * 
     * @param numericRepresentation whether to use the numeric or lexical representation
     */
    public void setNumericRepresentation(boolean numericRepresentation) {
        this.numericRepresentation = numericRepresentation;
    }
    
    /** {@inheritDoc} */
    public int hashCode(){
        if(numericRepresentation){
            if(value == null){
                return 0;
            }else if(value.booleanValue()){
                return 1;
            }else {
                return 3;
            }
        }else{
            if(value == null){
                return 4;
            }else if(value.booleanValue()){
                return 5;
            }else {
                return 6;
            }
        }
    }
    
    /** {@inheritDoc} */
    public boolean equals(Object obj){
        if(obj == null){
            return false;
        }
        
        if(obj instanceof XSBooleanValue){
            XSBooleanValue otherValue = (XSBooleanValue) obj;
            return hashCode() == otherValue.hashCode();
        }
        
        return false;
    }

    /**
     * Converts this to a string. See {@link #toString(Boolean, boolean)}.
     */
    public String toString() {
        return toString(value, numericRepresentation);
    }

    /**
     * Converts a boolean value into a string. If using the numeric representations and the value is true then "1" is
     * returned or "0" if the value is false. If lexical representation is used "true" and "false" will be returned. If
     * the given value is null, then "false" is returned.
{'fraction_non_alphanumeric': 0.08011527377521614, 'fraction_numerical': 0.004322766570605188, 'mean_word_length': 2.4007839294463498, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '363598', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1722, 'n_words': 688}