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

com.imsweb.validation.entities.StandaloneSet Maven / Gradle / Ivy

/*
 * Copyright (C) 2010 Information Management Services, Inc.
 */
package com.imsweb.validation.entities;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * A standalone set is a ... set of edits. It is independent of a particular edits XML file, it uses
 * edit IDs to reference the edits. It also requires the validator ID.
 * 

* 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 StandaloneSet { /** * Set ID */ protected String _id; /** * Set name */ protected String _name; /** * Set description */ protected String _description; /** * Inclusions */ protected Map> _inclusions; /** * Exclusions */ protected Map> _exclusions; /** * All validator IDs referenced in the sets */ protected Set _referencedValidatorIds; /** * Constructor. */ public StandaloneSet() { _referencedValidatorIds = new HashSet<>(); } /** * 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 inclusions. *

* Created on Apr 5, 2011 by depryf * @return inclusions (list of edit ID per validaor ID) */ public Map> getInclusions() { return _inclusions; } /** * Setter for the inclusions. *

* Created on Apr 5, 2011 by depryf * @param inclusions inclusions (list of edit ID per validaor ID) */ public void setInclusions(Map> inclusions) { this._inclusions = inclusions; } /** * Getter for the exclusions. *

* Created on Apr 5, 2011 by depryf * @return exclusions (list of edit ID per validaor ID) */ public Map> getExclusions() { return _exclusions; } /** * Setter for the exclusions. *

* Created on Apr 5, 2011 by depryf * @param exclusions exclusions (list of edit ID per validaor ID) */ public void setExclusions(Map> exclusions) { this._exclusions = exclusions; } /** * Adds a referenced validator ID. * @param validatorId validator ID */ public void addReferencedValidatorId(String validatorId) { _referencedValidatorIds.add(validatorId); } /** * Returns all the referenced validator ID. * @return all the referenced validator ID; maybe empty but never null */ public Set getReferencedValidatorIds() { return _referencedValidatorIds; } /** * Returns true if the edit with the given ID from the given validator ID should be included or not, according to this set. *

* The logic is: *

    *
  1. include if inclusions are null/empty (meaning include everything), or if the list contains the edit ID
  2. *
  3. if edit is included in step one, but the exclusions list contains the edit ID, then return false
  4. *
  5. return true
  6. *
      *

      * Created on Dec 9, 2010 by depryf * @param validatorId validator ID * @param editId edit ID * @return true if the edit with the given ID from the given validator ID should be included or not, according to this set */ public boolean needToInclude(String validatorId, String editId) { List inclusions = _inclusions.get(validatorId); List exclusions = _exclusions.get(validatorId); boolean include = inclusions == null || inclusions.isEmpty() || inclusions.contains(editId); if (exclusions != null && exclusions.contains(editId)) include = false; return include; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof StandaloneSet)) return false; StandaloneSet that = (StandaloneSet)o; return Objects.equals(_id, that._id); } @Override public int hashCode() { return Objects.hash(_id); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy