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 class ModularExponent { | |
//ModularExponent | |
//An implementation of divide-and-conquer method of calculating modular exponents | |
//See Introduction to Algorithms, Corment et al. | |
//tested correct to (a,b,n) = (256,256,256) | |
public static int modularExponent(int a, int b, int n) { | |
if (a < 0 || b < 0 || n < 0) { | |
throw new IllegalArgumentException("Arguments must be positive integers"); | |
} |
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
class MainPresenter implements MainContract.Presenter { | |
private final PlayerRepository playerRepository; | |
private final GamesRepository gamesRepository; | |
private final MainContract.View view; | |
@Inject | |
MainPresenter(PlayerRepository playerRepository, GamesRepository gamesRepository, MainContract.View view) { | |
this.playerRepository = playerRepository; | |
this.gamesRepository = gamesRepository; |
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
ListenableFuture<Games> retrieveGames(String playerName) { | |
return FluentFuture.from(playerRepository.retrieve(playerName)) | |
.transformAsync( (player) -> gamesRepository.retrieve(player.id()), directExecutor()) | |
} |
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
Observable<Games> retrieveGames(String playerName) { | |
return playerRepository.retrieve(playerName) | |
.flatMap( (player) -> gamesRepository.retrieve(player.id())); | |
} |
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
class MainRequestHelper { | |
private final PlayerRepository playerRepository; | |
private final GamesRepository gamesRepository; | |
@Inject | |
public MainRequestHelper(PlayerRepository playerRepository, GamesRepository gamesRepository, StatisticsProcessor statisticsProcessor) { | |
this.playerRepository = playerRepository; | |
this.gamesRepository = gamesRepository; | |
} |
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
class MainPresenter implements MainContract.Presenter { | |
private final MainRequestHelper mainRequestHelper; | |
private final MainContract.View view; | |
@Inject | |
MainPresenter(MainRequestHelper mainRequestHelper, MainContract.View view) { | |
this.mainRequestHelper = mainRequestHelper; | |
this.view = view; | |
} |
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
@ProducerModule(includes = { PlayerRepositoryModule.class, GamesRepositoryModule.class, PlayerNameModule.class } ) | |
final class MainRequestModule { | |
@Produces | |
static ListenableFuture<Player> player(PlayerRepository playerRepository, String playerName) { | |
return playerRepository.retrieve(playerName); | |
} | |
@Produces | |
static ListenableFuture<Games> games(GamesRepository gamesRepository, Player player) { |
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
@ProductionComponent(modules = { MainRequestModule.class, ExecutorModule.class }) | |
interface MainRequestComponent { | |
ListenableFuture<Games> games(); | |
} |
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
void showGames(String playerName) { | |
MainRequestComponent component = DaggerMainRequestComponent.builder() | |
.playerNameModule(new PlayerNameModule(playerName)) | |
.build(); | |
ListenableFuture<Games> futureGames = component.games(); | |
futureGames.addCallback(...) //todo: show games using view | |
} |
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 MainRequestHelper(PlayerRepository playerRepository, GamesRepository gamesRepository, StatisticsProcessor statisticsProcessor) { | |
this.playerRepository = playerRepository; | |
this.gamesRepository = gamesRepository; | |
this.statisticsProcessor = statisticsProcessor; | |
} | |
ListenableFuture<Statistics> getStatistics(String username) { | |
return FluentFuture.from(playerRepository.retrieve(username)) | |
.transformAsync( (player) -> gamesRepository.retrieve(player.id()), directExecutor()) | |
.transform( (games) -> statisticsProcessor.process(games), directExecutor()); |
OlderNewer