<commit_before>/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.parser.builder.impl;

import java.util.*;

import org.opendaylight.yangtools.yang.model.api.*;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;

public final class ConstraintsBuilder {
    private static final int HASH_IF_BOOL_TRUE = 1231;
    private static final int HASH_IF_BOOL_FALSE = 1237;

    private final String moduleName;
    private final int line;
    private final ConstraintDefinitionImpl instance;
    private final Set<MustDefinition> mustDefinitions;
    private RevisionAwareXPath whenStmt;
    private String whenCondition;
    private boolean mandatory;
    private Integer min;
    private Integer max;

    public ConstraintsBuilder(final String moduleName, final int line) {
        this.moduleName = moduleName;
        this.line = line;
        instance = new ConstraintDefinitionImpl();
        mustDefinitions = new HashSet<MustDefinition>();
    }

    ConstraintsBuilder(final ConstraintsBuilder b) {
        this.moduleName = b.getModuleName();
        this.line = b.getLine();
        instance = new ConstraintDefinitionImpl();
        mustDefinitions = new HashSet<MustDefinition>(b.getMustDefinitions());
        whenCondition = b.getWhenCondition();
        mandatory = b.isMandatory();
        min = b.getMinElements();
        max = b.getMaxElements();
    }

    ConstraintsBuilder(final String moduleName, final int line, final ConstraintDefinition base) {
        this.moduleName = moduleName;
        this.line = line;
        instance = new ConstraintDefinitionImpl();
        whenStmt = base.getWhenCondition();
        mustDefinitions = new HashSet<MustDefinition>(base.getMustConstraints());
        mandatory = base.isMandatory();
        min = base.getMinElements();
        max = base.getMaxElements();
    }

    public ConstraintDefinition build() {
        if (whenStmt == null) {
            if (whenCondition == null) {
                whenStmt = null;
            } else {
                whenStmt = new RevisionAwareXPathImpl(whenCondition, false);
            }
        }
        instance.setWhenCondition(whenStmt);
        instance.setMustConstraints(mustDefinitions);
        instance.setMandatory(mandatory);
        instance.setMinElements(min);
        instance.setMaxElements(max);
        return instance;
    }

    public String getModuleName() {
        return moduleName;
    }

    public int getLine() {
        return line;
    }

    public Integer getMinElements() {
        return min;
    }

    public void setMinElements(Integer minElements) {
        this.min = minElements;
    }

    public Integer getMaxElements() {
        return max;
    }

    public void setMaxElements(Integer maxElements) {
        this.max = maxElements;
    }

    public Set<MustDefinition> getMustDefinitions() {
        return mustDefinitions;
    }

    public void addMustDefinition(MustDefinition must) {
        mustDefinitions.add(must);
    }

    public String getWhenCondition() {
        return whenCondition;
    }

    public void addWhenCondition(String whenCondition) {
        this.whenCondition = whenCondition;
    }

    public boolean isMandatory() {
        return mandatory;
    }

    public void setMandatory(boolean mandatory) {
        this.mandatory = mandatory;
    }

    private final class ConstraintDefinitionImpl implements ConstraintDefinition {
        private RevisionAwareXPath whenCondition;
        private Set<MustDefinition> mustConstraints;
        private boolean mandatory;
        private Integer minElements;
        private Integer maxElements;

        @Override
        public RevisionAwareXPath getWhenCondition() {
            return whenCondition;
        }

        private void setWhenCondition(RevisionAwareXPath whenCondition) {
            this.whenCondition = whenCondition;
        }

        @Override
        public Set<MustDefinition> getMustConstraints() {
            if (mustConstraints == null) {
                return Collections.emptySet();
            } else {
                return mustConstraints;
            }
        }

        private void setMustConstraints(Set<MustDefinition> mustConstraints) {
            if (mustConstraints != null) {
                this.mustConstraints = mustConstraints;
            }
        }

        @Override
        public boolean isMandatory() {
            return mandatory;
        }

        private void setMandatory(boolean mandatory) {
            this.mandatory = mandatory;
        }

        @Override
        public Integer getMinElements() {
            return minElements;
        }

        private void setMinElements(Integer minElements) {
            this.minElements = minElements;
        }

        @Override
        public Integer getMaxElements() {
            return maxElements;
        }

        private void setMaxElements(Integer maxElements) {
            this.maxElements = maxElements;
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
            result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
            result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
            result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
            result = prime * result + (mandatory ? HASH_IF_BOOL_TRUE : HASH_IF_BOOL_FALSE);
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {<commit_msg>Memory hog: ConstraintDefinitionImpl should be static<commit_after>/*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.parser.builder.impl;

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

import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;

public final class ConstraintsBuilder {
    private static final int HASH_IF_BOOL_TRUE = 1231;
    private static final int HASH_IF_BOOL_FALSE = 1237;

    private final String moduleName;
    private final int line;
    private final ConstraintDefinitionImpl instance;
    private final Set<MustDefinition> mustDefinitions;
    private RevisionAwareXPath whenStmt;
    private String whenCondition;
    private boolean mandatory;
    private Integer min;
    private Integer max;

    public ConstraintsBuilder(final String moduleName, final int line) {
        this.moduleName = moduleName;
        this.line = line;
        instance = new ConstraintDefinitionImpl();
        mustDefinitions = new HashSet<MustDefinition>();
    }

    ConstraintsBuilder(final ConstraintsBuilder b) {
        this.moduleName = b.getModuleName();
        this.line = b.getLine();
        instance = new ConstraintDefinitionImpl();
        mustDefinitions = new HashSet<MustDefinition>(b.getMustDefinitions());
        whenCondition = b.getWhenCondition();
        mandatory = b.isMandatory();
        min = b.getMinElements();
        max = b.getMaxElements();
    }

    ConstraintsBuilder(final String moduleName, final int line, final ConstraintDefinition base) {
        this.moduleName = moduleName;
        this.line = line;
        instance = new ConstraintDefinitionImpl();
        whenStmt = base.getWhenCondition();
        mustDefinitions = new HashSet<MustDefinition>(base.getMustConstraints());
        mandatory = base.isMandatory();
        min = base.getMinElements();
        max = base.getMaxElements();
    }

    public ConstraintDefinition build() {
        if (whenStmt == null) {
            if (whenCondition == null) {
                whenStmt = null;
            } else {
                whenStmt = new RevisionAwareXPathImpl(whenCondition, false);
            }
        }
        instance.setWhenCondition(whenStmt);
        instance.setMustConstraints(mustDefinitions);
        instance.setMandatory(mandatory);
        instance.setMinElements(min);
        instance.setMaxElements(max);
        return instance;
    }

    public String getModuleName() {
        return moduleName;
    }

    public int getLine() {
        return line;
    }

    public Integer getMinElements() {
        return min;
    }

    public void setMinElements(final Integer minElements) {
        this.min = minElements;
    }

    public Integer getMaxElements() {
        return max;
    }

    public void setMaxElements(final Integer maxElements) {
        this.max = maxElements;
    }

    public Set<MustDefinition> getMustDefinitions() {
        return mustDefinitions;
    }

    public void addMustDefinition(final MustDefinition must) {
        mustDefinitions.add(must);
    }

    public String getWhenCondition() {
        return whenCondition;
    }

    public void addWhenCondition(final String whenCondition) {
        this.whenCondition = whenCondition;
    }

    public boolean isMandatory() {
        return mandatory;
    }

    public void setMandatory(final boolean mandatory) {
        this.mandatory = mandatory;
    }

    private static final class ConstraintDefinitionImpl implements ConstraintDefinition {
        private RevisionAwareXPath whenCondition;
        private Set<MustDefinition> mustConstraints;
        private boolean mandatory;
        private Integer minElements;
        private Integer maxElements;

        @Override
        public RevisionAwareXPath getWhenCondition() {
            return whenCondition;
        }

        private void setWhenCondition(final RevisionAwareXPath whenCondition) {
            this.whenCondition = whenCondition;
        }

        @Override
        public Set<MustDefinition> getMustConstraints() {
            if (mustConstraints == null) {
                return Collections.emptySet();
            } else {
                return mustConstraints;
            }
        }

        private void setMustConstraints(final Set<MustDefinition> mustConstraints) {
            if (mustConstraints != null) {
                this.mustConstraints = mustConstraints;
            }
        }

        @Override
        public boolean isMandatory() {
            return mandatory;
        }

        private void setMandatory(final boolean mandatory) {
            this.mandatory = mandatory;
        }

        @Override
        public Integer getMinElements() {
            return minElements;
        }

        private void setMinElements(final Integer minElements) {
            this.minElements = minElements;
        }

        @Override
        public Integer getMaxElements() {
            return maxElements;
        }

        private void setMaxElements(final Integer maxElements) {
            this.maxElements = maxElements;
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
            result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
            result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
            result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
            result = prime * result + (mandatory ? HASH_IF_BOOL_TRUE : HASH_IF_BOOL_FALSE);
            return result;
        }

        @Override
        public boolean equals(final Object obj) {
            if (this == obj) {
{'fraction_non_alphanumeric': 0.08044394037589112, 'fraction_numerical': 0.0037265068049254697, 'mean_word_length': 2.3840460526315788, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1470388', 'n_tokens_mistral': 3183, 'n_tokens_neox': 3043, 'n_words': 807}