|
37 | 37 | import java.util.*; |
38 | 38 |
|
39 | 39 | import static java.util.Arrays.asList; |
| 40 | +import static org.apache.commons.lang.ObjectUtils.defaultIfNull; |
40 | 41 |
|
41 | 42 | /** |
42 | 43 | * A repository on GitHub. |
@@ -512,27 +513,34 @@ public void delete() throws IOException { |
512 | 513 | /** |
513 | 514 | * Sort orders for listing forks |
514 | 515 | */ |
515 | | - public static enum Sort { NEWEST, OLDEST, STARGAZERS } |
| 516 | + public static enum ForkSort { NEWEST, OLDEST, STARGAZERS } |
516 | 517 |
|
517 | 518 | /** |
518 | | - * Lists all the direct forks of this repository, sorted by {@link Sort#NEWEST Sort.NEWEST} |
| 519 | + * Lists all the direct forks of this repository, sorted by |
| 520 | + * github api default, currently {@link ForkSort#NEWEST ForkSort.NEWEST}. |
519 | 521 | */ |
520 | 522 | public PagedIterable<GHRepository> listForks() { |
521 | 523 | return listForks(null); |
522 | 524 | } |
523 | 525 |
|
524 | 526 | /** |
525 | 527 | * Lists all the direct forks of this repository, sorted by the given sort order. |
526 | | - * @param sort the sort order. If null, defaults to {@link Sort#NEWEST Sort.NEWEST}. |
| 528 | + * @param sort the sort order. If null, defaults to github api default, |
| 529 | + * currently {@link ForkSort#NEWEST ForkSort.NEWEST}. |
527 | 530 | */ |
528 | | - public PagedIterable<GHRepository> listForks(final Sort sort) { |
| 531 | + public PagedIterable<GHRepository> listForks(final ForkSort sort) { |
529 | 532 | return new PagedIterable<GHRepository>() { |
530 | 533 | public PagedIterator<GHRepository> iterator() { |
531 | | - return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + ((sort == null)?"":("?sort="+sort.toString().toLowerCase(Locale.ENGLISH)))), GHRepository[].class)) { |
| 534 | + String sortParam = ""; |
| 535 | + if (sort != null) { |
| 536 | + sortParam = "?sort=" + sort.toString().toLowerCase(Locale.ENGLISH); |
| 537 | + } |
| 538 | + return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + sortParam), GHRepository[].class)) { |
532 | 539 | @Override |
533 | 540 | protected void wrapUp(GHRepository[] page) { |
534 | | - for (GHRepository c : page) |
| 541 | + for (GHRepository c : page) { |
535 | 542 | c.wrap(root); |
| 543 | + } |
536 | 544 | } |
537 | 545 | }; |
538 | 546 | } |
|
0 commit comments