List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:com.trsst.server.TrsstAdapter.java
/** * Returns a relay peer to use to fetch contents. Implementors should return * a url chosen from an evenly or randomly distributed mix of known trsst * servers based on the home urls of this servers hosted content. This * implementation currently returns a relay from the * com.trsst.client.storage property, or null if the property does not * exist.//ww w .ja va2s. c om * * @param relays * may not return any relay on this list */ protected URL getRelayPeer(List<String> excludeHashes) { if (RELAYS == null) { String property = System.getProperty("com.trsst.server.relays"); if (property == null) { RELAYS = new String[0]; } else { RELAYS = property.split(","); } } // return a random relay that's not on the exclude list Set<String> excludes = new HashSet<String>(); if (excludeHashes != null) { excludes.addAll(excludeHashes); } List<String> relays = new LinkedList<String>(); for (String relay : RELAYS) { relays.add(relay); } Collections.shuffle(relays); for (String relay : relays) { try { if (!excludes.contains(relay)) { return new URL(relay); } } catch (MalformedURLException e) { log.error("getRelayPeer: bad relay specified: " + relay, e); } } return null; }
From source file:com.alibaba.jstorm.blobstore.BlobStoreUtils.java
/** * Meant to be called only by the supervisor for stormjar/stormconf/stormcode files. * * @param key/*from w ww .j av a 2 s. co m*/ * @param localFile * @param cb * @throws KeyNotFoundException * @throws IOException */ public static void downloadResourcesAsSupervisor(String key, String localFile, ClientBlobStore cb, Map conf) throws KeyNotFoundException, IOException { if (cb instanceof NimbusBlobStore) { List<NimbusInfo> nimbusInfos = null; CuratorFramework zkClient = null; try { zkClient = BlobStoreUtils.createZKClient(conf); nimbusInfos = Lists .newArrayList(BlobStoreUtils.getNimbodesWithLatestSequenceNumberOfBlob(zkClient, key)); Collections.shuffle(nimbusInfos); } catch (Exception e) { LOG.error("get available nimbus for blob key:{} error", e); return; } finally { if (zkClient != null) { zkClient.close(); zkClient = null; } } for (NimbusInfo nimbusInfo : nimbusInfos) { try { NimbusClient nimbusClient = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort()); cb.setClient(conf, nimbusClient); } catch (TTransportException e) { // ignore continue; } LOG.info("download blob {} from nimbus {}:{}", key, nimbusInfo.getHost(), nimbusInfo.getPort()); downloadResourcesAsSupervisorDirect(key, localFile, cb); } } else { downloadResourcesAsSupervisorDirect(key, localFile, cb); } }
From source file:net.semanticmetadata.lire.solr.FastLireRequestHandler.java
private void handleExtract(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, InstantiationException, IllegalAccessException { SolrParams params = req.getParams(); String paramUrl = params.get("extract"); String paramField = "cl_ha"; if (req.getParams().get("field") != null) paramField = req.getParams().get("field"); // int paramRows = defaultNumberOfResults; // if (params.get("rows") != null) // paramRows = params.getInt("rows"); LireFeature feat = null;//from w ww .jav a 2s . co m // BooleanQuery query = null; // wrapping the whole part in the try try { BufferedImage img = ImageIO.read(new URL(paramUrl).openStream()); img = ImageUtils.trimWhiteSpace(img); // getting the right feature per field: if (paramField == null || FeatureRegistry.getClassForHashField(paramField) == null) // if the feature is not registered. feat = new EdgeHistogram(); else { feat = (LireFeature) FeatureRegistry.getClassForHashField(paramField).newInstance(); } feat.extract(img); rsp.add("histogram", Base64.encodeBase64String(feat.getByteArrayRepresentation())); int[] hashes = BitSampling.generateHashes(feat.getDoubleHistogram()); ArrayList<String> hashStrings = new ArrayList<String>(hashes.length); for (int i = 0; i < hashes.length; i++) { hashStrings.add(Integer.toHexString(hashes[i])); } Collections.shuffle(hashStrings); rsp.add("hashes", hashStrings); // just use 50% of the hashes for search ... // query = createTermFilter(hashes, paramField, 0.5d); } catch (Exception e) { // rsp.add("Error", "Error reading image from URL: " + paramUrl + ": " + e.getMessage()); e.printStackTrace(); } // search if the feature has been extracted. // if (feat != null) doSearch(rsp, req.getSearcher(), paramField, paramRows, query, feat); }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private MutableList<Integer> getSizes() { MutableList<Integer> sizes = FastList.newListWith(LARGE_COUNT, MEDIUM_COUNT, SMALL_COUNT); Collections.shuffle(sizes); return sizes; }
From source file:clummy.classes.DataHandlingClass.java
/** * the the blood type string shuffled/*from ww w. ja va 2 s . com*/ * @return */ public String getShuffledBloodType() { List<String> bloodType = defaultList.getBloodTypeList(); Collections.shuffle(bloodType); Collections.shuffle(bloodType); return bloodType.get(randBetween(0, bloodType.size() - 1)); }
From source file:c5db.tablet.TabletService.java
private void notifyCohortsForTabletCreation(final List<Long> peers, final HTableDescriptor hTableDescriptor, final HRegionInfo hRegionInfo, final int maximumNumberOfCohorts) { int numberOfCohorts = peers.size() < 3 ? peers.size() : maximumNumberOfCohorts; ArrayList<Long> shuffledPeers = new ArrayList<>(peers); Collections.shuffle(shuffledPeers); List<Long> subList = shuffledPeers.subList(0, numberOfCohorts); for (long peer : subList) { ModuleSubCommand moduleSubCommand = prepareTabletModuleSubCommand( prepareLaunchTabletString(hTableDescriptor, hRegionInfo, subList)); relayRequest(prepareRequest(peer, moduleSubCommand)); }// w w w . ja v a 2 s .c o m }
From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java
private AuctionMarkProfile copyProfile(AuctionMarkWorker worker, AuctionMarkProfile other) { this.client_id = worker.getId(); this.scale_factor = other.scale_factor; this.loaderStartTime = other.loaderStartTime; this.loaderStopTime = other.loaderStopTime; this.users_per_itemCount = other.users_per_itemCount; this.items_per_category = other.items_per_category; this.gag_ids = other.gag_ids; // Initialize the UserIdGenerator so we can figure out whether our // client should even have these ids this.initializeUserIdGenerator(this.client_id); assert (this.userIdGenerator != null); for (int i = 0; i < this.allItemSets.length; i++) { LinkedList<ItemInfo> list = this.allItemSets[i]; assert (list != null); LinkedList<ItemInfo> origList = other.allItemSets[i]; assert (origList != null); for (ItemInfo itemInfo : origList) { UserId sellerId = itemInfo.getSellerId(); if (this.userIdGenerator.checkClient(sellerId)) { this.seller_item_cnt.set(sellerId, sellerId.getItemCount()); list.add(itemInfo);/* ww w . ja v a 2 s.com*/ } } // FOR Collections.shuffle(list); } // FOR for (ItemCommentResponse cr : other.pending_commentResponses) { UserId sellerId = new UserId(cr.sellerId); if (this.userIdGenerator.checkClient(sellerId)) { this.pending_commentResponses.add(cr); } } // FOR if (LOG.isTraceEnabled()) LOG.trace("SellerItemCounts:\n" + this.seller_item_cnt); return (this); }
From source file:com.clust4j.data.DataSet.java
/** * Shuffle the rows (and corresponding labels, if they exist) * and return the new dataset//ww w .java 2 s . co m * in place */ public DataSet shuffle() { final int m = numRows(); boolean has_labels = null != labels; // if the labels are null, there are no labels to shuffle... /* * Generate range of indices... */ ArrayList<Integer> indices = new ArrayList<Integer>(); for (int i = 0; i < m; i++) indices.add(i); /* * Shuffle indices in place... */ Collections.shuffle(indices); final int[] newLabels = has_labels ? new int[m] : null; final double[][] newData = new double[m][]; /* * Reorder things... */ int j = 0; for (Integer idx : indices) { if (has_labels) { newLabels[j] = this.labels[idx]; } newData[j] = VecUtils.copy(this.data.getRow(idx)); j++; } return new DataSet(new Array2DRowRealMatrix(newData, true), newLabels, getHeaders(), formatter, false); }
From source file:clummy.classes.DataHandlingClass.java
/** * shuffle the list of address/* w w w . j a va 2s. c o m*/ * @param filesToRead * @return */ public List<String> getShuffledListOfAddress(String filesToRead) { String temp; List<String> countries = readFile(AllFileList.ADDRESSLIST); Collections.shuffle(countries); while (countries.size() < totalListFromName) { temp = countries.get(randBetween(0, countries.size() - 1)); if (temp.startsWith("[\\D]")) temp = temp.replaceFirst("[\\D]", String.valueOf(randBetween(100, 991)) + " "); else { switch (randBetween(1, 5)) { case 1: if (temp.contains("Apartment")) break; else { temp = "Apartment " + randBetween(1, 69) + " " + temp; break; } case 2: temp = "Road " + randBetween(1, 69) + " " + temp; break; case 3: if (temp.contains("Level")) break; else { temp = "Level " + randBetween(1, 234) + " " + temp; break; } case 4: temp = "Street " + randBetween(1, 4244) + " " + temp; break; case 5: temp = "Highway " + randBetween(1, 69) + " " + temp; break; } } countries.add(temp); } Collections.shuffle(countries); System.out.println(countries); return countries; }
From source file:com.gs.collections.impl.parallel.SerialParallelLazyPerformanceTest.java
private MutableList<Function0<FastList<Integer>>> getIntegerListGenerators(int count, boolean shuffle) { Interval interval = Interval.fromTo(-(count / 2), count / 2 - 1); MutableList<Function0<FastList<Integer>>> generators = FastList.newList(); generators.add(() -> {/* w ww. j a va2s. com*/ FastList<Integer> integers = FastList.newList(interval); if (shuffle) { Collections.shuffle(integers); } return integers; }); Collections.shuffle(generators); return generators; }