Skip to content

Commit

Permalink
Rename Comparator/ComparisonCondition to UserComparator/UserCondition…
Browse files Browse the repository at this point in the history
… to align naming with the agreed terminology
  • Loading branch information
adams85 committed Sep 7, 2023
1 parent 4171dbb commit 2848429
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 160 deletions.
20 changes: 10 additions & 10 deletions benchmarks/NewVersionLib/BenchmarkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor
{
new ConditionContainer
{
ComparisonCondition = new ComparisonCondition()
UserCondition = new UserCondition()
{
ComparisonAttribute = nameof(User.Identifier),
Comparator = Comparator.SensitiveOneOf,
Comparator = UserComparator.SensitiveOneOf,
StringListValue = new[]
{
"61418c941ecda8031d08ab86ec821e676fde7b6a59cd16b1e7191503c2f8297d",
Expand All @@ -57,10 +57,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor
{
new ConditionContainer
{
ComparisonCondition = new ComparisonCondition()
UserCondition = new UserCondition()
{
ComparisonAttribute = nameof(User.Email),
Comparator = Comparator.Contains,
Comparator = UserComparator.Contains,
StringListValue = new[] { "@example.com" }
}
},
Expand All @@ -73,10 +73,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor
{
new ConditionContainer
{
ComparisonCondition = new ComparisonCondition()
UserCondition = new UserCondition()
{
ComparisonAttribute = "Version",
Comparator = Comparator.SemVerOneOf,
Comparator = UserComparator.SemVerOneOf,
StringListValue = new[] { "1.0.0", "2.0.0" }
}
},
Expand All @@ -89,10 +89,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor
{
new ConditionContainer
{
ComparisonCondition = new ComparisonCondition()
UserCondition = new UserCondition()
{
ComparisonAttribute = "Version",
Comparator = Comparator.SemVerGreaterThan,
Comparator = UserComparator.SemVerGreaterThan,
StringValue = "3.0.0"
}
},
Expand All @@ -105,10 +105,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor
{
new ConditionContainer
{
ComparisonCondition = new ComparisonCondition()
UserCondition = new UserCondition()
{
ComparisonAttribute = "Number",
Comparator = Comparator.NumberGreaterThan,
Comparator = UserComparator.NumberGreaterThan,
DoubleValue = 3.14
}
},
Expand Down
148 changes: 74 additions & 74 deletions src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public static IndentedTextBuilder AppendEvaluationResult(this IndentedTextBuilde
return builder.Append(result ? "true" : "false");
}

private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, object? comparisonValue)
private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, object? comparisonValue)
{
return builder.Append($"User.{comparisonAttribute} {comparator.ToDisplayText()} '{comparisonValue ?? InvalidValuePlaceholder}'");
}

private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, string? comparisonValue, bool isSensitive = false)
private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, string? comparisonValue, bool isSensitive = false)
{
return builder.AppendComparisonCondition(comparisonAttribute, comparator, !isSensitive ? (object?)comparisonValue : "<hashed value>");
return builder.AppendUserCondition(comparisonAttribute, comparator, !isSensitive ? (object?)comparisonValue : "<hashed value>");
}

private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, string[]? comparisonValue, bool isSensitive = false)
private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, string[]? comparisonValue, bool isSensitive = false)
{
if (comparisonValue is null)
{
return builder.AppendComparisonCondition(comparisonAttribute, comparator, (object?)null);
return builder.AppendUserCondition(comparisonAttribute, comparator, (object?)null);
}

const string valueText = "value", valuesText = "values";
Expand All @@ -51,62 +51,62 @@ private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBu
}
}

private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, double? comparisonValue, bool isDateTime = false)
private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, double? comparisonValue, bool isDateTime = false)
{
if (comparisonValue is null)
{
return builder.AppendComparisonCondition(comparisonAttribute, comparator, (object?)null);
return builder.AppendUserCondition(comparisonAttribute, comparator, (object?)null);
}

return isDateTime && DateTimeUtils.TryConvertFromUnixTimeSeconds(comparisonValue.Value, out var dateTime)
? builder.Append($"User.{comparisonAttribute} {comparator.ToDisplayText()} '{comparisonValue.Value}' ({dateTime:yyyy-MM-dd'T'HH:mm:ss.fffK} UTC)")
: builder.Append($"User.{comparisonAttribute} {comparator.ToDisplayText()} '{comparisonValue.Value}'");
}

public static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, ComparisonCondition condition)
public static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, UserCondition condition)
{
return condition.Comparator switch
{
Comparator.Contains or
Comparator.NotContains or
Comparator.SemVerOneOf or
Comparator.SemVerNotOneOf =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue),

Comparator.SemVerLessThan or
Comparator.SemVerLessThanEqual or
Comparator.SemVerGreaterThan or
Comparator.SemVerGreaterThanEqual =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue),

Comparator.NumberEqual or
Comparator.NumberNotEqual or
Comparator.NumberLessThan or
Comparator.NumberLessThanEqual or
Comparator.NumberGreaterThan or
Comparator.NumberGreaterThanEqual =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue),

Comparator.SensitiveOneOf or
Comparator.SensitiveNotOneOf or
Comparator.SensitiveTextStartsWith or
Comparator.SensitiveTextNotStartsWith or
Comparator.SensitiveTextEndsWith or
Comparator.SensitiveTextNotEndsWith or
Comparator.SensitiveArrayContains or
Comparator.SensitiveArrayNotContains =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue, isSensitive: true),

Comparator.DateTimeBefore or
Comparator.DateTimeAfter =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue, isDateTime: true),

Comparator.SensitiveTextEquals or
Comparator.SensitiveTextNotEquals =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue, isSensitive: true),
UserComparator.Contains or
UserComparator.NotContains or
UserComparator.SemVerOneOf or
UserComparator.SemVerNotOneOf =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue),

UserComparator.SemVerLessThan or
UserComparator.SemVerLessThanEqual or
UserComparator.SemVerGreaterThan or
UserComparator.SemVerGreaterThanEqual =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue),

UserComparator.NumberEqual or
UserComparator.NumberNotEqual or
UserComparator.NumberLessThan or
UserComparator.NumberLessThanEqual or
UserComparator.NumberGreaterThan or
UserComparator.NumberGreaterThanEqual =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue),

UserComparator.SensitiveOneOf or
UserComparator.SensitiveNotOneOf or
UserComparator.SensitiveTextStartsWith or
UserComparator.SensitiveTextNotStartsWith or
UserComparator.SensitiveTextEndsWith or
UserComparator.SensitiveTextNotEndsWith or
UserComparator.SensitiveArrayContains or
UserComparator.SensitiveArrayNotContains =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue, isSensitive: true),

UserComparator.DateTimeBefore or
UserComparator.DateTimeAfter =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue, isDateTime: true),

UserComparator.SensitiveTextEquals or
UserComparator.SensitiveTextNotEquals =>
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue, isSensitive: true),

_ =>
builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.GetComparisonValue(throwIfInvalid: false)),
builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.GetComparisonValue(throwIfInvalid: false)),
};
}

Expand Down Expand Up @@ -150,7 +150,7 @@ private static IndentedTextBuilder AppendConditions<TCondition>(this IndentedTex

_ = conditions[i].GetCondition(throwIfInvalid: false) switch
{
ComparisonCondition comparisonCondition => builder.AppendComparisonCondition(comparisonCondition),
UserCondition userCondition => builder.AppendUserCondition(userCondition),
PrerequisiteFlagCondition prerequisiteFlagCondition => builder.AppendPrerequisiteFlagCondition(prerequisiteFlagCondition),
SegmentCondition segmentCondition => builder.AppendSegmentCondition(segmentCondition),
_ => builder.Append(InvalidItemPlaceholder),
Expand Down Expand Up @@ -291,36 +291,36 @@ public static IndentedTextBuilder AppendSegment(this IndentedTextBuilder builder
return builder.AppendConditions(segment.Conditions);
}

public static string ToDisplayText(this Comparator comparator)
public static string ToDisplayText(this UserComparator comparator)
{
return comparator switch
{
Comparator.Contains => "CONTAINS ANY OF",
Comparator.NotContains => "NOT CONTAINS ANY OF",
Comparator.SemVerOneOf => "IS ONE OF",
Comparator.SemVerNotOneOf => "IS NOT ONE OF",
Comparator.SemVerLessThan => "<",
Comparator.SemVerLessThanEqual => "<=",
Comparator.SemVerGreaterThan => ">",
Comparator.SemVerGreaterThanEqual => ">=",
Comparator.NumberEqual => "=",
Comparator.NumberNotEqual => "!=",
Comparator.NumberLessThan => "<",
Comparator.NumberLessThanEqual => "<=",
Comparator.NumberGreaterThan => ">",
Comparator.NumberGreaterThanEqual => ">=",
Comparator.SensitiveOneOf => "IS ONE OF",
Comparator.SensitiveNotOneOf => "IS NOT ONE OF",
Comparator.DateTimeBefore => "BEFORE",
Comparator.DateTimeAfter => "AFTER",
Comparator.SensitiveTextEquals => "EQUALS",
Comparator.SensitiveTextNotEquals => "NOT EQUALS",
Comparator.SensitiveTextStartsWith => "STARTS WITH ANY OF",
Comparator.SensitiveTextNotStartsWith => "NOT STARTS WITH ANY OF",
Comparator.SensitiveTextEndsWith => "ENDS WITH ANY OF",
Comparator.SensitiveTextNotEndsWith => "NOT ENDS WITH ANY OF",
Comparator.SensitiveArrayContains => "ARRAY CONTAINS ANY OF",
Comparator.SensitiveArrayNotContains => "ARRAY NOT CONTAINS ANY OF",
UserComparator.Contains => "CONTAINS ANY OF",
UserComparator.NotContains => "NOT CONTAINS ANY OF",
UserComparator.SemVerOneOf => "IS ONE OF",
UserComparator.SemVerNotOneOf => "IS NOT ONE OF",
UserComparator.SemVerLessThan => "<",
UserComparator.SemVerLessThanEqual => "<=",
UserComparator.SemVerGreaterThan => ">",
UserComparator.SemVerGreaterThanEqual => ">=",
UserComparator.NumberEqual => "=",
UserComparator.NumberNotEqual => "!=",
UserComparator.NumberLessThan => "<",
UserComparator.NumberLessThanEqual => "<=",
UserComparator.NumberGreaterThan => ">",
UserComparator.NumberGreaterThanEqual => ">=",
UserComparator.SensitiveOneOf => "IS ONE OF",
UserComparator.SensitiveNotOneOf => "IS NOT ONE OF",
UserComparator.DateTimeBefore => "BEFORE",
UserComparator.DateTimeAfter => "AFTER",
UserComparator.SensitiveTextEquals => "EQUALS",
UserComparator.SensitiveTextNotEquals => "NOT EQUALS",
UserComparator.SensitiveTextStartsWith => "STARTS WITH ANY OF",
UserComparator.SensitiveTextNotStartsWith => "NOT STARTS WITH ANY OF",
UserComparator.SensitiveTextEndsWith => "ENDS WITH ANY OF",
UserComparator.SensitiveTextNotEndsWith => "NOT ENDS WITH ANY OF",
UserComparator.SensitiveArrayContains => "ARRAY CONTAINS ANY OF",
UserComparator.SensitiveArrayNotContains => "ARRAY NOT CONTAINS ANY OF",
_ => InvalidOperatorPlaceholder
};
}
Expand Down
Loading

0 comments on commit 2848429

Please sign in to comment.