<commit_before>package com.amee.domain.item.profile;

import com.amee.domain.LocaleHolder;
import com.amee.domain.ObjectType;
import com.amee.domain.data.ItemValueDefinition;
import com.amee.domain.item.BaseItemValue;
import com.amee.platform.science.ExternalTextValue;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Configurable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "PROFILE_ITEM_TEXT_VALUE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Configurable(autowire = Autowire.BY_TYPE)
public class ProfileItemTextValue extends BaseProfileItemValue implements ExternalTextValue {

    // 32767 because this is bigger than 255, smaller than 65535 and fits into an exact number of bits.
    public final static int VALUE_SIZE = 32767;

    @Column(name = "VALUE", nullable = false, length = VALUE_SIZE)
    private String value = "";

    public ProfileItemTextValue() {
        super();
    }

    public ProfileItemTextValue(ItemValueDefinition itemValueDefinition, NuProfileItem profileItem) {
        super(itemValueDefinition, profileItem);
        setValue(value);
    }

    public ProfileItemTextValue(ItemValueDefinition itemValueDefinition, NuProfileItem profileItem, String value) {
        this(itemValueDefinition, profileItem);
        setValue(value);
    }

    protected void copyTo(BaseItemValue o) {
        super.copyTo(o);
        ((ProfileItemTextValue)o).value = value;
    }

    public void checkItemValueDefinition() {
        if ((getItemValueDefinition().isDouble() || getItemValueDefinition().isInteger())) {
            throw new IllegalStateException();
        }
    }

    @Override
    public boolean isDouble() {
        return false;
    }

    @Override
    public boolean isConvertible() {
        return false;
    }

    @Override
    public boolean isUsableValue() {
        return !StringUtils.isBlank(getValue());
    }

    public String getValue() {
        if (getItemValueDefinition().isText() && !LocaleHolder.isDefaultLocale()) {
            return localeService.getLocaleNameValue(this, value);
        } else {
            return value;
        }
    }

    @Override
    public String getValueAsString() {
        return getValue();
    }

    @Override
    public String getUsableValue() {
        return getValueAsString();
    }

    public void setValue(String value) {
        // Make sure value is not null and is not too long.
        if (value != null) {
            if (value.length() > VALUE_SIZE) {
                value = value.substring(0, VALUE_SIZE - 1);
            }
            this.value = value;
        } else {
            this.value = "";
        }
    }

    @Override
    public ObjectType getObjectType() {
        return ObjectType.PITV;
    }

}
<commit_msg>PL-2789 - Improved support for locales, intelligent handling of legacy and nu items and values to ensure they don't clash<commit_after>package com.amee.domain.item.profile;

import com.amee.domain.ObjectType;
import com.amee.domain.data.ItemValueDefinition;
import com.amee.domain.item.BaseItemValue;
import com.amee.platform.science.ExternalTextValue;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "PROFILE_ITEM_TEXT_VALUE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProfileItemTextValue extends BaseProfileItemValue implements ExternalTextValue {

    // 32767 because this is bigger than 255, smaller than 65535 and fits into an exact number of bits.
    public final static int VALUE_SIZE = 32767;

    @Column(name = "VALUE", nullable = false, length = VALUE_SIZE)
    private String value = "";

    public ProfileItemTextValue() {
        super();
    }

    public ProfileItemTextValue(ItemValueDefinition itemValueDefinition, NuProfileItem profileItem) {
        super(itemValueDefinition, profileItem);
        setValue(value);
    }

    public ProfileItemTextValue(ItemValueDefinition itemValueDefinition, NuProfileItem profileItem, String value) {
        this(itemValueDefinition, profileItem);
        setValue(value);
    }

    protected void copyTo(BaseItemValue o) {
        super.copyTo(o);
        ((ProfileItemTextValue) o).value = value;
    }

    public void checkItemValueDefinition() {
        if ((getItemValueDefinition().isDouble() || getItemValueDefinition().isInteger())) {
            throw new IllegalStateException();
        }
    }

    @Override
    public boolean isDouble() {
        return false;
    }

    @Override
    public boolean isConvertible() {
        return false;
    }

    @Override
    public boolean isUsableValue() {
        return !StringUtils.isBlank(getValue());
    }

    public String getValue() {
        return value;
    }

    @Override
    public String getValueAsString() {
        return getValue();
    }

    @Override
    public String getUsableValue() {
        return getValueAsString();
    }

    public void setValue(String value) {
        // Make sure value is not null and is not too long.
        if (value != null) {
            if (value.length() > VALUE_SIZE) {
                value = value.substring(0, VALUE_SIZE - 1);
            }
            this.value = value;
        } else {
            this.value = "";
        }
    }

    @Override
    public ObjectType getObjectType() {
        return ObjectType.PITV;
    }

}

{'fraction_non_alphanumeric': 0.09242685025817556, 'fraction_numerical': 0.007573149741824441, 'mean_word_length': 2.971975393028025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7321770', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1567, 'n_words': 382}