<commit_before>package com.amee.domain.data;

import com.amee.domain.*;
import com.amee.domain.path.Pathable;
import com.amee.platform.science.AmountCompoundUnit;
import com.amee.platform.science.AmountPerUnit;
import com.amee.platform.science.AmountUnit;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "RETURN_VALUE_DEFINITION")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ReturnValueDefinition extends AMEEEntity implements Pathable {

    // TODO: Never allow nulls for the values. Encapsulate as with other entities. Provide default values. Protect for NPEs.
    // TODO: Are the unit size constants required?

    public static final int TYPE_MIN_SIZE = 1;
    public static final int TYPE_MAX_SIZE = 255;
    public static final int UNIT_MIN_SIZE = 1;
    public static final int UNIT_MAX_SIZE = 255;
    public static final int PER_UNIT_MIN_SIZE = 1;
    public static final int PER_UNIT_MAX_SIZE = 255;

    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "ITEM_DEFINITION_ID")
    private ItemDefinition itemDefinition;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "VALUE_DEFINITION_ID")
    private ValueDefinition valueDefinition;

    @Column(name = "TYPE")
    private String type;

    @Column(name = "UNIT")
    private String unit;

    @Column(name = "PER_UNIT")
    private String perUnit;

    @Column(name = "DEFAULT_TYPE")
    private boolean defaultType;

    public ReturnValueDefinition() {
        super();
    }

    public ReturnValueDefinition(ItemDefinition itemDefinition) {
        super();
        setItemDefinition(itemDefinition);
        itemDefinition.add(this);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public AmountUnit getUnit() {
        return StringUtils.isNotBlank(unit) ? AmountUnit.valueOf(unit) : AmountUnit.ONE;
    }

    public void setUnit(AmountUnit unit) {
        this.unit = unit.toString();
    }

    public AmountPerUnit getPerUnit() {
        return StringUtils.isNotBlank(perUnit) ? AmountPerUnit.valueOf(perUnit) : AmountPerUnit.ONE;
    }

    public void setPerUnit(AmountPerUnit perUnit) {
        this.perUnit = perUnit.toString();
    }

    public boolean isDefaultType() {
        return defaultType;
    }

    public void setDefaultType(boolean isDefault) {
        this.defaultType = isDefault;
    }

    public ItemDefinition getItemDefinition() {
        return itemDefinition;
    }

    public void setItemDefinition(ItemDefinition itemDefinition) {
        this.itemDefinition = itemDefinition;
    }

    public ValueDefinition getValueDefinition() {
        return valueDefinition;
    }

    public void setValueDefinition(ValueDefinition valueDefinition) {
        this.valueDefinition = valueDefinition;
    }

    @Override
    public String getPath() {
        return getUid();
    }

    @Override
    public String getName() {
        return getUid();
    }

    @Override
    public String getDisplayName() {
        return getName();
    }

    @Override
    public String getDisplayPath() {
        return getPath();
    }

    @Override
    public String getFullPath() {
        return getItemDefinition().getFullPath() + "/" + getPath();
    }

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

    @Override
    public List<IAMEEEntityReference> getHierarchy() {
        List<IAMEEEntityReference> entities = getItemDefinition().getHierarchy();
        entities.add(this);
        return entities;
    }

    @Override
    public boolean isTrash() {
        return status.equals(AMEEStatus.TRASH) || getItemDefinition().isTrash();
    }

    public AmountCompoundUnit getCompoundUnit() {
        return getUnit().with(getPerUnit());
    }
}<commit_msg>PL-3294 - Guard against nulls in ReturnValueDefinition.<commit_after>package com.amee.domain.data;

import com.amee.domain.*;
import com.amee.domain.path.Pathable;
import com.amee.platform.science.AmountCompoundUnit;
import com.amee.platform.science.AmountPerUnit;
import com.amee.platform.science.AmountUnit;
import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "RETURN_VALUE_DEFINITION")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ReturnValueDefinition extends AMEEEntity implements Pathable {

    public static final int TYPE_MIN_SIZE = 1;
    public static final int TYPE_MAX_SIZE = 255;
    public static final int UNIT_MAX_SIZE = 255;
    public static final int PER_UNIT_MAX_SIZE = 255;

    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "ITEM_DEFINITION_ID")
    private ItemDefinition itemDefinition;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "VALUE_DEFINITION_ID")
    private ValueDefinition valueDefinition;

    @Column(name = "TYPE")
    private String type = "";

    @Column(name = "UNIT")
    private String unit = "";

    @Column(name = "PER_UNIT")
    private String perUnit = "";

    @Column(name = "DEFAULT_TYPE")
    private boolean defaultType = false;

    public ReturnValueDefinition() {
        super();
    }

    public ReturnValueDefinition(ItemDefinition itemDefinition) {
        super();
        setItemDefinition(itemDefinition);
        itemDefinition.add(this);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public AmountUnit getUnit() {
        return StringUtils.isNotBlank(unit) ? AmountUnit.valueOf(unit) : AmountUnit.ONE;
    }

    public void setUnit(AmountUnit unit) {
        this.unit = unit.toString();
    }

    public AmountPerUnit getPerUnit() {
        return StringUtils.isNotBlank(perUnit) ? AmountPerUnit.valueOf(perUnit) : AmountPerUnit.ONE;
    }

    public void setPerUnit(AmountPerUnit perUnit) {
        this.perUnit = perUnit.toString();
    }

    public boolean isDefaultType() {
        return defaultType;
    }

    public void setDefaultType(boolean isDefault) {
        this.defaultType = isDefault;
    }

    public ItemDefinition getItemDefinition() {
        return itemDefinition;
    }

    public void setItemDefinition(ItemDefinition itemDefinition) {
        this.itemDefinition = itemDefinition;
    }

    public ValueDefinition getValueDefinition() {
        return valueDefinition;
    }

    public void setValueDefinition(ValueDefinition valueDefinition) {
        this.valueDefinition = valueDefinition;
    }

    @Override
    public String getPath() {
        return getUid();
    }

    @Override
    public String getName() {
        return getUid();
    }

    @Override
    public String getDisplayName() {
        return getName();
    }

    @Override
    public String getDisplayPath() {
        return getPath();
    }

    @Override
    public String getFullPath() {
        return getItemDefinition().getFullPath() + "/" + getPath();
    }

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

    @Override
    public List<IAMEEEntityReference> getHierarchy() {
        List<IAMEEEntityReference> entities = getItemDefinition().getHierarchy();
        entities.add(this);
        return entities;
    }

    @Override
    public boolean isTrash() {
        return status.equals(AMEEStatus.TRASH) || getItemDefinition().isTrash();
    }

    public AmountCompoundUnit getCompoundUnit() {
        return getUnit().with(getPerUnit());
    }
}
{'fraction_non_alphanumeric': 0.09328263624841572, 'fraction_numerical': 0.0032953105196451204, 'mean_word_length': 3.1357442348008386, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2141483', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2203, 'n_words': 511}