refactor: domain - generic isSortInConflict
This commit is contained in:
parent
07f18c8aab
commit
80f14d6601
|
@ -3,7 +3,6 @@ package domain
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -232,10 +231,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. EnnoblementSortIDASC and EnnoblementSortIDDESC).
|
||||
func (s EnnoblementSort) IsInConflict(s2 EnnoblementSort) bool {
|
||||
ss := []EnnoblementSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -542,10 +542,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. PlayerSortIDASC and PlayerSortIDDESC).
|
||||
func (s PlayerSort) IsInConflict(s2 PlayerSort) bool {
|
||||
ss := []PlayerSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -3,7 +3,6 @@ package domain
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -202,10 +201,7 @@ const (
|
|||
// IsInConflict returns true if two sorts can't be used together
|
||||
// (e.g. PlayerSnapshotSortIDASC and PlayerSnapshotSortIDDESC).
|
||||
func (s PlayerSnapshotSort) IsInConflict(s2 PlayerSnapshotSort) bool {
|
||||
ss := []PlayerSnapshotSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -527,10 +527,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. ServerSortKeyASC and ServerSortKeyDESC).
|
||||
func (s ServerSort) IsInConflict(s2 ServerSort) bool {
|
||||
ss := []ServerSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
func (s ServerSort) String() string {
|
||||
|
|
|
@ -470,10 +470,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. TribeSortIDASC and TribeSortIDDESC).
|
||||
func (s TribeSort) IsInConflict(s2 TribeSort) bool {
|
||||
ss := []TribeSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -265,10 +265,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. TribeChangeSortIDASC and TribeChangeSortIDDESC).
|
||||
func (s TribeChangeSort) IsInConflict(s2 TribeChangeSort) bool {
|
||||
ss := []TribeChangeSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -3,7 +3,6 @@ package domain
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -228,10 +227,7 @@ const (
|
|||
// IsInConflict returns true if two sorts can't be used together
|
||||
// (e.g. TribeSnapshotSortIDASC and TribeSnapshotSortIDDESC).
|
||||
func (s TribeSnapshotSort) IsInConflict(s2 TribeSnapshotSort) bool {
|
||||
ss := []TribeSnapshotSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -199,3 +200,12 @@ func newSortFromString[T interface {
|
|||
Sort: s,
|
||||
}
|
||||
}
|
||||
|
||||
func isSortInConflict[T interface {
|
||||
~uint8
|
||||
}](s1 T, s2 T) bool {
|
||||
ss := []T{s1, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package domain
|
|||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type Version struct {
|
||||
|
@ -107,10 +106,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. VersionSortCodeASC and VersionSortCodeDESC).
|
||||
func (s VersionSort) IsInConflict(s2 VersionSort) bool {
|
||||
ss := []VersionSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
func (s VersionSort) String() string {
|
||||
|
|
|
@ -390,10 +390,7 @@ const (
|
|||
|
||||
// IsInConflict returns true if two sorts can't be used together (e.g. VillageSortIDASC and VillageSortIDDESC).
|
||||
func (s VillageSort) IsInConflict(s2 VillageSort) bool {
|
||||
ss := []VillageSort{s, s2}
|
||||
slices.Sort(ss)
|
||||
// ASC is always an odd number, DESC is always an even number
|
||||
return (ss[0]%2 == 1 && ss[0] == ss[1]-1) || ss[0] == ss[1]
|
||||
return isSortInConflict(s, s2)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
|
Loading…
Reference in New Issue