List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:com.eightmins.eightminutes.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;/* w w w . j av a 2s .com*/ for (i = 0; i < MainFragment.NUM_ROWS; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < MainFragment.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(string.grid_view)); gridRowAdapter.add(getString(string.error_fragment)); gridRowAdapter.add(getResources().getString(string.personal_settings)); mRowsAdapter.add(new ListRow(gridHeader, gridRowAdapter)); setAdapter(mRowsAdapter); }
From source file:com.example.hp.smartstor.CloudMusicManager.uamp.model.MusicProvider.java
/** * Get an iterator over a shuffled collection of all songs *//* w w w. ja va 2 s .co m*/ public Iterable<MediaMetadataCompat> getShuffledMusic() { if (mCurrentState != State.INITIALIZED) { return Collections.emptyList(); } List<MediaMetadataCompat> shuffled = new ArrayList<>(mMusicListById.size()); for (com.example.hp.smartstor.CloudMusicManager.uamp.model.MutableMediaMetadata mutableMetadata : mMusicListById .values()) { shuffled.add(mutableMetadata.metadata); } Collections.shuffle(shuffled); return shuffled; }
From source file:com.androidtv_test.view.main.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); //?// w w w.j a va 2 s . co m mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); CardPresenter cardPresenter = new CardPresenter();//? int i; 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:android.test.com.quxuetv.ibrowse.test.MainFragment.java
private void loadRows() { List<Movie> list = MovieList.setupMovies(); // mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(new CustomListRowPresenter()); CardPresenter cardPresenter = new CardPresenter(); int i;/* w ww. java 2 s . co 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)); } MyHeaderItem header = new MyHeaderItem(i, MovieList.MOVIE_CATEGORY[i], R.drawable.ic_add_white_48dp); CustomListRow mClr = new CustomListRow(header, listRowAdapter); mClr.setmNums(1); mRowsAdapter.add(mClr); } // HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES"); MyHeaderItem gridHeader = new MyHeaderItem(i, "PREFERENCES", R.drawable.ic_add_white_48dp); 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 CustomListRow(gridHeader, gridRowAdapter)); setAdapter(mRowsAdapter); }
From source file:de.unisb.cs.st.javalanche.mutation.run.task.MutationTaskCreator.java
/** * Generates given number of mutation task, where each task consists of a * given number of mutations. Note: The MutationProperties.PROJECT_PREFIX * variable has to be set.//from ww w. j ava 2s . c om * * @param numberOfTasks * number of tasks that should be created * @param mutationsPerTask * number of mutations per task * @throws IOException */ public static void createMutationTasks(int numberOfTasks, int mutationsPerTask) throws IOException { String prefix = ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix(); int numberOfIds = numberOfTasks * mutationsPerTask; List<Long> mutationIds = getMutations(prefix, numberOfIds); Collections.shuffle(mutationIds); int i = 1; for (; i <= numberOfTasks; i++) { List<Long> idsForTask = new ArrayList<Long>(); if (mutationIds.size() >= mutationsPerTask) { idsForTask.addAll(mutationIds.subList(0, mutationsPerTask)); } else { logger.info("Not enough mutations fetched from db"); idsForTask.addAll(mutationIds); } mutationIds.removeAll(idsForTask); if (idsForTask.size() > 0) { writeListToFile(idsForTask, i, numberOfTasks); } else { logger.info("No more mutations. Finishing after file " + (i - 1)); break; } } i = i - 1; System.out.println("Created " + i + " mutation tasks"); }
From source file:eu.eubrazilcc.lvl.core.GbSeqXmlFileTest.java
@Test public void test() { System.out.println("GbSeqXmlFileTest.test()"); try {/*w w w .jav a2 s.c o m*/ File output = null; String payload = null; // test writing individual FASTA files (uncompressed) final Collection<File> files = getGBSeqXMLFiles(); for (final File file : files) { System.out.println(" >> Sequence file: " + file.getCanonicalPath()); output = new File(TEST_OUTPUT_DIR, "sequence.fasta"); toFasta(file, output.getCanonicalPath(), false); assertThat("fasta sequence file exists: " + output.getCanonicalPath(), output.canRead(), equalTo(true)); payload = readFileToString(output); assertThat("fasta sequence is not null", payload, notNullValue()); assertThat("fasta sequence is not empty", isNotBlank(payload), equalTo(true)); /* uncomment for additional output */ System.out.println(" >> FASTA sequence \n" + payload); } // test writing a single FASTA file (uncompressed) output = new File(TEST_OUTPUT_DIR, "sequences.fasta"); toFasta(files, output.getCanonicalPath(), false); assertThat("fasta sequences file exists: " + output.getCanonicalPath(), output.canRead(), equalTo(true)); payload = readFileToString(output); assertThat("fasta sequences is not null", payload, notNullValue()); assertThat("fasta sequences is not empty", isNotBlank(payload), equalTo(true)); /* uncomment for additional output */ System.out.println(" >> FASTA sequences \n" + payload); // test writing a FASTA file (compressed) final List<File> list = newArrayList(files); Collections.shuffle(list); final File file = list.get(0); output = new File(TEST_OUTPUT_DIR, "sequence.fasta.gz"); toFasta(file, output.getCanonicalPath(), false); assertThat("fasta GZIP compressed file exists: " + output.getCanonicalPath(), output.canRead(), equalTo(true)); assertThat("fasta GZIP compressed file is not empty", output.length() > 0l, equalTo(true)); } catch (Exception e) { e.printStackTrace(System.err); fail("GbSeqXmlFileTest.test() failed: " + e.getMessage()); } finally { System.out.println("GbSeqXmlFileTest.test() has finished"); } }
From source file:com.pureinfo.tgirls.servlet.GetPicArrServlet.java
@Override protected void doGet(HttpServletRequest _req, HttpServletResponse _resp) throws ServletException, IOException { String type = _req.getParameter("pictype"); String s = _req.getParameter("size"); String sstartIndex = _req.getParameter("startIndex"); if (StringUtils.isEmpty(s)) { s = "50"; }/*ww w . java2 s. c om*/ if (StringUtils.isEmpty(sstartIndex)) { sstartIndex = "0"; } int startIndex = Integer.parseInt(sstartIndex); int resultsize = Integer.parseInt(s); logger.debug("to get pics with type:" + type + " and size:" + resultsize); _resp.setContentType("text/json; charset=utf-8"); JsonBase json = new JsonBase(); //List<Photo> result = new ArrayList<Photo>(); List<Photo> cacheList = null; if ((cacheList = (List<Photo>) cache.get("pics." + type)) == null) { try { startIndex = 0; IPhotoMgr mgr = (IPhotoMgr) ArkContentHelper.getContentMgrOf(Photo.class); if (StringUtils.isEmpty(type)) { cacheList = mgr.getRandomPics(500); } else { cacheList = mgr.getRandomPics(Integer.parseInt(type), 500); } if (cacheList != null) { cache.put("pics." + type, cacheList); } } catch (PureException e) { logger.error("error when get pics.", e); } } if (cacheList == null || cacheList.isEmpty()) { json.setErrorCode(ErrorCode.ERROR.getCode()); json.setErrorMsg(""); _resp.getWriter().write(json.toString()); return; } //Collections.shuffle(cacheList); //result.addAll(cacheList); //if (resultsize < result.size()) { // result.subList(0, resultsize); //} try { Photo photo; List<JSONObject> jsonList = new ArrayList<JSONObject>(); int temp = 0; int i = 0; if (startIndex == 0) { startIndex = new Random().nextInt(cacheList.size()); } Iterator<Photo> itor = new LoopingIterator(cacheList); while (itor.hasNext() && i < resultsize) { photo = itor.next(); if (temp < startIndex) { logger.debug("currentIndex[" + temp + "] and startIndex[" + startIndex + "]"); temp++; continue; } logger.debug("to add photo[" + photo + "]"); jsonList.add(new JSONObject(photo)); i++; } Collections.shuffle(jsonList); json.put("pics", jsonList); json.put("nextIndex", startIndex + resultsize); } catch (JSONException e) { throw new RuntimeException(); } // logger.debug("result:" + json.toString()); _resp.getWriter().write(json.toString()); return; }
From source file:com.kaltura.playkit.samples.androidtv.MainFragment.java
private void loadRows() { List<Movie> list = MainActivity.list; CardPresenter cardPresenter = new CardPresenter(); int i;//w w w. j a v a2 s .com for (i = 0; i < MOVIE_CATEGORY.length; i++) { if (i != 0) { Collections.shuffle(list); } ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter); for (int j = 0; j < list.size(); j++) { listRowAdapter.add(list.get(j % (list.size()))); } HeaderItem header = new HeaderItem(i, 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)); }
From source file:mobi.designmyapp.template.sample.upvprod.task.PoiProxyRequestTask.java
/** * Retrieves the PoiProxy data and processes mapping of the JSON response to a PoiProxyResult POJO * @param url should contain the url call to PoiProxy services * @return/*from ww w . j a va 2 s .c o m*/ */ @Override protected PoiProxyResult doInBackground(URI... url) { PoiProxyResult result = null; HttpClient client = new DefaultHttpClient(); //For each URI provided, we call and get the result for (URI callURI : url) { // Process http request try { HttpGet request = new HttpGet(callURI); HttpResponse response = client.execute(request); StatusLine statusLine = response.getStatusLine(); // If request has returned correctly, process JSON if (statusLine.getStatusCode() == HttpStatus.SC_OK) { InputStream resultStream = response.getEntity().getContent(); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); // If first call, the result is the object if (result == null) result = mapper.readValue(resultStream, PoiProxyResult.class); // Otherwise, add the results to the previous result else result.getFeatures() .addAll(mapper.readValue(resultStream, PoiProxyResult.class).getFeatures()); resultStream.close(); } else { //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (IOException e) { Log.e(TAG, "Error while retrieving POI Proxy query: " + callURI + " data:" + e); } } if (result != null) Collections.shuffle(result.getFeatures()); return result; }
From source file:com.linkedin.pinot.tools.query.comparison.StarTreeQueryGenerator.java
/** * Randomly generate the WHERE clause of the query, may return empty string * @return// w ww.j a v a 2s.co m */ private String generatePredicates() { int numDimensions = _dimensionColumns.size(); int numPredicates = _random.nextInt(numDimensions + 1); numPredicates = Math.min(numPredicates, MAX_NUM_PREDICATES); if (numPredicates == 0) { return EMPTY_STRING; } List<String> predicates = new ArrayList<>(numPredicates); Collections.shuffle(_dimensionColumns); for (int i = 0; i < numPredicates; i++) { predicates.add(generatePredicate(_dimensionColumns.get(i))); } return WHERE + " " + StringUtils.join(predicates, " AND "); }