private IRangeClauseFilter RemoveClausesCoveredBy(RangeClauseFilter <T> removeFrom, RangeClauseFilter <T> removalSpec) { var newFilter = RemoveIsClausesCoveredBy(removeFrom, removalSpec); newFilter = RemoveRangesCoveredBy(removeFrom, removalSpec); newFilter = RemoveSingleValuesCoveredBy(removeFrom, removalSpec); newFilter = RemoveRelationalOpsCoveredBy(removeFrom, removalSpec); return(newFilter); }
private RangeClauseFilter <T> RemoveSingleValuesCoveredBy(RangeClauseFilter <T> removeFrom, RangeClauseFilter <T> removalSpec) { List <T> toRemove = new List <T>(); if (removalSpec.TryGetIsLTValue(out T removalSpecLT)) { foreach (var sv in removeFrom.SingleValues) { if (removalSpecLT.CompareTo(sv) > 0) { toRemove.Add(sv); } } } if (removalSpec.TryGetIsGTValue(out T removalSpecGT)) { foreach (var sv in removeFrom.SingleValues) { if (removalSpecGT.CompareTo(sv) < 0) { toRemove.Add(sv); } } } foreach (var tup in removalSpec.RangeValues) { foreach (var val in removeFrom.SingleValues) { if (tup.Item1.CompareTo(val) <= 0 && tup.Item2.CompareTo(val) >= 0) { toRemove.Add(val); } } } toRemove.AddRange(removalSpec.SingleValues); foreach (var rem in toRemove) { removeFrom.SingleValues.Remove(rem); } var toRemoveVariables = new List <string>(); foreach (var value in removalSpec.VariableSingleValues) { if (removeFrom.VariableSingleValues.Contains(value)) { toRemoveVariables.Add(value); } } toRemoveVariables.ForEach(rv => removeFrom.VariableSingleValues.Remove(rv)); return(removeFrom); }
private RangeClauseFilter <T> RemoveRangesCoveredBy(RangeClauseFilter <T> removeFrom, RangeClauseFilter <T> removalSpec) { if (!(removeFrom.RangeValues.Any() || removeFrom.VariableRanges.Any())) { return(removeFrom); } var rangesToRemove = new List <Tuple <T, T> >(); if (removalSpec.TryGetIsLTValue(out T removalSpecLT)) { foreach (var tup in removeFrom.RangeValues) { if (removalSpecLT.CompareTo(tup.Item1) > 0 && removalSpecLT.CompareTo(tup.Item2) > 0) { rangesToRemove.Add(tup); } } } if (removalSpec.TryGetIsGTValue(out T removalSpecGT)) { foreach (var tup in removeFrom.RangeValues) { if (removalSpecGT.CompareTo(tup.Item1) < 0 && removalSpecGT.CompareTo(tup.Item2) < 0) { rangesToRemove.Add(tup); } } } foreach (var tup in removeFrom.RangeValues) { foreach (var rem in removalSpec.RangeValues) { if (rem.Item1.CompareTo(tup.Item1) <= 0 && rem.Item2.CompareTo(tup.Item2) >= 0) { rangesToRemove.Add(tup); } } } removeFrom.RemoveRangeValues(rangesToRemove); var varRangesToRemove = new List <string>(); foreach (var value in removeFrom.VariableRanges) { if (removalSpec.VariableRanges.Contains(value)) { varRangesToRemove.Add(value); } } varRangesToRemove.ForEach(vr => removeFrom._variableRanges.Remove(vr)); return(removeFrom); }
public IRangeClauseFilter Create(string typeName, IParseTreeValueFactory valueFactory) { if (valueFactory is null) { throw new ArgumentNullException(); } if (!(IntegralNumberExtents.Keys.Contains(typeName) || typeName.Equals(Tokens.Double) || typeName.Equals(Tokens.Single) || typeName.Equals(Tokens.Currency) || typeName.Equals(Tokens.Boolean) || typeName.Equals(Tokens.String))) { throw new ArgumentException($"Unsupported TypeName ({typeName})"); } if (IntegralNumberExtents.Keys.Contains(typeName)) { var integerTypeFilter = new RangeClauseFilter <long>(typeName, valueFactory, this, ParseTreeValue.TryConvertValue); var minExtent = valueFactory.Create(IntegralNumberExtents[typeName].Item1.ToString(), typeName); var maxExtent = valueFactory.Create(IntegralNumberExtents[typeName].Item2.ToString(), typeName); integerTypeFilter.AddExtents(minExtent, maxExtent); return(integerTypeFilter); } else if (typeName.Equals(Tokens.Double) || typeName.Equals(Tokens.Single)) { var doubleTypeFilter = new RangeClauseFilter <double>(typeName, valueFactory, this, ParseTreeValue.TryConvertValue); if (typeName.Equals(Tokens.Single)) { var minExtent = valueFactory.Create(CompareExtents.SINGLEMIN.ToString(), typeName); var maxExtent = valueFactory.Create(CompareExtents.SINGLEMAX.ToString(), typeName); doubleTypeFilter.AddExtents(minExtent, maxExtent); } return(doubleTypeFilter); } else if (typeName.Equals(Tokens.Boolean)) { var boolTypeFilter = new RangeClauseFilter <bool>(typeName, valueFactory, this, ParseTreeValue.TryConvertValue); return(boolTypeFilter); } else if (typeName.Equals(Tokens.Currency)) { var decimalTypeFilter = new RangeClauseFilter <decimal>(typeName, valueFactory, this, ParseTreeValue.TryConvertValue); var minExtent = valueFactory.Create(CompareExtents.CURRENCYMIN.ToString(), typeName); var maxExtent = valueFactory.Create(CompareExtents.CURRENCYMAX.ToString(), typeName); decimalTypeFilter.AddExtents(minExtent, maxExtent); return(decimalTypeFilter); } var filter = new RangeClauseFilter <string>(typeName, valueFactory, this, ParseTreeValue.TryConvertValue); return(filter); }
private static RangeClauseFilter <T> RemoveIsClausesCoveredBy(RangeClauseFilter <T> removeFrom, RangeClauseFilter <T> removalSpec) { if (removeFrom.TryGetIsLTValue(out T isLT) && removalSpec.TryGetIsLTValue(out T removalSpecLT) && removalSpecLT.CompareTo(isLT) >= 0) { removeFrom.RemoveIsLTClause(); } if (removeFrom.TryGetIsGTValue(out T isGT) && removalSpec.TryGetIsGTValue(out T removalSpecGT) && removalSpecGT.CompareTo(isGT) <= 0) { removeFrom.RemoveIsGTClause(); } return(removeFrom); }
private RangeClauseFilter <T> RemoveRelationalOpsCoveredBy(RangeClauseFilter <T> removeFrom, RangeClauseFilter <T> removalSpec) { List <string> toRemove = new List <string>(); if (removalSpec.FiltersAllRelationalOps) { removeFrom.RelationalOps.Clear(); } foreach (var rem in removalSpec.RelationalOps) { if (removeFrom.RelationalOps.Contains(rem)) { toRemove.Add(rem); } } foreach (var rem in toRemove) { removeFrom.RelationalOps.Remove(rem); } return(removeFrom); }