List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:de.jackwhite20.japs.shared.nio.NioSocketClient.java
public NioSocketClient(List<ClusterServer> clusterServers, String name) { // Randomize the list to give a chance for a better use of the cluster Collections.shuffle(clusterServers); if (name == null || name.isEmpty()) { throw new IllegalArgumentException("name cannot be null or empty"); }// ww w .j ava2s .co m this.clusterServers = clusterServers; this.name = name; ClusterServer first = clusterServers.get(0); this.host = first.host(); this.port = first.port(); if (!connect(host, port)) { throw new ConnectException("cannot initially connect to " + first.host() + ":" + first.port()); } }
From source file:com.github.fge.uritemplate.ExtendedTestsTest.java
@DataProvider public Iterator<Object[]> getData() { final List<Object[]> list = Lists.newArrayList(); VariableMapBuilder builder;/* w w w . j a va 2s. c o m*/ Iterator<Map.Entry<String, JsonNode>> iterator; Map.Entry<String, JsonNode> entry; for (final JsonNode node : data) { // Cycle through values if (node.path("disabled").asBoolean(false)) continue; builder = VariableMap.newBuilder(); iterator = node.get("variables").fields(); while (iterator.hasNext()) { entry = iterator.next(); if (entry.getValue().isNull()) continue; builder.addValue(entry.getKey(), Util.fromJson(entry.getValue())); } for (final JsonNode n : node.get("testcases")) list.add(new Object[] { n.get(0).textValue(), builder.freeze(), n.get(1) }); } Collections.shuffle(list); return list.iterator(); }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.tiers.TierMap.java
/** * Gets a random {@link Tier} out of the ones loaded on the server using chance. Returns null if none found. * * @return random Tier/*from www . j av a 2 s .co m*/ */ public Tier getRandomWithChance() { double totalWeight = 0; List<Tier> v = new ArrayList<>(values()); Collections.shuffle(v); for (Tier t : v) { totalWeight += t.getSpawnChance(); } double chosenWeight = MythicDropsPlugin.getInstance().getRandom().nextDouble() * totalWeight; double currentWeight = 0; for (Tier t : v) { currentWeight += t.getSpawnChance(); if (currentWeight >= chosenWeight) { return t; } } return null; }
From source file:com.pzy.jcook.project.web.FrontController.java
@RequestMapping("exam") public String exam(Model model, HttpServletRequest req) { User user = (User) req.getSession().getAttribute("webuser"); if (user == null) { model.addAttribute("tip", "?"); return "web/car"; }/*from ww w. j ava 2s . co m*/ List<Exam> exams = examService.findAll(); Collections.shuffle(exams); model.addAttribute("exams", exams); return "web/exam"; }
From source file:cz.fi.muni.pa165.service.GameServiceImpl.java
@Override public List<List<Pair>> generateSeasonMatches() { List<List<Pair>> result = new ArrayList<>(); List<Team> teams = teamDao.findByAll(); Collections.shuffle(teams); //add ghost team if odd number of teams if (teams.size() % 2 != 0) teams.add(new Team(-1L)); //round robin for (int i = 0; i < teams.size() - 1; i++) { List<Pair> row = new ArrayList<>(); for (int j = 0; j < teams.size() / 2; j++) { if (teams.get(j).getId() != -1L && teams.get(teams.size() - j - 1).getId() != -1L) row.add(new Pair(teams.get(j), teams.get(teams.size() - j - 1))); }//w w w .j av a2 s. c om result.add(row); Team t = teams.remove(teams.size() - 1); teams.add(1, t); } Collections.shuffle(result); return result; }
From source file:org.flite.cach3.test.l2.L2InvalidateMultiTest.java
@Test public void test() { final TestSvc test = (TestSvc) context.getBean("testSvc"); final String g1 = RandomStringUtils.randomAlphabetic(4) + "-"; final List<Long> ids = new ArrayList<Long>(); final long base = System.currentTimeMillis() - 200000; for (int ix = 0; ix < 10; ix++) { ids.add(base + ix);//from w ww. j a va 2 s . c o m } final List<Long> addls = new ArrayList<Long>(); addls.addAll(ids); for (int ix = 0; ix < 10; ix++) { addls.add(1000L + ix); } Collections.shuffle(addls); // Set the base expectations final List<String> first = test.getL2MultiAlpha(addls, g1); for (final String out : first) { assertTrue(out.startsWith(g1)); } // Now call the invalidate test.invalidateL2MultiCharlie(ids); // Only the invalidated ones should be different. Collections.shuffle(addls); final String g2 = RandomStringUtils.randomAlphabetic(8) + "-"; final List<String> results = test.getL2MultiAlpha(addls, g2); assertTrue(results.size() > 0); for (int ix = 0; ix < addls.size(); ix++) { final Long key = addls.get(ix); final String result = results.get(ix); assertTrue(StringUtils.contains(result, key.toString())); assertTrue("Key: " + key, result.startsWith(ids.contains(key) ? g2 : g1)); } }
From source file:com.mythesis.profileanalysis.Evaluate.java
public Evaluate(String outputDirectory, List<Integer> nTopics, List<Double> beta, int niters, int top_words, String LDAdir, double testSplit) { this.outputDirectory = outputDirectory; this.nTopics = new ArrayList<>(); this.alpha = new ArrayList<>(); this.beta = new ArrayList<>(); this.nTopics = nTopics; for (Integer nTopic : nTopics) { this.alpha.add((double) (50 / nTopic)); }//from ww w . j a va 2s .c om this.beta = beta; this.niters = niters; this.top_words = top_words; logLikelihoods = new ArrayList<>(); trainingSet = new ArrayList<>(); testSet = new ArrayList<>(); File ldaFile = new File(LDAdir); List<String> pages = new ArrayList<>(); try { pages = FileUtils.readLines(ldaFile); } catch (IOException ex) { Logger.getLogger(Evaluate.class.getName()).log(Level.SEVERE, null, ex); } pages.remove(0); //shuffle pages Collections.shuffle(pages); int testSetSize = (int) (pages.size() * testSplit); int trainingSetSize = pages.size() - testSetSize; int counter = 0; Random rn = new Random(); testSet.add(String.valueOf(testSetSize)); trainingSet.add(String.valueOf(trainingSetSize)); while (counter < testSetSize) { int index = rn.nextInt(pages.size()); if (!testSet.contains(pages.get(index))) { testSet.add(pages.get(index)); pages.remove(index); counter++; } } trainingSet.addAll(pages); }
From source file:com.weavers.duqhan.controller.WebController.java
@RequestMapping(value = "/scraping", method = RequestMethod.GET) // scraping product from list @ResponseBody//from w w w . j ava 2 s. co m public String scraping(@RequestParam int start, @RequestParam int limit) { List<StatusBean> statusBeans = new ArrayList<>(); for (int i = start; i < start + limit; i++) { StatusBean bean = new StatusBean(); bean.setId(Long.valueOf(i)); statusBeans.add(bean); } Collections.shuffle(statusBeans); productService.loadTempProducts(statusBeans); return "wait'n watch.."; }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.TierUtil.java
public static Tier randomTierWithIdentifyChance(Collection<Tier> values) { Validate.notNull(values, "Collection<Tier> cannot be null"); double totalWeight = 0; List<Tier> v = new ArrayList<>(values); Collections.shuffle(v); for (Tier t : v) { totalWeight += t.getIdentifyChance(); }//w w w . ja v a 2 s . c om double chosenWeight = MythicDropsPlugin.getInstance().getRandom().nextDouble() * totalWeight; double currentWeight = 0; for (Tier t : v) { currentWeight += t.getIdentifyChance(); if (currentWeight >= chosenWeight) { return t; } } return null; }
From source file:com.naver.jr.study.bo.sesame.SesameBOImpl.java
private List<SesameContents> getMainStepList(List<SesameContents> contentList, String stepName) { List<SesameContents> sesameContentList = sesameDAO.selectMainStepList(stepName); Collections.shuffle(sesameContentList); if (CollectionUtils.isNotEmpty(sesameContentList)) { contentList.add(sesameContentList.get(0)); }/* w ww. java 2s . c o m*/ return contentList; }