com.imsweb.validation.entities.EmbeddedSet Maven / Gradle / Ivy
/*
* Copyright (C) 2010 Information Management Services, Inc.
*/
package com.imsweb.validation.entities;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* An embedded set is a ... set of edits provided within a given validator; edit IDs to reference the edits.
*
* It allows inclusions and exclusions and provides a utility method to use those inclusions/exclusions: needToInclude().
*
* Created on Apr 5, 2011 by depryf
*/
public class EmbeddedSet {
/**
* DB ID for this set
*/
protected Long _setId;
/**
* Set ID
*/
protected String _id;
/**
* Set name
*/
protected String _name;
/**
* Validator under which this set is registered
*/
protected Validator _validator;
/**
* Set description
*/
protected String _description;
/**
* Inclusions
*/
protected Set _inclusions;
/**
* Exclusions
*/
protected Set _exclusions;
/**
* Ignored flag; unlike the rule ignore flags, the engine doesn't take into account the embedded set flags when executing rules.
*/
protected Boolean _ignored;
/**
* The default conditions for this set; this field is not supported in the XML and can only be used/populated programmatically...
*/
protected Set _defaultConditions;
/**
* Constructor.
*/
public EmbeddedSet() {
_ignored = Boolean.FALSE;
_defaultConditions = new HashSet<>();
}
/**
* Getter for the set persistence ID. Must be unique within the validation engine.
*
* In a system persisting the sets in a database, that would represent a database primary key.
* In a system using only memory objects loaded from XML, it should be assigned using the
* getNextSetSequence() method in ValidatorServices.
*
* Created on Mar 10, 2011 by depryf
* @return the category persistence ID
*/
public Long getSetId() {
return _setId;
}
/**
* Setter for the set persistence ID. Must be unique within the validation engine.
*
* In a system persisting the sets in a database, that would represent a database primary key.
* In a system using only memory objects loaded from XML, it should be assigned using the
* getNextSetSequence() method in ValidatorServices.
*
* Created on Mar 10, 2011 by depryf
* @param setId category persistence ID
*/
public void setSetId(Long setId) {
_setId = setId;
}
/**
* Getter for the set ID.
*
* Created on Apr 5, 2011 by depryf
* @return set ID
*/
public String getId() {
return _id;
}
/**
* Setter for the set ID.
*
* Created on Apr 5, 2011 by depryf
* @param id set ID
*/
public void setId(String id) {
this._id = id;
}
/**
* Getter for the set name.
*
* Created on Apr 5, 2011 by depryf
* @return set name
*/
public String getName() {
return _name;
}
/**
* Setter for the set name.
*
* Created on Apr 5, 2011 by depryf
* @param name set name
*/
public void setName(String name) {
this._name = name;
}
/**
* Getter for the set description.
*
* Created on Apr 5, 2011 by depryf
* @return set description
*/
public String getDescription() {
return _description;
}
/**
* Setter for the set description.
*
* Created on Apr 5, 2011 by depryf
* @param description set description
*/
public void setDescription(String description) {
this._description = description;
}
/**
* Getter for the parent Validator.
*
* Created on Mar 10, 2011 by depryf
* @return a Validator
*/
public Validator getValidator() {
return _validator;
}
/**
* Setter for the parent Valdidator.
*
* Created on Mar 10, 2011 by depryf
* @param validator the parent Validator.
*/
public void setValidator(Validator validator) {
_validator = validator;
}
/**
* Getter for the inclusions.
*
* Created on Apr 5, 2011 by depryf
* @return inclusions (set of edit IDs)
*/
public Set getInclusions() {
return _inclusions;
}
/**
* Setter for the inclusions.
*
* Created on Apr 5, 2011 by depryf
* @param inclusions inclusions (set of edit IDs)
*/
public void setInclusions(Set inclusions) {
this._inclusions = inclusions;
}
/**
* Getter for the exclusions.
*
* Created on Apr 5, 2011 by depryf
* @return exclusions (set of edit IDs)
*/
public Set getExclusions() {
return _exclusions;
}
/**
* Setter for the exclusions.
*
* Created on Apr 5, 2011 by depryf
* @param exclusions exclusions (set of edit IDs)
*/
public void setExclusions(Set exclusions) {
this._exclusions = exclusions;
}
/**
* Getter for the ignored flag.
*
* Created on Mar 10, 2011 by depryf
* @return true if the set is ignored
*/
public Boolean getIgnored() {
return _ignored;
}
/**
* Setter for the ignored flag.
*
* Created on Mar 10, 2011 by depryf
* @param ignored the ignored flag to set
*/
public void setIgnored(Boolean ignored) {
_ignored = ignored == null ? Boolean.FALSE : ignored;
}
/**
* Getter for the default conditions.
*
* Created on Mar 10, 2011 by depryf
* @return the default conditions
*/
public Set getDefaultConditions() {
return _defaultConditions;
}
/**
* Setter for the default conditions.
*
* Created on Mar 10, 2011 by depryf
* @param defaultConditions the default conditions
*/
public void setDefaultConditions(Set defaultConditions) {
_defaultConditions = defaultConditions;
}
/**
* Returns true if the edit with the given ID should be included or not, according to this set.
*
* The logic is:
*
* - include if inclusions are null/empty (meaning include everything), or if the list contains the edit ID
* - if edit is included in step one, but the exclusions list contains the edit ID, then return false
* - return true
*
*
* Created on Dec 9, 2010 by depryf
* @param editId edit ID
* @return true if the edit with the given ID should be included or not, according to this set
*/
public boolean needToInclude(String editId) {
boolean include = _inclusions == null || _inclusions.isEmpty() || _inclusions.contains(editId);
if (_exclusions != null && _exclusions.contains(editId))
include = false;
return include;
}
@Override
public String toString() {
return getId();
}
@Override
public boolean equals(Object other) {
if (!(other instanceof EmbeddedSet))
return false;
EmbeddedSet castOther = (EmbeddedSet)other;
if (getSetId() != null)
return new EqualsBuilder().append(getSetId(), castOther.getSetId()).isEquals();
else
return new EqualsBuilder().append(getId(), castOther.getId()).isEquals();
}
@Override
public int hashCode() {
if (getSetId() != null)
return new HashCodeBuilder().append(getSetId()).toHashCode();
else
return new HashCodeBuilder().append(getId()).toHashCode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy