7from .strategy_isortentries
import ISortEntries, SortOptions
8from .strategy_entryinformation
import EntryInformation
19 def __init__(self, reversedSort : bool) ->
None:
36 def Sort(self, entries : list[EntryInformation]) ->
None:
37 entries.sort(reverse=self.
_reversedSort, key=
lambda entry : entry.Name)
43 return "Strategy_SortEntries_ByName"
58 def __init__(self, reversedSort : bool) ->
None:
75 def Sort(self, entries : list[EntryInformation]) ->
None:
76 entries.sort(reverse=self.
_reversedSort, key=
lambda entry : entry.Age)
82 return "Strategy_SortEntries_ByAge"
97 def __init__(self, reversedSort : bool) ->
None:
114 def Sort(self, entries : list[EntryInformation]) ->
None:
115 entries.sort(reverse=self.
_reversedSort, key=
lambda entry : entry.Height)
121 return "Strategy_SortEntries_ByHeight"
141 case SortOptions.ByName:
142 optionAsString =
"ByName"
144 case SortOptions.ByAge:
145 optionAsString =
"ByAge"
147 case SortOptions.ByHeight:
148 optionAsString =
"ByHeight"
151 optionAsString =
"Unknown {0}".format(int(sortOption))
153 return optionAsString
171 def Create(sortOption : SortOptions, reversedSort : bool) -> ISortEntries:
175 case SortOptions.ByName:
178 case SortOptions.ByAge:
181 case SortOptions.ByHeight:
185 message =
"Unrecognized sort option: {0}".format(Strategy_SortEntries_ClassFactory._SortOptionToString(sortOption))
186 raise ValueError(message)
Represents a sorting strategy.
Strategy for sorting the ages in ascending (or descending) order.
str ToString(self)
Return a stringized version of this class.
None Sort(self, list[EntryInformation] entries)
Sort the specified list of entries in place.
None __init__(self, bool reversedSort)
Constructor.
_reversedSort
Controls order of sort: true for descending, false for ascending.
Strategy for sorting the heights in ascending (or descending) order.
str ToString(self)
Return a stringized version of this class.
None Sort(self, list[EntryInformation] entries)
Sort the specified list of entries in place.
None __init__(self, bool reversedSort)
Constructor.
_reversedSort
Controls order of sort: true for descending, false for ascending.
Strategy for sorting the names in ascending (or descending) order.
str ToString(self)
Return a stringized version of this class.
None Sort(self, list[EntryInformation] entries)
Sort the specified list of entries in place.
None __init__(self, bool reversedSort)
_reversedSort
Controls order of sort: true for descending, false for ascending.
Holds the class factory for the sorting strategies.
ISortEntries Create(SortOptions sortOption, bool reversedSort)
Generate an instance of a sorting strategy based on the given sorting option and reversed sort flag.
str _SortOptionToString(SortOptions sortOption)
Convert a SortOptions enumeration to a string.