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