Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AsaiYusuke committed Feb 4, 2023
1 parent 200dd1c commit bc56545
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ const (
msgTypeObjectOrArray string = `object/array`
)

var emptyList = []interface{}{struct{}{}}
var emptyEntity = struct{}{}
var emptyList = []interface{}{emptyEntity}
var fullList = []interface{}{true}
2 changes: 1 addition & 1 deletion syntax_basic_comparator_numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *syntaxBasicNumericComparator) typeCast(values []interface{}) bool {
values[index], _ = typedValue.Float64()
case struct{}:
default:
values[index] = struct{}{}
values[index] = emptyEntity
}
}
return foundValue
Expand Down
2 changes: 1 addition & 1 deletion syntax_basic_comparator_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (c *syntaxBasicStringComparator) typeCast(values []interface{}) bool {
foundValue = true
case struct{}:
default:
values[index] = struct{}{}
values[index] = emptyEntity
}
}
return foundValue
Expand Down
4 changes: 2 additions & 2 deletions syntax_basic_compare_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func (q *syntaxBasicCompareQuery) compute(
var hasValue bool
// The syntax parser always results in a literal value on the right side as input.
for leftIndex := range leftValues {
if leftValues[leftIndex] == struct{}{} {
if leftValues[leftIndex] == emptyEntity {
continue
}
if q.comparator.comparator(leftValues[leftIndex], rightValues[0]) {
hasValue = true
} else {
leftValues[leftIndex] = struct{}{}
leftValues[leftIndex] = emptyEntity
}
}
if hasValue {
Expand Down
8 changes: 4 additions & 4 deletions syntax_node_qualifier_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (f *syntaxFilterQualifier) retrieveMap(
isEachResult := len(valueList) == len(srcMap)

if !isEachResult {
if valueList[0] == struct{}{} {
if valueList[0] == emptyEntity {
return ErrorMemberNotExist{
errorBasicRuntime: f.errorRuntime,
}
Expand All @@ -58,7 +58,7 @@ func (f *syntaxFilterQualifier) retrieveMap(

for index := range *sortKeys {
if isEachResult {
if valueList[index] == struct{}{} {
if valueList[index] == emptyEntity {
continue
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (f *syntaxFilterQualifier) retrieveList(
isEachResult := len(valueList) == len(srcList)

if !isEachResult {
if valueList[0] == struct{}{} {
if valueList[0] == emptyEntity {
return ErrorMemberNotExist{
errorBasicRuntime: f.errorRuntime,
}
Expand All @@ -104,7 +104,7 @@ func (f *syntaxFilterQualifier) retrieveList(

for index := range srcList {
if isEachResult {
if valueList[index] == struct{}{} {
if valueList[index] == emptyEntity {
continue
}
}
Expand Down
10 changes: 5 additions & 5 deletions syntax_query_logical_and.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ func (l *syntaxLogicalAnd) compute(

leftComputedList := l.leftQuery.compute(root, currentList)
if len(leftComputedList) == 1 {
if leftComputedList[0] == struct{}{} {
if leftComputedList[0] == emptyEntity {
return leftComputedList
}
return l.rightQuery.compute(root, currentList)
}

rightComputedList := l.rightQuery.compute(root, currentList)
if len(rightComputedList) == 1 {
if rightComputedList[0] == struct{}{} {
if rightComputedList[0] == emptyEntity {
return rightComputedList
}
return leftComputedList
}

var hasValue bool
for index := range rightComputedList {
if rightComputedList[index] == struct{}{} {
leftComputedList[index] = struct{}{}
if rightComputedList[index] == emptyEntity {
leftComputedList[index] = emptyEntity
continue
}
if leftComputedList[index] != struct{}{} {
if leftComputedList[index] != emptyEntity {
hasValue = true
}
}
Expand Down
6 changes: 3 additions & 3 deletions syntax_query_logical_not.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ func (l *syntaxLogicalNot) compute(

computedList := l.query.compute(root, currentList)
if len(computedList) == 1 {
if computedList[0] == struct{}{} {
if computedList[0] == emptyEntity {
return fullList
}
return emptyList
}

var hasValue bool
for index := range computedList {
if computedList[index] == struct{}{} {
if computedList[index] == emptyEntity {
computedList[index] = true
hasValue = true
} else {
computedList[index] = struct{}{}
computedList[index] = emptyEntity
}
}
if hasValue {
Expand Down
6 changes: 3 additions & 3 deletions syntax_query_logical_or.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ func (l *syntaxLogicalOr) compute(

leftComputedList := l.leftQuery.compute(root, currentList)
if len(leftComputedList) == 1 {
if leftComputedList[0] == struct{}{} {
if leftComputedList[0] == emptyEntity {
return l.rightQuery.compute(root, currentList)
}
return leftComputedList
}

rightComputedList := l.rightQuery.compute(root, currentList)
if len(rightComputedList) == 1 {
if rightComputedList[0] == struct{}{} {
if rightComputedList[0] == emptyEntity {
return leftComputedList
}
return rightComputedList
}

for index := range rightComputedList {
if rightComputedList[index] != struct{}{} {
if rightComputedList[index] != emptyEntity {
leftComputedList[index] = rightComputedList[index]
}
}
Expand Down
2 changes: 1 addition & 1 deletion syntax_query_param_current_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *syntaxQueryParamCurrentRoot) compute(
var hasValue bool
for index := range currentList {
if err := e.param.retrieve(root, currentList[index], &containers[index]); err != nil {
result[index] = struct{}{}
result[index] = emptyEntity
continue
}
hasValue = true
Expand Down

0 comments on commit bc56545

Please sign in to comment.