<commit_before>package ch.difty.sipamato.entity.filter;

import ch.difty.sipamato.entity.IdSipamatoEntity;
import ch.difty.sipamato.lib.AssertAs;

/**
 * Implementations of {@link SearchTerm} accept a <code>fieldName</code> as key and a <code>rawSearchTerm</code> as value.
 * The rawSearchTerm holds a comparison specification holding a value and some meta information on how to compare the field
 * with the provided value.<p/>
 *
 * <b>Note:</b>Identity is based on <code>fieldName</code> and <code>rawSearchTerm</code> only, thus ignoring <code>id</code>
 *             or <code>searchConditionId</code>. This might be an issue in some use cases in the future!
 *
 * @author u.joss
 */
public abstract class SearchTerm<T extends SearchTerm<?>> extends IdSipamatoEntity<Long> {

    private static final long serialVersionUID = 1L;

    private final Long searchConditionId;
    private final SearchTermType searchTermType;
    private final String fieldName;
    private final String searchTerm;

    SearchTerm(final SearchTermType type, final String fieldName, final String rawSearchTerm) {
        this(null, type, null, fieldName, rawSearchTerm);
    }

    SearchTerm(final Long id, final SearchTermType type, final Long searchConditionId, final String fieldName, final String rawSearchTerm) {
        super(id);
        this.searchConditionId = searchConditionId;
        this.searchTermType = AssertAs.notNull(type);
        this.fieldName = AssertAs.notNull(fieldName, "fieldName");
        this.searchTerm = AssertAs.notNull(rawSearchTerm, "rawSearchTerm");
    }

    public static SearchTerm<?> of(final long id, final int searchTermTypeId, final long searchConditionId, final String fieldName, final String rawSearchTerm) {
        SearchTermType type = SearchTermType.byId(searchTermTypeId);
        switch (type) {
        case BOOLEAN:
            return new BooleanSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case INTEGER:
            return new IntegerSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case STRING:
            return new StringSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case AUDIT:
            return new AuditSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        default:
            throw new UnsupportedOperationException("SearchTermType." + type + " is not supported");
        }
    }

    public SearchTermType getSearchTermType() {
        return searchTermType;
    }

    public Long getSearchConditionId() {
        return searchConditionId;
    }

    public String getFieldName() {
        return fieldName;
    }

    public String getRawSearchTerm() {
        return searchTerm;
    }

    @Override
    public String getDisplayValue() {
        return searchTerm;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + fieldName.hashCode();
        result = prime * result + searchTerm.hashCode();
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        @SuppressWarnings("unchecked")
        final T other = (T) obj;
        if (fieldName.hashCode() != other.getFieldName().hashCode())
            return false;
        if (!searchTerm.equals(other.getRawSearchTerm()))
            return false;
        return true;
    }

}<commit_msg>Rename variable<commit_after>package ch.difty.sipamato.entity.filter;

import ch.difty.sipamato.entity.IdSipamatoEntity;
import ch.difty.sipamato.lib.AssertAs;

/**
 * Implementations of {@link SearchTerm} accept a <code>fieldName</code> as key and a <code>rawSearchTerm</code> as value.
 * The rawSearchTerm holds a comparison specification holding a value and some meta information on how to compare the field
 * with the provided value.<p/>
 *
 * <b>Note:</b>Identity is based on <code>fieldName</code> and <code>rawSearchTerm</code> only, thus ignoring <code>id</code>
 *             or <code>searchConditionId</code>. This might be an issue in some use cases in the future!
 *
 * @author u.joss
 */
public abstract class SearchTerm<T extends SearchTerm<?>> extends IdSipamatoEntity<Long> {

    private static final long serialVersionUID = 1L;

    private final Long searchConditionId;
    private final SearchTermType searchTermType;
    private final String fieldName;
    private final String rawSearchTerm;

    SearchTerm(final SearchTermType type, final String fieldName, final String rawSearchTerm) {
        this(null, type, null, fieldName, rawSearchTerm);
    }

    SearchTerm(final Long id, final SearchTermType type, final Long searchConditionId, final String fieldName, final String rawSearchTerm) {
        super(id);
        this.searchConditionId = searchConditionId;
        this.searchTermType = AssertAs.notNull(type);
        this.fieldName = AssertAs.notNull(fieldName, "fieldName");
        this.rawSearchTerm = AssertAs.notNull(rawSearchTerm, "rawSearchTerm");
    }

    public static SearchTerm<?> of(final long id, final int searchTermTypeId, final long searchConditionId, final String fieldName, final String rawSearchTerm) {
        SearchTermType type = SearchTermType.byId(searchTermTypeId);
        switch (type) {
        case BOOLEAN:
            return new BooleanSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case INTEGER:
            return new IntegerSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case STRING:
            return new StringSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        case AUDIT:
            return new AuditSearchTerm(id, searchConditionId, fieldName, rawSearchTerm);
        default:
            throw new UnsupportedOperationException("SearchTermType." + type + " is not supported");
        }
    }

    public SearchTermType getSearchTermType() {
        return searchTermType;
    }

    public Long getSearchConditionId() {
        return searchConditionId;
    }

    public String getFieldName() {
        return fieldName;
    }

    public String getRawSearchTerm() {
        return rawSearchTerm;
    }

    @Override
    public String getDisplayValue() {
        return rawSearchTerm;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + fieldName.hashCode();
        result = prime * result + rawSearchTerm.hashCode();
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        @SuppressWarnings("unchecked")
        final T other = (T) obj;
        if (fieldName.hashCode() != other.getFieldName().hashCode())
            return false;
        if (!rawSearchTerm.equals(other.getRawSearchTerm()))
            return false;
        return true;
    }

}
{'fraction_non_alphanumeric': 0.08773400391170719, 'fraction_numerical': 0.0011176306230790724, 'mean_word_length': 2.929198682766191, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '4827724', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1919, 'n_words': 577}