List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile//from w ww.ja v a 2s . c om * @param params * @throws ParseException * @throws IOException * @throws InterruptedException */ public static long selectionQuery(Path inFile, final ResultCollector<NASAPoint> output, OperationsParams params) throws ParseException, IOException, InterruptedException { // 1- Find matching temporal partitions final FileSystem fs = inFile.getFileSystem(params); Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params); // 2- Find the matching tile and the position in that tile final Point queryPoint = (Point) params.getShape("point"); final double userQueryLon = queryPoint.x; final double userQueryLat = queryPoint.y; // Convert query point from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(queryPoint.y * Math.PI / 180); double projectedX = queryPoint.x * cosPhiRad; queryPoint.x = (projectedX + 180.0) / 10.0; queryPoint.y = (90.0 - queryPoint.y) / 10.0; final int h = (int) Math.floor(queryPoint.x); final int v = (int) Math.floor(queryPoint.y); final String tileID = String.format("h%02dv%02d", h, v); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { return p.getName().indexOf(tileID) >= 0; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } // All matching files are supposed to have the same resolution final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0)); final java.awt.Point queryInMatchingTile = new java.awt.Point(); queryInMatchingTile.x = (int) Math.floor((queryPoint.x - h) * resolution); queryInMatchingTile.y = (int) Math.floor((queryPoint.y - v) * resolution); // 3- Query all matching files in parallel List<Long> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<Long>() { @Override public Long run(int i1, int i2) { ResultCollector<AggregateQuadTree.PointValue> internalOutput = output == null ? null : new ResultCollector<AggregateQuadTree.PointValue>() { NASAPoint middleValue = new NASAPoint(userQueryLon, userQueryLat, 0, 0); @Override public void collect(AggregateQuadTree.PointValue value) { middleValue.value = value.value; middleValue.timestamp = value.timestamp; output.collect(middleValue); } }; long numOfResults = 0; for (int i_file = i1; i_file < i2; i_file++) { try { Path matchingFile = allMatchingFiles.get(i_file); java.awt.Rectangle query = new java.awt.Rectangle(queryInMatchingTile.x, queryInMatchingTile.y, 1, 1); AggregateQuadTree.selectionQuery(fs, matchingFile, query, internalOutput); } catch (IOException e) { e.printStackTrace(); } } return numOfResults; } }); long totalResults = 0; for (long result : threadsResults) { totalResults += result; } return totalResults; }
From source file:modnlp.capte.AlignerUtils.java
public static void writeAlignment(String sourcename, Vector<Object[]> d) { //Output the current alignment as a tab separated file String sp = ""; BufferedWriter pw;//from ww w . jav a 2 s. c om try { pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sourcename), "UTF-8")); //PrintWriter tp = new PrintWriter(new OutputStreamWriter(new FileOutputStream(targetname),"UTF8")); String source = ""; String target = ""; Object[] stemp; for (int i = 0; i < d.size(); i++) { stemp = d.get(i); source = (String) stemp[0]; target = (String) stemp[1]; source = clean(source); target = clean(target); sp += source + "\t" + target + "\n"; } pw.write(new String(UnicodeUtil.convert(sp.getBytes(), "UTF-8"))); pw.close(); //return sp; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
private static Object getParameter(int index, Vector<Object> parameters) { if (index > parameters.size() - 1) return null; return parameters.get(index); }
From source file:com.tethrnet.manage.util.SSHUtil.java
public static List<String> listDir(HostSystem hostSystem, SchSession session) { Channel channel = null;/*from w w w. j a v a 2s. c om*/ ChannelSftp c = null; String remote_dir = AppConfig.getProperty("remote_download_dir"); List<String> fileList = new ArrayList<String>(); try { channel = session.getSession().openChannel("sftp"); c = (ChannelSftp) channel; channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(CHANNEL_TIMEOUT); System.out.println(c.getHome()); Vector<ChannelSftp.LsEntry> files = c.ls(remote_dir); for (int i = 0; i < files.size(); i++) { String fileName = files.get(i).getFilename(); if (fileName.equals(".") || fileName.equals("..")) { continue; } fileList.add(fileName); } } catch (Exception e) { log.info(e.toString(), e); e.printStackTrace(); hostSystem.setErrorMsg(e.getMessage()); hostSystem.setStatusCd(HostSystem.GENERIC_FAIL_STATUS); } //exit if (c != null) { c.exit(); } //disconnect if (channel != null) { channel.disconnect(); } return fileList; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * <p>toExecution.</p>/*w w w . ja va 2s . com*/ * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return a {@link com.greenpepper.server.domain.Execution} object. */ public static Execution toExecution(Vector<Object> xmlRpcParameters) { Execution execution = new Execution(); execution.setResults(toNullIfEmpty((String) xmlRpcParameters.get(EXECUTION_RESULTS_IDX))); execution.setExecutionErrorId(toNullIfEmpty((String) xmlRpcParameters.get(EXECUTION_ERRORID_IDX))); execution.setFailures((Integer) xmlRpcParameters.get(EXECUTION_FAILIURES_IDX)); execution.setErrors((Integer) xmlRpcParameters.get(EXECUTION_ERRORS_IDX)); execution.setSuccess((Integer) xmlRpcParameters.get(EXECUTION_SUCCESS_IDX)); execution.setIgnored((Integer) xmlRpcParameters.get(EXECUTION_IGNORED_IDX)); FormatedDate date = new FormatedDate((String) xmlRpcParameters.get(EXECUTION_EXECUTION_DATE_IDX)); execution.setExecutionDate(date.asTimestamp()); if (xmlRpcParameters.size() >= EXECUTION_LOGS_OUT_IDX) { execution.setStdoutLogs(toNullIfEmpty((String) xmlRpcParameters.get(EXECUTION_LOGS_OUT_IDX))); } if (xmlRpcParameters.size() >= EXECUTION_LOGS_ERR_IDX) { execution.setStderrLogs(toNullIfEmpty((String) xmlRpcParameters.get(EXECUTION_LOGS_ERR_IDX))); } return execution; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * <p>toRequirementSummary.</p> * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return a {@link com.greenpepper.server.domain.RequirementSummary} object. *///from w w w .j ava 2 s .co m public static RequirementSummary toRequirementSummary(Vector<Object> xmlRpcParameters) { RequirementSummary summary = new RequirementSummary(); summary.setReferencesSize((Integer) xmlRpcParameters.get(SUMMARY_REFERENCES_IDX)); summary.setFailures((Integer) xmlRpcParameters.get(SUMMARY_FAILIURES_IDX)); summary.setErrors((Integer) xmlRpcParameters.get(SUMMARY_ERRORS_IDX)); summary.setSuccess((Integer) xmlRpcParameters.get(SUMMARY_SUCCESS_IDX)); summary.setExceptions((Integer) xmlRpcParameters.get(SUMMARY_EXCEPTION_IDX)); return summary; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Requirement parameters into a Requirement Object.<br> * Structure of the parameters:<br> * Vector[name, Vector[repository parameters]] * </p>//from w w w . j a v a2s. co m * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Requirement. */ @SuppressWarnings("unchecked") public static Requirement toRequirement(Vector<Object> xmlRpcParameters) { Requirement requirement = null; if (!xmlRpcParameters.isEmpty()) { String name = (String) xmlRpcParameters.get(DOCUMENT_NAME_IDX); requirement = Requirement.newInstance(name); requirement.setRepository(toRepository((Vector<Object>) xmlRpcParameters.get(DOCUMENT_REPOSITORY_IDX))); } return requirement; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the Project parameters into a Project Object.<br> * Structure of the parameters:<br> * Vector[name]/*from w w w.ja va 2 s . c o m*/ * </p> * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the Project. */ public static Project toProject(Vector<Object> xmlRpcParameters) { Project project = null; if (!xmlRpcParameters.isEmpty()) { project = Project.newInstance((String) xmlRpcParameters.get(PROJECT_NAME_IDX)); } return project; }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile/*from ww w.java 2 s.c o m*/ * @param params * @throws ParseException * @throws IOException * @throws InterruptedException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException, InterruptedException { // 1- Find matching temporal partitions final FileSystem fs = inFile.getFileSystem(params); Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params); // 2- Find all matching files (AggregateQuadTrees) in matching partitions final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR(); // Convert spatialRange from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180); double southWest = spatialRange.x1 * cosPhiRad; double southEast = spatialRange.x2 * cosPhiRad; cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180); double northWest = spatialRange.x1 * cosPhiRad; double northEast = spatialRange.x2 * cosPhiRad; spatialRange.x1 = Math.min(northWest, southWest); spatialRange.x2 = Math.max(northEast, southEast); // Convert to the h v space used by MODIS spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0; spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0; spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0; spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0; // Vertically flip because the Sinusoidal space increases to the south double tmp = spatialRange.y2; spatialRange.y2 = spatialRange.y1; spatialRange.y1 = tmp; // Find the range of cells in MODIS Sinusoidal grid overlapping the range final int h1 = (int) Math.floor(spatialRange.x1); final int h2 = (int) Math.ceil(spatialRange.x2); final int v1 = (int) Math.floor(spatialRange.y1); final int v2 = (int) Math.ceil(spatialRange.y2); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { Matcher matcher = MODISTileID.matcher(p.getName()); if (!matcher.matches()) return false; int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); return h >= h1 && h < h2 && v >= v1 && v < v2; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } //noinspection SizeReplaceableByIsEmpty if (allMatchingFiles.isEmpty()) return null; final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0)); // 3- Query all matching files in parallel List<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<AggregateQuadTree.Node>() { @Override public Node run(int i1, int i2) { Node threadResult = new AggregateQuadTree.Node(); for (int i_file = i1; i_file < i2; i_file++) { Path matchingFile = allMatchingFiles.get(i_file); try { Matcher matcher = MODISTileID.matcher(matchingFile.getName()); matcher.matches(); // It has to match int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); // Clip the query region and normalize in this tile Rectangle translated = spatialRange.translate(-h, -v); int x1 = (int) (Math.max(translated.x1, 0) * resolution); int y1 = (int) (Math.max(translated.y1, 0) * resolution); int x2 = (int) (Math.min(translated.x2, 1.0) * resolution); int y2 = (int) (Math.min(translated.y2, 1.0) * resolution); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (Exception e) { throw new RuntimeException("Error reading file " + matchingFile, e); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) { finalResult.accumulate(threadResult); } numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
/** * Transforms the Vector of the EnvironmentType parameters into a EnvironmentType Object.<br> * </p>//from www . j a va 2 s . c om * * @param xmlRpcParameters a {@link java.util.Vector} object. * @return the EnvironmentType. */ public static EnvironmentType toEnvironmentType(Vector<Object> xmlRpcParameters) { EnvironmentType type = null; if (!xmlRpcParameters.isEmpty()) type = EnvironmentType.newInstance((String) xmlRpcParameters.get(ENVTYPE_NAME_IDX)); return type; }