Skip to content

Instantly share code, notes, and snippets.

@secondsun
Created April 4, 2013 14:47
Show Gist options
  • Save secondsun/dcf5682b6ff17c729d9a to your computer and use it in GitHub Desktop.
Save secondsun/dcf5682b6ff17c729d9a to your computer and use it in GitHub Desktop.
Junction Android
public interface Junction<Parent, Child> {
read(Parent parent, Callback<List<Child>> callback);
}
public JunctionApplication extends Application {
onCreate() {
Pipeline pipeline = new Pipeline();
pipeline.pipe(Player.class);
pipeline.pipe(Team.class);
}
getPlayers(Callback<List<Player>> callback) {
pipe.get("player").read(callback);
}
getTeams(Callback<List<Team>> callback) {
pipe.get("team").read(callback);
}
getPlayersOnTeam(Team team, Callback<List<Player>> callback) {
pipe.junction("team","player").read(team, callback);
}
getTeamsPlayerHasPlayerFor(Player player, Callback<List<Team>> callback) {
pipe.junction("player","team").read(player, callback);
}
}
class Player {
@RecordId
Long id;
String name;
List<Team> teamsPlayedFor;
Team currentTeam;
}
class Team {
@RecordId
Long id;
String name;
List<Player> currentPlayers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment