List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:android.math.practice.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;/*from w w w. j a v a 2s . c o m*/ for (i = 0; i < NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < NUM_COLS; j++) { listRowAdapter.add(list.get(j % 5)); } HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES"); GridItemPresenter mGridPresenter = new GridItemPresenter(); ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter); gridRowAdapter.add(getResources().getString(R.string.grid_view)); gridRowAdapter.add(getString(R.string.error_fragment)); gridRowAdapter.add(getResources().getString(R.string.personal_settings)); mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); setAdapter(mRowsAdapter); }
From source file:com.amazon.lab.usbphotoviewer.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;//from ww w . j a v a2 s .c o m for (i = 0; i < NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < list.size(); j++) { if ((i == 0 && !list.get(j).isUhd()) || (i == 1 && list.get(j).isUhd())) listRowAdapter.add(list.get(j)); } HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES"); GridItemPresenter mGridPresenter = new GridItemPresenter(); ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter); gridRowAdapter.add(getResources().getString(R.string.grid_view)); gridRowAdapter.add(getString(R.string.error_fragment)); gridRowAdapter.add(getResources().getString(R.string.personal_settings)); //mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); setAdapter(mRowsAdapter); }
From source file:com.example.android.AudioArchive.model.MusicProvider.java
/** * Get an iterator over a shuffled collection of all songs *//* w w w .j a va 2 s . c o m*/ public Iterable<MediaMetadataCompat> getShuffledMusic() { if (mCurrentState != State.INITIALIZED) { return Collections.emptyList(); } List<MediaMetadataCompat> shuffled = new ArrayList<>(mMusicListById.size()); for (MutableMediaMetadata mutableMetadata : mMusicListById.values()) { shuffled.add(mutableMetadata.metadata); } Collections.shuffle(shuffled); return shuffled; }
From source file:com.android.tv.leanback.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;//from ww w. j a v a2s . c o m for (i = 0; i < NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < NUM_COLS; j++) { listRowAdapter.add(list.get(j % 5)); } HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } HeaderItem gridHeader = new HeaderItem(i, ""); GridItemPresenter mGridPresenter = new GridItemPresenter(); ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter); gridRowAdapter.add(getResources().getString(R.string.grid_view)); gridRowAdapter.add(getString(R.string.error_fragment)); gridRowAdapter.add(getResources().getString(R.string.personal_settings)); myView = new MyTestView(getActivity().getBaseContext()); /*myView.setText("dsdsds"); gridRowAdapter.add(myView);*/ mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); setAdapter(mRowsAdapter); }
From source file:org.jboss.examples.camel.MessageResequencerTest.java
@Test(timeout = 30000L) public void testUnorderedMessages() throws Exception { List<Integer> unorderedMessages = new ArrayList<>(); for (int i = 0; i < 10; ++i) { unorderedMessages.add(i);/*from w w w . j a va2s .c o m*/ } Collections.shuffle(unorderedMessages); for (Integer message : unorderedMessages) { log.info(String.format("Sending message #%s...", message)); activemq.sendBodyAndHeader(message, "MyGroupingID", 1); } mock.expectedMessageCount(10); mock.expectsAscending().simple("${body}"); mock.await(30, TimeUnit.SECONDS); mock.assertIsSatisfied(); }
From source file:com.github.lukaszbudnik.gugis.GugisReplicatorInterceptor.java
@Override public Object invoke(MethodInvocation i) throws Throwable { if (log.isDebugEnabled()) { log.debug(//from ww w . j a v a 2s . com "Method " + i.getMethod() + " is called on " + i.getThis() + " with args " + i.getArguments()); } Propagate propagate = i.getMethod().getDeclaredAnnotation(Propagate.class); Class clazz = i.getMethod().getDeclaringClass().getInterfaces()[0]; if (log.isDebugEnabled()) { log.debug("About to find bindings for " + clazz); log.debug("Propagation set to " + propagate.propagation()); log.debug("Allow failure set to " + propagate.allowFailure()); } List<Binding<Object>> bindings = injector.findBindingsByType(TypeLiteral.get(clazz)); if (bindings.size() == 0) { log.error("No bindings found for " + clazz); throw new GugisException("No bindings found for " + clazz); } if (log.isDebugEnabled()) { log.debug("Found " + bindings.size() + " bindings for " + clazz); } Stream<Try<Object>> resultStream = Stream.empty(); switch (propagate.propagation()) { case FASTEST: { Stream<Try<Object>> executedStream = executeBindings(propagate.allowFailure(), bindings.stream(), i.getMethod().getName(), i.getArguments()); Optional<Try<Object>> anyResult = executedStream.filter(t -> t.isSuccess()).findAny(); resultStream = anyResult.isPresent() ? Stream.of(anyResult.get()) : Stream.<Try<Object>>empty(); break; } case PRIMARY: { Stream<Binding<Object>> filtered = bindings.stream() .filter(b -> b.getProvider().get().getClass().isAnnotationPresent(Primary.class)); resultStream = executeBindings(propagate.allowFailure(), filtered, i.getMethod().getName(), i.getArguments()); break; } case SECONDARY: { Stream<Binding<Object>> filtered = bindings.stream() .filter(b -> b.getProvider().get().getClass().isAnnotationPresent(Secondary.class)); resultStream = executeBindings(propagate.allowFailure(), filtered, i.getMethod().getName(), i.getArguments()); break; } case RANDOM: { ArrayList<Binding<Object>> modifiableBindings = new ArrayList<>(bindings); Collections.shuffle(modifiableBindings); for (Binding<Object> binding : modifiableBindings) { Stream<Try<Object>> executedStream = executeBindings(propagate.allowFailure(), Stream.of(binding), i.getMethod().getName(), i.getArguments()); Optional<Try<Object>> anyResult = executedStream.filter(t -> t.isSuccess()).findFirst(); if (anyResult.isPresent()) { resultStream = Stream.of(anyResult.get()); break; } } break; } default: { // handles ALL Stream<Binding<Object>> bindingStream = bindings.stream(); resultStream = executeBindings(propagate.allowFailure(), bindingStream, i.getMethod().getName(), i.getArguments()); break; } } List<Try<Object>> tries = resultStream.collect(Collectors.toList()); List<Try<Object>> successes = tries.stream().filter(t -> t.isSuccess()).collect(Collectors.toList()); if (successes.size() == 0) { String errorMessage = ErrorMessageBuilder .buildErrorMessageFromTries("No result for " + propagate.propagation() + " found for " + clazz.getCanonicalName() + "." + i.getMethod().getName(), tries); throw new GugisException(errorMessage); } // all implementations should be homogeneous and should return same value for same arguments Try<Object> tryObject = successes.get(0); if (log.isDebugEnabled()) { log.debug("Method " + i.getMethod() + " returns " + tryObject.get()); } return tryObject.get(); }
From source file:com.hackday.andy.jztv.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); // ListRowPresenter ?? mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;//from w ww . j av a2 s .com for (i = 0; i < NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < NUM_COLS; j++) { // 5/row listRowAdapter.add(list.get(j % 5)); } HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES"); GridItemPresenter mGridPresenter = new GridItemPresenter(); ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter); gridRowAdapter.add(getResources().getString(R.string.grid_view)); gridRowAdapter.add(getString(R.string.error_fragment)); gridRowAdapter.add(getResources().getString(R.string.personal_settings)); mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); // browser fragmentadapter setAdapter(mRowsAdapter); }
From source file:com.publicuhc.uhcaddons.teammanager.commands.RandomTeamsCommand.java
@CommandMethod("randomteams") @PermissionRestriction(RANDOM_TEAMS_PERMISSION) @CommandOptions("n") public void onRandomTeams(OptionSet set, CommandSender sender, Integer amount) { if (amount < 1) { translate.sendMessage("greater than zero", sender); return;// w w w. j av a 2 s . c o m } List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers()); Collections.shuffle(players); Iterator<Player> playerIterator = players.iterator(); while (playerIterator.hasNext()) { if (scoreboard.getPlayerTeam(playerIterator.next()) != null) { playerIterator.remove(); } } if (amount <= players.size()) { translate.sendMessage("not enough players online", sender, players.size()); return; } List<List<Player>> splitup = split(players, amount); for (List<Player> teamGroup : splitup) { Team newTeam = manager.getNewTeam(true); Collection<String> playerNames = Lists.newArrayList(); for (OfflinePlayer p : teamGroup) { playerNames.add(p.getName()); } for (Player p : teamGroup) { newTeam.addPlayer(p); } manager.sendToTeamTranslated(newTeam, "your team", Joiner.on(",").join(playerNames)); } translate.sendMessage("created", sender, splitup.size()); }
From source file:com.appdevper.mediaplayer.util.QueueHelper.java
/** * Create a random queue.//from w ww .j av a 2s.co m * * @param musicProvider the provider used for fetching music. * @return list containing {@link MediaSession.QueueItem}'s */ public static List<MediaSessionCompat.QueueItem> getRandomQueue(MusicProvider musicProvider) { List<MediaMetadataCompat> result = new ArrayList<>(); for (String genre : musicProvider.getGenres()) { Iterable<MediaMetadataCompat> tracks = musicProvider.getMusicsByGenre(genre); for (MediaMetadataCompat track : tracks) { if (ThreadLocalRandom.current().nextBoolean()) { result.add(track); } } } LogHelper.d(TAG, "getRandomQueue: result.size=", result.size()); Collections.shuffle(result); return convertToQueue(result, MediaIDHelper.MEDIA_ID_MUSICS_BY_SEARCH, "random"); }
From source file:com.ancho.tv.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;/*from w w w . j a v a2s . c o m*/ for (i = 0; i < NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < NUM_COLS; j++) { listRowAdapter.add(list.get(j % 5)); } HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]); mRowsAdapter.add(new ListRow(header, listRowAdapter)); } HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES"); GridItemPresenter mGridPresenter = new GridItemPresenter(); ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter); gridRowAdapter.add(getResources().getString(R.string.grid_view)); gridRowAdapter.add(getString(R.string.error_fragment)); gridRowAdapter.add(getResources().getString(R.string.personal_settings)); mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); // mRowsAdapter.replace(); setAdapter(mRowsAdapter); }