List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:edu.usc.pgroup.louvain.hadoop.ReduceCommunity.java
private Graph reconstructGraph(Iterable<BytesWritable> values) throws Exception { Iterator<BytesWritable> it = values.iterator(); SortedMap<Integer, GraphMessage> map = new TreeMap<Integer, GraphMessage>(); //Load data// ww w .ja va 2s . c o m while (it.hasNext()) { BytesWritable bytesWritable = it.next(); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytesWritable.getBytes()); try { ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); GraphMessage msg = (GraphMessage) objectInputStream.readObject(); map.put(msg.getCurrentPartition(), msg); } catch (IOException e) { e.printStackTrace(); throw new Exception(e); } } // Renumber int gap = 0; int degreeGap = 0; Path pt = new Path(outpath + File.separator + "Map-Partition-Sizes"); FileSystem fs = FileSystem.get(new Configuration()); if (fs.exists(pt)) { fs.delete(pt, true); } BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fs.create(pt, true))); PrintWriter out = new PrintWriter(br); for (int i = 0; i < map.keySet().size(); i++) { GraphMessage msg = map.get(i); long currentDegreelen = msg.getDegrees()[msg.getDegrees().length - 1]; if (i != 0) { for (int j = 0; j < msg.getLinks().length; j++) { msg.getLinks()[j] += gap; } for (int j = 0; j < msg.getRemoteMap().length; j++) { msg.getRemoteMap()[j].source += gap; } for (int j = 0; j < msg.getN2c().length; j++) { msg.getN2c()[j] += gap; } for (int j = 0; j < msg.getDegrees().length; j++) { msg.getDegrees()[j] += degreeGap; } } out.println("" + i + "," + msg.getNb_nodes()); gap += msg.getNb_nodes(); degreeGap += currentDegreelen; } out.flush(); out.close(); //Integrate Graph graph = new Graph(); for (int i = 0; i < map.keySet().size(); i++) { GraphMessage msg = map.get(i); Collections.addAll(graph.getDegrees().getList(), msg.getDegrees()); Collections.addAll(graph.getLinks().getList(), msg.getLinks()); Collections.addAll(graph.getWeights().getList(), msg.getWeights()); graph.setNb_links(graph.getNb_links() + msg.getNb_links()); graph.setNb_nodes((int) (graph.getNb_nodes() + msg.getNb_nodes())); graph.setTotal_weight(graph.getTotal_weight() + msg.getTotal_weight()); } //Merge local done. Map<Integer, Vector<Integer>> remoteEdges = new HashMap<Integer, Vector<Integer>>(); Map<Integer, Vector<Float>> remoteWeighs = new HashMap<Integer, Vector<Float>>(); for (int i = 0; i < map.keySet().size(); i++) { Map<HashMap.SimpleEntry<Integer, Integer>, Float> m = new HashMap<AbstractMap.SimpleEntry<Integer, Integer>, Float>(); GraphMessage msg = map.get(i); for (int j = 0; j < msg.getRemoteMap().length; j++) { RemoteMap remoteMap = msg.getRemoteMap()[j]; int sink = remoteMap.sink; int sinkPart = remoteMap.sinkPart; int target = map.get(sinkPart).getN2c()[sink]; HashMap.SimpleEntry<Integer, Integer> key = new HashMap.SimpleEntry<Integer, Integer>( remoteMap.source, target); if (m.containsKey(key)) { m.put(key, m.get(key) + 1.0f); } else { m.put(key, 1.0f); } } graph.setNb_links(graph.getNb_links() + m.size()); Iterator<HashMap.SimpleEntry<Integer, Integer>> itr = m.keySet().iterator(); while (itr.hasNext()) { HashMap.SimpleEntry<Integer, Integer> key = itr.next(); float w = m.get(key); if (remoteEdges.containsKey(key.getKey())) { remoteEdges.get(key.getKey()).getList().add(key.getValue()); if (remoteWeighs.containsKey(key.getKey())) { remoteWeighs.get(key.getKey()).getList().add(w); } } else { Vector<Integer> list = new Vector<Integer>(); list.getList().add(key.getValue()); remoteEdges.put(key.getKey(), list); Vector<Float> wList = new Vector<Float>(); wList.getList().add(w); remoteWeighs.put(key.getKey(), wList); } } } graph.addRemoteEdges(remoteEdges, remoteWeighs); //Merge Remote Done return graph; }
From source file:com.groupon.odo.proxylib.BackupService.java
/** * Return the structured backup data//from w ww . ja v a 2s .c o m * * @return Backup of current configuration * @throws Exception exception */ public Backup getBackupData() throws Exception { Backup backupData = new Backup(); backupData.setGroups(getGroups()); backupData.setProfiles(getProfiles()); ArrayList<Script> scripts = new ArrayList<Script>(); Collections.addAll(scripts, ScriptService.getInstance().getScripts()); backupData.setScripts(scripts); return backupData; }
From source file:com.skelril.aurora.shard.ShardManagerComponent.java
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity();//from w w w. j a v a 2s . c o m World world = getShardWorld(); if (!event.getEntity().getWorld().equals(world)) return; // Externally set if (playerState.containsKey(player.getUniqueId())) return; PlayerInstanceDeathEvent deathEvent = new PlayerInstanceDeathEvent(player, new PlayerRespawnProfile_1_7_10( player, event.getDroppedExp(), KeepAction.KEEP, KeepAction.KEEP, KeepAction.KEEP, KeepAction.KEEP)); callEvent(deathEvent); event.getDrops().clear(); PlayerRespawnProfile_1_7_10 profile = deathEvent.getProfile(); switch (profile.getArmorAction()) { case DROP: Collections.addAll(event.getDrops(), profile.getArmorContents()); break; } switch (profile.getInvAction()) { case DROP: Collections.addAll(event.getDrops(), profile.getInventoryContents()); break; } event.setDroppedExp((int) deathEvent.getProfile().getDroppedExp()); playerState.put(player.getUniqueId(), deathEvent.getProfile()); }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
@Override public List<String> getFileLocations(String path, FileLocationOptions options) throws IOException { // If the user has hinted the underlying storage nodes are not co-located with Alluxio // workers, short circuit without querying the locations if (Configuration.getBoolean(PropertyKey.UNDERFS_HDFS_REMOTE)) { return null; }/*from w ww . java 2 s. c om*/ List<String> ret = new ArrayList<>(); try { FileStatus fStatus = mFileSystem.getFileStatus(new Path(path)); BlockLocation[] bLocations = mFileSystem.getFileBlockLocations(fStatus, options.getOffset(), 1); if (bLocations.length > 0) { String[] names = bLocations[0].getHosts(); Collections.addAll(ret, names); } } catch (IOException e) { LOG.warn("Unable to get file location for {} : {}", path, e.getMessage()); } return ret; }
From source file:com.moscona.dataSpace.DataFrame.java
public IVectorIterator<Map<String, IScalar>> iterator(IBitMap result, String... columns) throws DataSpaceException, InvalidArgumentException { if (columns == null || columns.length == 0) { return iterator(result); } else {//from w w w . j a v a2 s . co m ArrayList<String> list = new ArrayList<String>(columns.length); Collections.addAll(list, columns); return iterator(result, list); } }
From source file:com.extrahardmode.config.EHMConfig.java
/** * Register new nodes to load from the config * * @param nodes nodes to register//from w ww . j a v a 2s.c om */ public void registerNodes(ConfigNode[] nodes) { Collections.addAll(mConfigNodes, nodes); }
From source file:fr.openwide.nuxeo.utils.document.DocumentUtils.java
/** * Returns true if and only if the "to" doctype is a supertype of "from" * /* w ww . ja va 2 s . c om*/ * @param from target type * @param to queried supertype * @return true if to is a supertype of from */ public static boolean isAssignable(String from, String to) { if (from.equals(to)) { return true; } TypeManager typeManager; try { typeManager = Framework.getService(TypeManager.class); } catch (Exception e) { throw new RuntimeException("Unable to get TypeManager", e); } Set<String> superTypes = new HashSet<String>(); Collections.addAll(superTypes, typeManager.getSuperTypes(from)); return superTypes.contains(to); }
From source file:edu.ku.brc.util.AttachmentUtils.java
/** * @param f the file to be opened/*from www . j a va 2s .co m*/ * @throws Exception */ public static void openFile(final File f) throws Exception { if (UIHelper.isWindows()) { HashSet<String> hashSet = new HashSet<String>(); Collections.addAll(hashSet, new String[] { "wav", "mp3", "snd", "mid", "aif", "aiff", }); String ext = FilenameUtils.getExtension(f.getName()).toLowerCase(); if (hashSet.contains(ext)) { Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + f.getAbsolutePath()); return; } } Desktop.getDesktop().open(f); }
From source file:io.restassured.module.mockmvc.internal.MockMvcRequestSpecificationImpl.java
public MockMvcRequestSpecification postProcessors(RequestPostProcessor postProcessor, RequestPostProcessor... additionalPostProcessors) { notNull(postProcessor, RequestPostProcessor.class); this.requestPostProcessors.add(postProcessor); if (additionalPostProcessors != null && additionalPostProcessors.length >= 1) { Collections.addAll(this.requestPostProcessors, additionalPostProcessors); }/*from w w w. j av a 2s. co m*/ return this; }
From source file:sx.blah.discord.handle.impl.obj.Channel.java
@Override public MessageHistory getMessageHistory(int messageCount) { if (messageCount <= messages.size()) { // we already have all of the wanted messages in the cache return new MessageHistory(messages.values().stream().sorted(new MessageComparator(true)) .limit(messageCount).collect(Collectors.toList())); } else {//from w w w . ja v a 2 s.c o m List<IMessage> retrieved = new ArrayList<>(messageCount); AtomicLong lastMessage = new AtomicLong(DiscordUtils.getSnowflakeFromTimestamp(Instant.now())); int chunkSize = messageCount < MESSAGE_CHUNK_COUNT ? messageCount : MESSAGE_CHUNK_COUNT; while (retrieved.size() < messageCount) { // while we dont have messageCount messages IMessage[] chunk = getHistory(lastMessage.get(), chunkSize); if (chunk.length == 0) break; lastMessage.set(chunk[chunk.length - 1].getLongID()); Collections.addAll(retrieved, chunk); } return new MessageHistory( retrieved.size() > messageCount ? retrieved.subList(0, messageCount) : retrieved); } }