List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:org.springmodules.validation.util.condition.common.AbstractCompoundCondition.java
/** * Constructs a new AbstractCompoundCondition with the given collection of conditions. * * @param conditions The conditions this condition is compound from. */// w w w. jav a 2s . com public AbstractCompoundCondition(Collection conditions) { Assert.notNull(conditions, "Compound condition cannot accept null as conditions"); this.conditions = (Condition[]) conditions.toArray(new Condition[conditions.size()]); }
From source file:br.com.caelum.vraptor.interceptor.multipart.MultipartItemsProcessor.java
public void process() { Multimap<String, String> params = LinkedListMultimap.create(); for (FileItem item : items) { if (item.isFormField()) { params.put(item.getFieldName(), getValue(item)); continue; }/* w w w .ja va 2 s . c om*/ if (notEmpty(item)) { try { UploadedFile fileInformation = new DefaultUploadedFile(item.getInputStream(), item.getName(), item.getContentType()); parameters.setParameter(item.getFieldName(), item.getName()); request.setAttribute(item.getName(), fileInformation); logger.debug("Uploaded file: {} with {}", item.getFieldName(), fileInformation); } catch (Exception e) { throw new InvalidParameterException("Cant parse uploaded file " + item.getName(), e); } } else { logger.debug("A file field was empty: {}", item.getFieldName()); } } for (String paramName : params.keySet()) { Collection<String> paramValues = params.get(paramName); parameters.setParameter(paramName, paramValues.toArray(new String[paramValues.size()])); } }
From source file:io.kahu.hawaii.domain.FieldChecker.java
private boolean checkAllFieldsAreBlank(Object bean, Collection<String> fieldNames) throws ServerException { return checkAllFieldsAreBlank(bean, fieldNames.toArray(new String[] {})); }
From source file:com.liferay.portal.search.elasticsearch.internal.SearchHitDocumentTranslatorImpl.java
protected Field translate(SearchHitField searchHitField) { String name = searchHitField.getName(); Collection<Object> values = searchHitField.getValues(); Field field = new Field(name, ArrayUtil.toStringArray(values.toArray(new Object[values.size()]))); return field; }
From source file:com.sf.ddao.orm.rsmapper.ArrayRSMapper.java
@Override public Object handle(Context context, ResultSet rs) throws SQLException { Collection list = (Collection) super.handle(context, rs); Object[] array = (Object[]) Array.newInstance(itemType, list.size()); //noinspection unchecked return list.toArray(array); }
From source file:com.twitter.ambrose.service.impl.InMemoryStatsService.java
public void writeJsonToDisk() throws IOException { if (dagWriter != null && dagNodeNameMap != null) { Collection<DAGNode> nodes = getDagNodeNameMap(null).values(); JSONUtil.writeJson(dagWriter, nodes.toArray(new DAGNode[dagNodeNameMap.size()])); dagWriter.close();/* w ww . j a v a 2 s . c o m*/ } if (eventsWriter != null && eventMap != null) { Collection<WorkflowEvent> events = getEventsSinceId(null, -1); JSONUtil.writeJson(eventsWriter, events.toArray(new WorkflowEvent[events.size()])); eventsWriter.close(); } }
From source file:com.scottieknows.test.cassandra.CassandraAutoConfiguration.java
@Bean public Cluster cluster(CassandraConfigurationProperties cassandraConfigurationProperties) { Integer nodes = cassandraConfigurationProperties.getClusterNodes(); Collection<String> ips = new ArrayList<>(); for (int i = 1; i <= nodes; i++) { ips.add("127.0.0." + i); }// www. jav a 2s .co m return Cluster.builder().addContactPoints(ips.toArray(new String[0])).build(); }
From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.shortherstPathMenuHandlers.DijkstraWeightedShortestPathMenuHandler.java
@Override public void actionPerformed(ActionEvent e) { final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); Collection<String> vertices = viewerPanel.getCurrentGraph().getVertices(); String[] test = vertices.toArray(new String[0]); Arrays.sort(test);/*from w w w . ja va2 s.co m*/ final String mFrom = (String) JOptionPane.showInputDialog(frame, "Choose A Node", "A Node", JOptionPane.PLAIN_MESSAGE, null, test, test[0]); final String mTo = (String) JOptionPane.showInputDialog(frame, "Choose B Node", "B Node", JOptionPane.PLAIN_MESSAGE, null, test, test[0]); String weightedKey = JOptionPane.showInputDialog(frame, "Enter Weighted Key", "Weighted Key", JOptionPane.QUESTION_MESSAGE); Transformer<String, Double> wtTransformer = new Transformer<String, Double>() { public Double transform(String edgeId) { return null; } }; final Graph<String, String> mGraph = viewerPanel.getCurrentGraph(); DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph, wtTransformer); final List<String> mPred = alg.getPath(mFrom, mTo); // System.out.println("The shortest unweighted path from" + mFrom +" to " + mTo + " is:"); // System.out.println(mPred.toString()); if (mPred == null) { JOptionPane.showMessageDialog(frame, String.format("Shortest path between %s,%s is not found", mFrom, mTo), "Message", JOptionPane.INFORMATION_MESSAGE); return; } final Layout<String, String> layout = vv.getGraphLayout(); for (final String edge : layout.getGraph().getEdges()) { if (mPred.contains(edge)) { vv.setEdgeStroke(edge, new BasicStroke(4f)); } } }
From source file:org.ambraproject.wombat.service.remote.ArticleApiImpl.java
@Override public CloseableHttpResponse requestAsset(String assetId, Collection<? extends Header> headers) throws IOException { HttpGet get = buildGet(ApiAddress.builder("assetfiles").addToken(assetId).build()); get.setHeaders(headers.toArray(new Header[headers.size()])); return cachedRemoteStreamer.getResponse(get); }
From source file:no.norrs.projects.andronary.tasks.DictListTask.java
@Override protected String[] doInBackground(String... lookup) { try {/*from www .j a va 2s . c o m*/ System.out.println(String.format("%s : %s : %s", lookup[0], lookup[1], lookup[2])); if (lookup[0] == null) { dl.showError(new Exception("Press menu and configure up webservice.."), null); return null; } UsernamePasswordCredentials creds = null; if (lookup[1] != null && lookup[2] != null && !lookup[1].equalsIgnoreCase("") && !lookup[2].equalsIgnoreCase("")) { creds = new UsernamePasswordCredentials(lookup[1], lookup[2]); } DictonaryParser dp = new DictonaryParser(); Collection<String> results = dp.dictonaries(Uri.parse(String.format("%s/languages/", lookup[0])), creds); return results.toArray(new String[results.size()]); } catch (IOException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } return null; }