Last active
August 29, 2015 14:13
-
-
Save xfyre/9d72eae57a460dba440b to your computer and use it in GitHub Desktop.
retrieveRankedList example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<ContestEntrance> retrieveRankedList ( Contest contest, ContestSignupRole role ) { | |
if ( !contest.isRandomPartnered () ) | |
throw new IllegalArgumentException ( "only applicable for random-partnered contests" ); | |
final List<ContestEntrance> list = new ArrayList<ContestEntrance> (); | |
final List<ContestRound> reverseRoundsList = new ArrayList<ContestRound> ( contest.getRounds () ); | |
Collections.reverse ( reverseRoundsList ); | |
for ( final ContestRound round : reverseRoundsList ) { | |
if ( !( round.isScored () || round.isFinished () ) ) | |
throw new IllegalArgumentException ( "all rounds must be scored" ); | |
if ( round.isFinal () ) { | |
if ( role == round.getDrawRole () ) { | |
list.addAll ( round.getRankedEntrances () ); | |
} else { | |
CollectionUtils.collect ( round.getRankedEntrances (), new Transformer () { | |
@Override | |
public Object transform ( Object input ) { | |
ContestEntrance entrance = (ContestEntrance) input; | |
return entrance.getDraw ().getPartnerEntrance (); | |
} | |
}, list ); | |
} | |
} else { | |
List<ContestEntrance> roundEntrances = round.getEntrancesSortedByCallbackScore ( role ); | |
CollectionUtils.select ( roundEntrances, new Predicate () { | |
@Override | |
public boolean evaluate ( Object object ) { | |
ContestEntrance entrance = (ContestEntrance) object; | |
return entrance.getRank () != null; | |
} | |
}, list ); | |
} | |
} | |
return list; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retrieveRankedList(contest: Contest, role: ContestSignupRole) = { | |
if (!contest.isRandomPartnered) | |
throw new IllegalArgumentException("only applicable for random-partnered contests"); | |
if (contest.getRounds.asScala.count(!_.isScored) > 0) | |
throw new IllegalArgumentException("all rounds must be scored"); | |
contest.getRounds.asScala.toList.reverse.flatMap(_.getContestEntrances.asScala) | |
.filter(_.getRank != null) | |
.filter(_.getContestSignup.getRole == role) | |
.sortBy(_.getRank) | |
.asJava | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment