All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.imsweb.algorithms.seersiterecode.SeerExecutableSiteGroupDto Maven / Gradle / Ivy

package com.imsweb.algorithms.seersiterecode;

import java.util.List;

import org.apache.commons.lang3.Range;

/**
 * Internal site group DTO used to calculate the recode, this class should not be used outside of SEER*Utils...
 * User: depryf
 * Date: 8/22/12
 */
public class SeerExecutableSiteGroupDto {

    /**
     * Unique identifier
     */
    private String _id;

    /**
     * Name of the group
     */
    private String _name;

    /**
     * Site inclusions (single integer values or ranges)
     */
    private List _siteInclusions;

    /**
     * Site exclusions (single integer values or ranges)
     */
    private List _siteExclusions;

    /**
     * Histology inclusions (single integer values or ranges)
     */
    private List _histologyInclusions;

    /**
     * Histology exclusions (single integer values or ranges)
     */
    private List _histologyExclusions;

    /**
     * Recode
     */
    private String _recode;

    public String getId() {
        return _id;
    }

    public String getName() {
        return _name;
    }

    public List getSiteInclusions() {
        return _siteInclusions;
    }

    public List getSiteExclusions() {
        return _siteExclusions;
    }

    public List getHistologyInclusions() {
        return _histologyInclusions;
    }

    public List getHistologyExclusions() {
        return _histologyExclusions;
    }

    public String getRecode() {
        return _recode;
    }

    public void setId(String id) {
        _id = id;
    }

    public void setSiteInclusions(List siteInclusions) {
        _siteInclusions = siteInclusions;
    }

    public void setSiteExclusions(List siteExclusions) {
        _siteExclusions = siteExclusions;
    }

    public void setHistologyInclusions(List histologyInclusions) {
        _histologyInclusions = histologyInclusions;
    }

    public void setHistologyExclusions(List histologyExclusions) {
        _histologyExclusions = histologyExclusions;
    }

    public void setName(String name) {
        _name = name;
    }

    public void setRecode(String recode) {
        _recode = recode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        SeerExecutableSiteGroupDto that = (SeerExecutableSiteGroupDto)o;

        return !(_id != null ? !_id.equals(that._id) : that._id != null);

    }

    @Override
    public int hashCode() {
        return _id != null ? _id.hashCode() : 0;
    }

    public boolean matches(Integer site, Integer histology) {
        boolean siteOk, histOk = false;

        // check site
        if (_siteInclusions != null)
            siteOk = isContained(_siteInclusions, site);
        else if (_siteExclusions != null)
            siteOk = !isContained(_siteExclusions, site);
        else
            siteOk = true;

        // check histology (only if site matched)
        if (siteOk) {
            if (_histologyInclusions != null)
                histOk = isContained(_histologyInclusions, histology);
            else if (_histologyExclusions != null)
                histOk = !isContained(_histologyExclusions, histology);
            else
                histOk = true;
        }

        return siteOk && histOk;
    }

    @SuppressWarnings("unchecked")
    private boolean isContained(List list, Integer value) {
        if (list == null)
            return false;
        for (Object obj : list)
            if ((obj instanceof Range && ((Range)obj).contains(value)) || (obj.equals(value)))
                return true;
        return false;
    }
}