@@ -77,6 +77,74 @@ public class ListProjectBranchesExample {
7777}
7878```
7979
80+ ### Sorting results
81+
82+ You can sort the results of ` list* ` methods by one or multiple fields using the ` OrderByField ` class.
83+ If sort direction is not specified, results will be sorted in ascending (` ASC ` ) order by default.
84+
85+ #### Example: Sort string comments by ` id ` descending
86+
87+ ``` java
88+ import com.crowdin.client.Client ;
89+ import com.crowdin.client.core.model.Credentials ;
90+ import com.crowdin.client.stringcomments.model.OrderByField ;
91+ import com.crowdin.client.stringcomments.model.SortOrder ;
92+ import com.crowdin.client.stringcomments.model.StringComment ;
93+
94+ import java.util.Collections ;
95+ import java.util.List ;
96+
97+ public class ListCommentsSortedExample {
98+
99+ public static void main (String [] args ) {
100+ Credentials credentials = new Credentials (" your-token" , " your-organization" );
101+ Client client = new Client (credentials);
102+
103+ OrderByField orderByIdDesc = new OrderByField ();
104+ orderByIdDesc. setFieldName(" id" );
105+ orderByIdDesc. setOrderBy(SortOrder . DESC ); // Optional: default is ASC
106+
107+ List<StringComment > comments = client
108+ .getStringCommentsApi()
109+ .listStringComments(
110+ 123L , // projectId
111+ null , null , null , null , null , null ,
112+ Collections . singletonList(orderByIdDesc)
113+ )
114+ .getData()
115+ .stream()
116+ .map(response - > response. getData())
117+ .toList();
118+
119+ comments. forEach(comment - > System . out. println(comment. getId()));
120+ }
121+
122+ }
123+ ```
124+ #### Example: Sort by multiple fields
125+
126+ You can also sort by multiple fields, for example: first by ` createdAt ` , then by ` id ` .
127+
128+ ``` java
129+ import java.util.Arrays ;
130+ import com.crowdin.client.stringcomments.model.OrderByField ;
131+ import com.crowdin.client.stringcomments.model.SortOrder ;
132+
133+ public class ListCommentsSortedExample {
134+
135+ public static void main (String [] args ) {
136+ OrderByField orderByCreatedAtAsc = new OrderByField ();
137+ orderByCreatedAtAsc. setFieldName(" createdAt" ); // ASC by default
138+
139+ OrderByField orderByIdDesc = new OrderByField ();
140+ orderByIdDesc. setFieldName(" id" );
141+ orderByIdDesc. setOrderBy(SortOrder . DESC );
142+
143+ List<OrderByField > orderBy = Arrays . asList(orderByCreatedAtAsc, orderByIdDesc);
144+ }
145+ }
146+ ```
147+
80148### Customization
81149
82150This client uses [ Apache http client] ( https://hc.apache.org/ ) and [ Jackson json library] ( https://github.com/FasterXML/jackson ) .
0 commit comments