List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:ca.myewb.frame.PostParamWrapper.java
public String[] getArray(String value) { ArrayList<String> values = new ArrayList<String>(); int i = 0;/*from www . j a v a 2 s . c o m*/ while (stringParams.get(value + i) != null) { values.add(stringParams.get(value + i++)); } return values.toArray(new String[1]); }
From source file:com.microsoft.azure.servicebus.samples.prefetch.Prefetch.java
long sendAndReceiveMessages(IMessageSender sender, IMessageReceiver receiver, int messageCount) throws Exception { // Now we can start sending messages. Random rnd = new Random(); byte[] mockPayload = new byte[100]; // 100 random-byte payload rnd.nextBytes(mockPayload);/* ww w . j a va 2 s .co m*/ System.out.printf("\nSending %d messages to the queue\n", messageCount); ArrayList<CompletableFuture<Void>> sendOps = new ArrayList<>(); for (int i = 0; i < messageCount; i++) { IMessage message = new Message(mockPayload); message.setTimeToLive(Duration.ofMinutes(5)); sendOps.add(sender.sendAsync(message)); } CompletableFuture.allOf(sendOps.toArray(new CompletableFuture<?>[sendOps.size()])).join(); System.out.printf("Send completed\n"); // Receive the messages System.out.printf("Receiving messages...\n"); // Start stopwatch Stopwatch stopWatch = Stopwatch.createStarted(); IMessage receivedMessage = receiver.receive(Duration.ofSeconds(5)); while (receivedMessage != null) { // here's where you'd do any work // complete (round trips) receiver.complete(receivedMessage.getLockToken()); if (--messageCount <= 0) break; // now get the next message receivedMessage = receiver.receive(Duration.ofSeconds(5)); } // Stop the stopwatch stopWatch.stop(); System.out.printf("Receive completed\n"); long timeTaken = stopWatch.elapsed(TimeUnit.MILLISECONDS); System.out.printf("Time to receive and complete all messages = %d milliseconds\n", timeTaken); return timeTaken; }
From source file:com.thoughtworks.go.domain.materials.svn.SvnMaterialUpdater.java
private BuildCommand checkout(String workingDir, Revision revision) { ArrayList<String> args = new ArrayList<>(); addCredentials(args);/*from ww w . j a v a2 s .c o m*/ args.add("checkout"); args.add("--non-interactive"); args.add("-r"); args.add(revision.getRevision()); args.add(material.getUrlArgument().forCommandLine()); args.add(workingDir); return exec("svn", args.toArray(new String[args.size()])); }
From source file:classif.Majority.KMeansSymbolicSequence.java
public void cluster() { centers = new ClassedSequence[nbClusters]; affectation = new ArrayList[nbClusters]; // pickup centers int[] selected = randGen.nextPermutation(data.size(), nbClusters); for (int i = 0; i < selected.length; i++) { centers[i] = new ClassedSequence(data.get(selected[i]).sequence, data.get(selected[i]).classValue); }//from www. j a v a 2s. c o m // for each iteration i for (int i = 0; i < 15; i++) { // init for (int k = 0; k < affectation.length; k++) { affectation[k] = new ArrayList<ClassedSequence>(); } // for each data point j for (int j = 0; j < data.size(); j++) { double minDist = Double.MAX_VALUE; // for each cluster k for (int k = 0; k < centers.length; k++) { // distance between cluster k and data point j double currentDist = centers[k].sequence.distance(data.get(j).sequence); if (currentDist < minDist) { clusterMap[j] = k; minDist = currentDist; } } // affect data point j to cluster affected to j affectation[clusterMap[j]].add(data.get(j)); } // redefine for (int j = 0; j < nbClusters; j++) { if (affectation[j].size() == 0) { centers[j] = null; } else { ArrayList<Sequence> copyaffectation = new ArrayList<Sequence>(); for (ClassedSequence eachClassedSequence : affectation[j]) { copyaffectation.add(eachClassedSequence.sequence); } centers[j].sequence = Sequences.mean(copyaffectation.toArray(new Sequence[0])); centers[j].classValue = MajorityClass(affectation[j]); } } } }
From source file:com.ripariandata.timberwolf.writer.hive.SequenceFileMailWriterTest.java
private static MailboxItem mockMailboxItem(final String key, final String body, final String subject, final String timesent, final String sender, final String to, final String cc, final String bcc) { MailboxItem mail = mock(MailboxItem.class); ArrayList<String> headers = new ArrayList<String>(); when(mail.hasKey(any(String.class))).thenReturn(true); when(mail.getHeader("Item ID")).thenReturn(key); if (body != null) { when(mail.getHeader("Body")).thenReturn(body); headers.add("Body"); }// w w w . j a v a 2 s.co m if (subject != null) { when(mail.getHeader("Subject")).thenReturn(subject); headers.add("Subject"); } if (timesent != null) { when(mail.getHeader("Time Sent")).thenReturn(timesent); headers.add("Time Sent"); } if (sender != null) { when(mail.getHeader("Sender")).thenReturn(sender); headers.add("Sender"); } if (to != null) { when(mail.getHeader("To")).thenReturn(to); headers.add("To"); } if (cc != null) { when(mail.getHeader("Cc")).thenReturn(cc); headers.add("Cc"); } if (bcc != null) { when(mail.getHeader("Bcc")).thenReturn(bcc); headers.add("Bcc"); } when(mail.getHeaderKeys()).thenReturn(headers.toArray(new String[0])); return mail; }
From source file:com.shanke.common.conf.StringHandle.java
/** * Split a string using the given separator, with no escaping performed. * /*from www . j ava 2 s. c o m*/ * @param str * a string to be split. Note that this may not be null. * @param separator * a separator char * @return an array of strings */ public static String[] split(String str, char separator) { // String.split returns a single empty result for splitting the empty // string. if (str.isEmpty()) { return new String[] { "" }; } ArrayList<String> strList = new ArrayList<String>(); int startIndex = 0; int nextIndex = 0; while ((nextIndex = str.indexOf((int) separator, startIndex)) != -1) { strList.add(str.substring(startIndex, nextIndex)); startIndex = nextIndex + 1; } strList.add(str.substring(startIndex)); // remove trailing empty split(s) int last = strList.size(); // last split while (--last >= 0 && "".equals(strList.get(last))) { strList.remove(last); } return strList.toArray(new String[strList.size()]); }
From source file:it.crs4.most.ehrlib.parser.AdlParser.java
/** * Gets the paths array./* ww w .j a v a 2 s. com*/ * * @param path the path * @return the paths array */ private String[] getPathsArray(String path) { ArrayList<String> pathsA = new ArrayList<String>(Arrays.asList(path.split("[\\[\\]/]"))); Iterator<String> iter = pathsA.iterator(); while (iter.hasNext()) { if (iter.next().equalsIgnoreCase("")) iter.remove(); } return pathsA.toArray(new String[0]); }
From source file:com.netspective.axiom.sql.ResultSetUtils.java
public String[] getResultSetRowsAsStrings(ResultSet rs) throws SQLException { ArrayList result = new ArrayList(); while (rs.next()) { result.add(rs.getString(1));/*from w w w. jav a 2s . c om*/ } if (result.size() > 0) return (String[]) result.toArray(new String[result.size()]); else return null; }
From source file:com.baidu.android.voicedemo.ActivityTouch.java
@Override public void onPartialResults(Bundle partialResults) { ArrayList<String> nbest = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); if (nbest.size() > 0) { print("~" + Arrays.toString(nbest.toArray(new String[0]))); txtResult.setText(nbest.get(0)); }/*from www .ja v a 2 s .c o m*/ }
From source file:gdt.data.entity.BaseHandler.java
/** * Get an array of all facet handlers in the database * @param entigrator instance of the Entigrator class * @return array of facet handlers.//w ww . ja v a 2 s . com */ public static FacetHandler[] listAllHandlers(Entigrator entigrator) { try { ArrayList<FacetHandler> fl = new ArrayList<FacetHandler>(); // System.out.println("BaseHandler:listAllHandlers:BEGIN"); fl.add(new FieldsHandler()); fl.add(new FolderHandler()); fl.add(new WebsetHandler()); fl.add(new BookmarksHandler()); fl.add(new IndexHandler()); fl.add(new ExtensionHandler()); fl.add(new QueryHandler()); fl.add(new ProcedureHandler()); // System.out.println("BaseHandler:listAllHandlers:END EMBEDDED"); FacetHandler[] fha = ExtensionHandler.listExtensionHandlers(entigrator); if (fha != null) { //System.out.println("BaseHandler:listAllHandlers:fha="+fha.length); for (FacetHandler fh : fha) { //System.out.println("BaseHandler:listAllHandlers:fh="+fh.toString()); fl.add(fh); } } //else // System.out.println("BaseHandler:listAllHandlers:no extensions"); // System.out.println("BaseHandler:listAllHandlers:END EXTENSIONS"); return fl.toArray(new FacetHandler[0]); } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); return null; } }