using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Text; namespace Sarand.Net.Standard.Base.Core { //======================================================================= /// /// Code parameter value with flag to indicate whether the value /// is included (valid as a filter) or excluded (explicitly not matched). /// public class CodeParam { //------------------------------------------------------------------- // Construction. public CodeParam (String code, bool including) { Code = StringUtil.EmptyOnNull(code); Including = including; } //------------------------------------------------------------------- // Properties. /// Code parameter. public String Code { get; } /// Whether the value is included (valid as a filter) or excluded (explicitly not matched). public bool Including { get; } //------------------------------------------------------------------- /// Determine if the two code params 'match' - taking code and 'sense' flag into account. public bool Matches (CodeParam cp) { // Values match if either code is blank: if (StringUtil.IsEmpty(Code) || StringUtil.IsEmpty(cp.Code)) return true; // Values match if both 'senses' are negative: if (!Including && !cp.Including) return true; // Values match if both 'senses' are positive and the codes are the same: if (Including && cp.Including) return Code.EqualsCI(cp.Code); // Values match if 'senses' and codes are different: if (Including != cp.Including) return !Code.EqualsCI(cp.Code); return false; } //------------------------------------------------------------------- /// Compare code params - first on code then on flag. public int Compare (CodeParam cp) { if (Code.EqualsCI(cp.Code)) { // Compare 'Including' flags: if (!Including && cp.Including) return 1; if (Including && !cp.Including) return -1; return 0; } return Code.CompareTo(cp.Code); } //------------------------------------------------------------------- } //======================================================================= }