[LIB-5] Site sources of snooker-score-api
[snooker-score-api.git] / src / site / apt / examples / use-sort-in-collections.apt.vm
1  ------
2  Using sorting of received data
3  ------
4  Dmitry Samoshin aka gotty
5  ------
6  2017-01-27
7  ------
8
9 ~~ Copyright (c) 2017. Developed by Hedgecode.
10 ~~
11 ~~ Licensed under the Apache License, Version 2.0 (the "License");
12 ~~ you may not use this file except in compliance with the License.
13 ~~ You may obtain a copy of the License at
14 ~~
15 ~~   http://www.apache.org/licenses/LICENSE-2.0
16 ~~
17 ~~ Unless required by applicable law or agreed to in writing, software
18 ~~ distributed under the License is distributed on an "AS IS" BASIS,
19 ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 ~~ See the License for the specific language governing permissions and
21 ~~ limitations under the License.
22
23 ~~ NOTE: For help with the syntax of this file, see:
24 ~~ http://maven.apache.org/doxia/references/apt-format.html
25
26 Using sorting of received data
27
28   The data obtained from the API methods calls of the main interface of the library,
29   in most cases, represent collection classes (<<<Players>>>, <<<Events>>>, <<<Matches>>>) 
30   which can be sorted by certain parameters for convenience of further use in client applications.
31
32   The types of possible sorts for specific collection classes are listed below.
33
34 ===
35
36   <<<Players>>> - entity class which contains a selection of players on certain parameters.\
37   This class provides two types of sorting:
38
39   <<1.>> Sorting players by name.
40
41   <<2.>> Sorting players by age, both in descending order and in ascending order.
42
43   Java code that shows all the above sorting methods is presented below:
44
45 +-------
46 Players players = Snooker.API().getPlayers(...);
47 ...
48 players.sortByName();
49 ...
50 players.sortByAge();
51 players.sortByAgeDesc();
52 ...
53 +-------
54
55 ===
56
57   <<<Events>>> - entity class which contains a selection of tournaments for certain parameters.
58
59   Java code that shows the sorting of tournaments by date is presented below:
60
61 +-------
62 Events events = Snooker.API().getSeasonEvents((...);
63 ...
64 events.sortByDate();
65 ...
66 +-------
67
68 ===
69
70   <<<Matches>>> - entity class which contains a selection of matches for certain parameters.\
71   This class provides two types of sorting:
72
73   <<1.>> Sorting matches by number.\
74   This sorting type will be useful when the selection contains all the matches of a single tournament.
75
76   <<2.>> Sorting matches by tournament.\
77   This sorting type will be useful when the selection contains all the matches
78   of an individual player for the season in different tournaments.
79
80   Java code that shows all the above sorting methods is presented below:
81
82 +-------
83 Matches matches = Snooker.API().getEventMatches((...);
84 ...
85 matches.sortByNumber();
86 ...
87 matches.sortByEvent();
88 ...
89 +-------