diff --git a/internal/domain/ennoblement.go b/internal/domain/ennoblement.go index 1af9765..ca76e1e 100644 --- a/internal/domain/ennoblement.go +++ b/internal/domain/ennoblement.go @@ -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 diff --git a/internal/domain/player.go b/internal/domain/player.go index 116dbeb..afc2e3b 100644 --- a/internal/domain/player.go +++ b/internal/domain/player.go @@ -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 diff --git a/internal/domain/player_snapshot.go b/internal/domain/player_snapshot.go index fcecbcf..9dd884f 100644 --- a/internal/domain/player_snapshot.go +++ b/internal/domain/player_snapshot.go @@ -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 diff --git a/internal/domain/server.go b/internal/domain/server.go index 0246bae..b66b690 100644 --- a/internal/domain/server.go +++ b/internal/domain/server.go @@ -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 { diff --git a/internal/domain/tribe.go b/internal/domain/tribe.go index 2b06c83..a0d0642 100644 --- a/internal/domain/tribe.go +++ b/internal/domain/tribe.go @@ -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 diff --git a/internal/domain/tribe_change.go b/internal/domain/tribe_change.go index 2447435..3ac5a46 100644 --- a/internal/domain/tribe_change.go +++ b/internal/domain/tribe_change.go @@ -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 diff --git a/internal/domain/tribe_snapshot.go b/internal/domain/tribe_snapshot.go index 1afedcf..6a97256 100644 --- a/internal/domain/tribe_snapshot.go +++ b/internal/domain/tribe_snapshot.go @@ -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 diff --git a/internal/domain/utils.go b/internal/domain/utils.go index 856e1dd..f2ff138 100644 --- a/internal/domain/utils.go +++ b/internal/domain/utils.go @@ -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] +} diff --git a/internal/domain/version.go b/internal/domain/version.go index 14ca043..20ba71f 100644 --- a/internal/domain/version.go +++ b/internal/domain/version.go @@ -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 { diff --git a/internal/domain/village.go b/internal/domain/village.go index 2af1593..1d31db8 100644 --- a/internal/domain/village.go +++ b/internal/domain/village.go @@ -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