List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Create a string of class names for a particular SamplerController * * @param properties/*from w ww . ja va2s. c om*/ * The properties with info about the samples. * @param name * The name of the sampler controller. * @return The TestSamples value * @deprecated (3.0) not used */ @Deprecated public static String[] getTestSamples(Properties properties, String name) { Vector<String> vector = getVector(properties, name + ".testsample"); // $NON-NLS-1$ return vector.toArray(new String[vector.size()]); }
From source file:jmxsh.ListCmd.java
public void cmdProc(Interp interp, TclObject argv[]) throws TclException { try {// w w w . jav a2 s. co m CommandLine cl = parseCommandLine(argv); String args[] = cl.getArgs(); String[] expressions = null; if (cl.hasOption("help")) { new HelpFormatter().printHelp("jmx_list [-?] [-s server] domain_regex:mbean_regex", "======================================================================", this.opts, "======================================================================", false); System.out.println("jmx_list retrieves the list of known mbeans for the given"); System.out.println("server. It takes a pair of regex expressions separated by"); System.out.println("colon. The first is an expression for the domain, the"); System.out.println("second is an expression for the mbean."); System.out.println(""); System.out.println("It will return a list of tcl strings."); return; } listDefaults(interp); this.server = cl.getOptionValue("server", this.server); if (args.length > 0) { expressions = args[0].split(":"); } if (this.server == null) { throw new TclException(interp, "No server specified; please set SERVER variable or use -s option.", TCL.ERROR); } String domain_regex = (expressions != null && expressions.length > 0) ? expressions[0] : ""; String mbean_regex = (expressions != null && expressions.length > 1) ? expressions[1] : ""; String[] domains = Jmx.getInstance().getDomains(this.server, domain_regex); Vector<String> beans = new Vector<String>(); for (String domain : domains) { List<String> list = Arrays.asList(Jmx.getInstance().getMBeans(this.server, domain, mbean_regex)); beans.addAll(list); } String[] emptyStringArray = new String[0]; TclObject result = Utils.array2list(beans.toArray(emptyStringArray)); interp.setResult(result); } catch (ParseException e) { throw new TclException(interp, e.getMessage(), 1); } catch (RuntimeException e) { throw new TclException(interp, "Cannot convert result to a string.", 1); } }
From source file:partes.service.Partes.java
/** * * * it returns an HashMap with a condition as key, and as value * an list of HashMap with {@link partes.refactorRunner.PartesInfo PartesInfo} as key * and the String (test) as value. /*from w ww .j a v a 2 s.co m*/ * @throws BPMNmalformedException * @throws TestGenerationException * @throws JAXBException * @throws FileNotFoundException */ @Override public HashMap<String, HashMap<PartesInfo, String>> generateTestSuite() throws BPMNmalformedException, TestGenerationException, FileNotFoundException, JAXBException { log.info("started test suite generation for " + PartesMain.instance.bpmnPath); HashMap<String, HashMap<PartesInfo, String>> xmlTests = new HashMap<String, HashMap<PartesInfo, String>>(); // #### STEP 1 ##### create the InteractionTrees HashMap<String, Tree> step1 = this.getcTreeGenerator().buildInteractionTrees(PartesMain.instance.bpmnPath); log.info("built interaction trees of " + step1.keySet().size() + " conditions"); if (PartesMain.instance.debug) { XStream xstream = new XStream(); String xml = xstream.toXML(step1); WriteToFile.writeToANewFileInOutputDir("TestSuite" + File.separator, PartesConf.getString("cmdline.tree_of_interaction_file"), xml.trim()); } /** * now, for each condition, we create projections and test pool. In the output folder * there will be one sub-folder for each condition. In each of theme there will be the * participants projections and the test sequence generated. * The conditions are the children of the root. * @see partes.refactorRunner.InteractionTreeBuilder.getTreeOfInteraction() */ Set<String> conditions = step1.keySet(); Iterator<String> condIter = conditions.iterator(); //look for participants Vector<PartesInfo> participants = PartesMain.instance.servicesWsdlUrl; //+ PartesConf.getString("treeBuilder.participant_conf_file")); log.info("participants are: " + participants.toString()); Vector<String> services = new Vector<String>(); for (PartesInfo p : participants) { services.add(p.getModelImplClass()); } String[] servicesToSearch = new String[0]; servicesToSearch = services.toArray(servicesToSearch); while (condIter.hasNext()) { String condition = condIter.next(); XStream xstream = new XStream(); String xml = xstream.toXML(step1.get(condition)); Tree treeOfOneCondition = (Tree) xstream.fromXML(xml); //cloned tree // #### STEP 2 #### makes the projections Vector<ProjectionInfo> step2 = this.getpProjectionGenerator().makeProjection(treeOfOneCondition, servicesToSearch); log.info("built " + step2.size() + "[" + condition + "] projection trees for participants"); // #### STEP 3 #### makes SOAPui project for (ProjectionInfo pi : step2) { if (PartesMain.instance.debug) { XStream xstream2 = new XStream(); String xml2 = xstream2.toXML(pi.getProjectionTree()); WriteToFile.writeToANewFileInOutputDir("TestSuite" + File.separator + condition, "projection-" + pi.getService() + ".xml", xml2); } for (PartesInfo p : participants) { if (pi.getService().equals(p.getModelImplClass())) { String wsdlLocation = p.getWsdlLocation(); String portTypeToSearch = p.getPortTypeToSearch(); String xmlTest = ""; try { xmlTest = this.getpTestBuilder() .makeSOAPuiProject(pi.getProjectionTree(), portTypeToSearch, wsdlLocation) .getProjectDocument().toString(); } catch (XmlException e) { //e.printStackTrace(); System.out.println("Partes causes an XmlException!"); } catch (IOException e) { //e.printStackTrace(); System.out.println("Partes causes an IOException!"); } catch (SoapUIException e) { //e.printStackTrace(); System.out.println("Partes causes an SoapUIException!"); } if (xmlTests.get(condition) == null) { xmlTests.put(condition, new HashMap<PartesInfo, String>()); } xmlTests.get(condition).put(p, xmlTest); log.info("built SOAPui project for " + p.getPortTypeToSearch()); } } } } //#### STEP 4 #### make integration test with all the traces of that condition String xmlTest = ""; xmlTest = this.getpTestBuilder().makeSOAPuiProjectTracesTest(step1, participants).getProjectDocument() .toString(); HashMap<PartesInfo, String> hm = new HashMap<PartesInfo, String>(); hm.put(null, xmlTest); xmlTests.put("whole choreography traces", hm); return xmlTests; }
From source file:edu.umn.cs.spatialHadoop.operations.Indexer.java
/*** * Create a partitioner for a particular job * @param in//ww w . j av a 2s. c o m * @param out * @param job * @param partitionerName * @return * @throws IOException */ public static Partitioner createPartitioner(Path[] ins, Path out, Configuration job, String partitionerName) throws IOException { try { Partitioner partitioner = null; Class<? extends Partitioner> partitionerClass = PartitionerClasses.get(partitionerName.toLowerCase()); if (partitionerClass == null) { throw new RuntimeException("Unknown index type '" + partitionerName + "'"); } boolean replicate = PartitionerReplicate.get(partitionerName.toLowerCase()); job.setBoolean("replicate", replicate); partitioner = partitionerClass.newInstance(); long t1 = System.currentTimeMillis(); final Rectangle inMBR = (Rectangle) OperationsParams.getShape(job, "mbr"); // Determine number of partitions long inSize = 0; for (Path in : ins) { inSize += FileUtil.getPathSize(in.getFileSystem(job), in); } long estimatedOutSize = (long) (inSize * (1.0 + job.getFloat(SpatialSite.INDEXING_OVERHEAD, 0.1f))); FileSystem outFS = out.getFileSystem(job); long outBlockSize = outFS.getDefaultBlockSize(out); int numPartitions = Math.max(1, (int) Math.ceil((float) estimatedOutSize / outBlockSize)); LOG.info("Partitioning the space into " + numPartitions + " partitions"); final Vector<Point> sample = new Vector<Point>(); float sample_ratio = job.getFloat(SpatialSite.SAMPLE_RATIO, 0.01f); long sample_size = job.getLong(SpatialSite.SAMPLE_SIZE, 100 * 1024 * 1024); LOG.info("Reading a sample of " + (int) Math.round(sample_ratio * 100) + "%"); ResultCollector<Point> resultCollector = new ResultCollector<Point>() { @Override public void collect(Point p) { sample.add(p.clone()); } }; OperationsParams params2 = new OperationsParams(job); params2.setFloat("ratio", sample_ratio); params2.setLong("size", sample_size); params2.setClass("outshape", Point.class, Shape.class); Sampler.sample(ins, resultCollector, params2); long t2 = System.currentTimeMillis(); System.out.println("Total time for sampling in millis: " + (t2 - t1)); LOG.info("Finished reading a sample of " + sample.size() + " records"); partitioner.createFromPoints(inMBR, sample.toArray(new Point[sample.size()]), numPartitions); return partitioner; } catch (InstantiationException e) { e.printStackTrace(); return null; } catch (IllegalAccessException e) { e.printStackTrace(); return null; } }
From source file:org.mili.core.templating.TemplateStore.java
/** * List all included templates by their names. * * @return List with all template names. *//*from ww w .j a v a2s . com*/ public String[] listTemplates() { Vector<String> v = new Vector<String>(); v.addAll(this.templates.keySet()); return (String[]) v.toArray(new String[] {}); }
From source file:edu.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
public static boolean multiplot(Path[] input, Path output, OperationsParams params) throws IOException, InterruptedException, ClassNotFoundException, ParseException { String timeRange = params.get("time"); final Date dateFrom, dateTo; final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd"); try {/*from w w w. j a va 2 s . c om*/ String[] parts = timeRange.split("\\.\\."); dateFrom = dateFormat.parse(parts[0]); dateTo = dateFormat.parse(parts[1]); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("Use the seperator two periods '..' to seperate from and to dates"); return false; // To avoid an error that causes dateFrom to be uninitialized } catch (ParseException e) { System.err.println("Illegal date format in " + timeRange); return false; } // Number of frames to combine in each image int combine = params.getInt("combine", 1); // Retrieve all matching input directories based on date range Vector<Path> matchingPathsV = new Vector<Path>(); for (Path inputFile : input) { FileSystem inFs = inputFile.getFileSystem(params); FileStatus[] matchingDirs = inFs.listStatus(input, new PathFilter() { @Override public boolean accept(Path p) { String dirName = p.getName(); try { Date date = dateFormat.parse(dirName); return date.compareTo(dateFrom) >= 0 && date.compareTo(dateTo) <= 0; } catch (ParseException e) { LOG.warn("Cannot parse directory name: " + dirName); return false; } } }); for (FileStatus matchingDir : matchingDirs) matchingPathsV.add(new Path(matchingDir.getPath(), "*.hdf")); } if (matchingPathsV.isEmpty()) { LOG.warn("No matching directories to given input"); return false; } Path[] matchingPaths = matchingPathsV.toArray(new Path[matchingPathsV.size()]); Arrays.sort(matchingPaths); // Clear all paths to ensure we set our own paths for each job params.clearAllPaths(); // Create a water mask if we need to recover holes on write if (params.get("recover", "none").equals("write")) { // Recover images on write requires a water mask image to be generated first OperationsParams wmParams = new OperationsParams(params); wmParams.setBoolean("background", false); Path wmImage = new Path(output, new Path("water_mask")); HDFPlot.generateWaterMask(wmImage, wmParams); params.set(HDFPlot.PREPROCESSED_WATERMARK, wmImage.toString()); } // Start a job for each path int imageWidth = -1; int imageHeight = -1; boolean overwrite = params.getBoolean("overwrite", false); boolean pyramid = params.getBoolean("pyramid", false); FileSystem outFs = output.getFileSystem(params); Vector<Job> jobs = new Vector<Job>(); boolean background = params.getBoolean("background", false); Rectangle mbr = new Rectangle(-180, -90, 180, 90); for (int i = 0; i < matchingPaths.length; i += combine) { Path[] inputPaths = new Path[Math.min(combine, matchingPaths.length - i)]; System.arraycopy(matchingPaths, i, inputPaths, 0, inputPaths.length); Path outputPath = new Path(output, inputPaths[0].getParent().getName() + (pyramid ? "" : ".png")); if (overwrite || !outFs.exists(outputPath)) { // Need to plot Job rj = HDFPlot.plotHeatMap(inputPaths, outputPath, params); if (imageHeight == -1 || imageWidth == -1) { if (rj != null) { imageHeight = rj.getConfiguration().getInt("height", 1000); imageWidth = rj.getConfiguration().getInt("width", 1000); mbr = (Rectangle) OperationsParams.getShape(rj.getConfiguration(), "mbr"); } else { imageHeight = params.getInt("height", 1000); imageWidth = params.getInt("width", 1000); mbr = (Rectangle) OperationsParams.getShape(params, "mbr"); } } if (background && rj != null) jobs.add(rj); } } // Wait until all jobs are done while (!jobs.isEmpty()) { Job firstJob = jobs.firstElement(); firstJob.waitForCompletion(false); if (!firstJob.isSuccessful()) { System.err.println("Error running job " + firstJob.getJobID()); System.err.println("Killing all remaining jobs"); for (int j = 1; j < jobs.size(); j++) jobs.get(j).killJob(); throw new RuntimeException("Error running job " + firstJob.getJobID()); } jobs.remove(0); } // Draw the scale in the output path if needed String scalerange = params.get("scalerange"); if (scalerange != null) { String[] parts = scalerange.split("\\.\\."); double min = Double.parseDouble(parts[0]); double max = Double.parseDouble(parts[1]); String scale = params.get("scale", "none").toLowerCase(); if (scale.equals("vertical")) { MultiHDFPlot.drawVerticalScale(new Path(output, "scale.png"), min, max, 64, imageHeight, params); } else if (scale.equals("horizontal")) { MultiHDFPlot.drawHorizontalScale(new Path(output, "scale.png"), min, max, imageWidth, 64, params); } } // Add the KML file createKML(outFs, output, mbr, params); return true; }
From source file:org.marketcetera.util.file.SmartLinksDirectoryWalkerTest.java
@Test public void walk() throws Exception { String root;//from w ww . ja v a2s .c o m String dir; String[] files = TEST_FILE_LIST; if (OperatingSystem.LOCAL.isUnix()) { dir = TEST_DIR_UNIX; root = TEST_ROOT_UNIX; files = (String[]) ArrayUtils.add(files, TEST_LINK_NAME); } else if (OperatingSystem.LOCAL.isWin32()) { dir = TEST_DIR_WIN32; root = TEST_ROOT_WIN32; } else { throw new AssertionError("Unknown platform"); } String[] dirs = (String[]) ArrayUtils.add(TEST_DIR_LIST, dir); ListWalker walker = new ListWalker(false); walker.apply(root); assertArrayPermutation(files, walker.getFiles()); assertArrayPermutation(dirs, walker.getDirectories()); assertEquals(3, walker.getMaxDepth()); Vector<String> results = new Vector<String>(); walker = new ListWalker(false); walker.apply(root, results); assertArrayPermutation(files, walker.getFiles()); assertArrayPermutation(dirs, walker.getDirectories()); assertArrayPermutation(ArrayUtils.addAll(files, dirs), results.toArray(ArrayUtils.EMPTY_STRING_ARRAY)); assertEquals(3, walker.getMaxDepth()); files = TEST_FILE_LIST; dirs = (String[]) ArrayUtils.add(TEST_DIR_LIST, dir); if (OperatingSystem.LOCAL.isUnix()) { files = (String[]) ArrayUtils.add(files, TEST_LINK_CONTENTS); dirs = (String[]) ArrayUtils.add(dirs, TEST_LINK_NAME); } walker = new ListWalker(true); walker.apply(root); assertArrayPermutation(files, walker.getFiles()); assertArrayPermutation(dirs, walker.getDirectories()); assertEquals(3, walker.getMaxDepth()); results = new Vector<String>(); walker = new ListWalker(true); walker.apply(root, results); assertArrayPermutation(files, walker.getFiles()); assertArrayPermutation(dirs, walker.getDirectories()); assertArrayPermutation(ArrayUtils.addAll(files, dirs), results.toArray(ArrayUtils.EMPTY_STRING_ARRAY)); assertEquals(3, walker.getMaxDepth()); }
From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java
/** * * @return//from ww w. j a v a 2s. c om */ public String[] getNames() { String[] result = null; try { String jsonStr = this.packageWaypointCall("getNames", null, null); debug("sending: " + jsonStr); String resString = server.call(jsonStr); debug("got back: " + resString); JSONObject res = new JSONObject(resString); String resArrStr = res.optString("result"); JSONArray nameArr = new JSONArray(resArrStr); Vector<String> vec = new Vector<>(); for (int i = 0; i < nameArr.length(); i++) { vec.add(nameArr.optString(i)); } result = vec.toArray(new String[] {}); } catch (Exception ex) { System.out.println("exception in rpc call to getNames: " + ex.getMessage()); } return result; }
From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java
/** * * @param category/*from w ww .ja v a 2 s. c o m*/ * @return */ public String[] getNamesInCategory(String category) { String[] result = null; try { String jsonStr = this.packageWaypointCall("getNamesInCategory", category, null); debug("sending: " + jsonStr); String resString = server.call(jsonStr); debug("got back: " + resString); JSONObject res = new JSONObject(resString); String resArrStr = res.optString("result"); JSONArray nameArr = new JSONArray(resArrStr); Vector<String> vec = new Vector<>(); for (int i = 0; i < nameArr.length(); i++) { vec.add(nameArr.optString(i)); } result = vec.toArray(new String[] {}); } catch (Exception ex) { System.out.println("exception in rpc call to getNamesInCategory: " + ex.getMessage()); } return result; }
From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java
/** * * @return// w ww.j a va 2s .co m */ public String[] getCategoryNames() { String[] result = null; try { String jsonStr = this.packageWaypointCall("getCategoryNames", null, null); debug("sending: " + jsonStr); String resString = server.call(jsonStr); debug("got back: " + resString); JSONObject res = new JSONObject(resString); String resArrStr = res.optString("result"); JSONArray nameArr = new JSONArray(resArrStr); Vector<String> vec = new Vector<>(); for (int i = 0; i < nameArr.length(); i++) { vec.add(nameArr.optString(i)); } result = vec.toArray(new String[] {}); } catch (Exception ex) { System.out.println("exception in rpc call to getCategoryNames: " + ex.getMessage()); } return result; }