<commit_before>/**
 *
 */
package org.verapdf.pdfa.validation;

import org.verapdf.pdfa.flavours.PDFAFlavour;

import javax.xml.bind.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import java.io.*;
import java.util.*;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@XmlRootElement(namespace = "http://www.verapdf.org/ValidationProfile", name = "profile")
final class ValidationProfileImpl implements ValidationProfile {
    private final static Map<PDFAFlavour, Map<String, Set<Rule>>> OBJECT_RULE_MAP = new HashMap<>();
    private final static Map<PDFAFlavour, Map<String, Set<Variable>>> OBJECT_VARIABLE_MAP = new HashMap<>();
    private final static Map<RuleId, Rule> RULE_LOOKUP = new HashMap<>();
    private final static ValidationProfileImpl DEFAULT = new ValidationProfileImpl();

    @XmlAttribute
    private final PDFAFlavour flavour;
    @XmlElement
    private final ProfileDetails details;
    @XmlElement
    private final String hash;
    @XmlElementWrapper
    @XmlElement(name = "rule")
    private final Set<Rule> rules;
    @XmlElementWrapper
    @XmlElement(name = "variable")
    private final Set<Variable> variables;

    private ValidationProfileImpl() {
        this(PDFAFlavour.NO_FLAVOUR, ProfileDetailsImpl.defaultInstance(),
                "hash", Collections.<Rule> emptySet(), Collections.<Variable> emptySet());
    }

    private ValidationProfileImpl(final PDFAFlavour flavour,
            final ProfileDetails details, final String hash,
            final Set<Rule> rules, final Set<Variable> variables) {
        super();
        this.flavour = flavour;
        this.details = details;
        this.hash = hash;
        this.rules = new HashSet<>(rules);
        this.variables = new HashSet<>(variables);
    }

    private ValidationProfileImpl(final PDFAFlavour flavour,
                                  final ProfileDetails details, final String hash,
                                  final SortedSet<Rule> rules, final Set<Variable> variables) {
        super();
        this.flavour = flavour;
        this.details = details;
        this.hash = hash;
        this.rules = rules;
        this.variables = new HashSet<>(variables);
    }

    /**
     * { @inheritDoc }
     */
    @Override
    public PDFAFlavour getPDFAFlavour() {
        return this.flavour;
    }

    /**
     * { @inheritDoc }
     */
    @Override
    public ProfileDetails getDetails() {
        return this.details;
    }<commit_msg>Fixed problem with rules caching<commit_after>/**
 *
 */
package org.verapdf.pdfa.validation;

import org.verapdf.pdfa.flavours.PDFAFlavour;

import javax.xml.bind.*;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import java.io.*;
import java.util.*;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
@XmlRootElement(namespace = "http://www.verapdf.org/ValidationProfile", name = "profile")
final class ValidationProfileImpl implements ValidationProfile {
    private final static Map<PDFAFlavour, Map<String, Set<Rule>>> OBJECT_RULE_MAP = new HashMap<>();
    private final static Map<PDFAFlavour, Map<String, Set<Variable>>> OBJECT_VARIABLE_MAP = new HashMap<>();
    private final static Map<RuleId, Rule> RULE_LOOKUP = new HashMap<>();
    private final static ValidationProfileImpl DEFAULT = new ValidationProfileImpl();

    @XmlAttribute
    private final PDFAFlavour flavour;
    @XmlElement
    private final ProfileDetails details;
    @XmlElement
    private final String hash;
    @XmlElementWrapper
    @XmlElement(name = "rule")
    private final Set<Rule> rules;
    @XmlElementWrapper
    @XmlElement(name = "variable")
    private final Set<Variable> variables;

    private ValidationProfileImpl() {
        this(PDFAFlavour.NO_FLAVOUR, ProfileDetailsImpl.defaultInstance(),
                "hash", Collections.<Rule> emptySet(), Collections.<Variable> emptySet());
    }

    private ValidationProfileImpl(final PDFAFlavour flavour,
            final ProfileDetails details, final String hash,
            final Set<Rule> rules, final Set<Variable> variables) {
        super();
        this.flavour = flavour;
        this.details = details;
        this.hash = hash;
        this.rules = new HashSet<>(rules);
        this.variables = new HashSet<>(variables);

        OBJECT_RULE_MAP.clear();
        OBJECT_VARIABLE_MAP.clear();
    }

    private ValidationProfileImpl(final PDFAFlavour flavour,
                                  final ProfileDetails details, final String hash,
                                  final SortedSet<Rule> rules, final Set<Variable> variables) {
        super();
        this.flavour = flavour;
        this.details = details;
        this.hash = hash;
        this.rules = rules;
        this.variables = new HashSet<>(variables);

        OBJECT_RULE_MAP.clear();
        OBJECT_VARIABLE_MAP.clear();
    }

    /**
     * { @inheritDoc }
     */
    @Override
    public PDFAFlavour getPDFAFlavour() {
        return this.flavour;
    }

    /**
     * { @inheritDoc }
     */
    @Override
    public ProfileDetails getDetails() {
        return this.details;
    }
{'fraction_non_alphanumeric': 0.10905240868184224, 'fraction_numerical': 0.0, 'mean_word_length': 3.0514653323802716, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6722340', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1547, 'n_words': 366}