List of usage examples for java.util List toArray
<T> T[] toArray(T[] a);
From source file:com.google.api.ads.dfp.lib.utils.v201208.PqlUtils.java
/** * Gets the row values for a row of the result set in the form of an object * array./*from w w w. j av a2 s .c o m*/ * * @param row the row to get the values for * @return the object array of the row values * @throws IllegalArgumentException if the value could not be extracted from * the row value * @throws IllegalAccessException if the row value could not be accessed */ public static Object[] getRowValues(Row row) throws IllegalArgumentException, IllegalAccessException { List<Object> rowValues = new ArrayList<Object>(); for (Value value : row.getValues()) { rowValues.add(getValue(value)); } return rowValues.toArray(new Object[] {}); }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.BeanToTextExporter.java
public static String beanListToText(final String type, final Writer out, final Map<String, String> columns, final List data, final DateFormat dateFormat) { CSVWriter writer = new CSVWriter(out); if ("tab".equals(type)) { writer = new CSVWriter(out, '\t', CSVWriter.NO_QUOTE_CHARACTER); }/*from w ww . j a va2 s. co m*/ List<String> cols = new LinkedList<String>(); try { //Writing the column headers for (Map.Entry<String, String> e : columns.entrySet()) { cols.add(e.getValue()); } writer.writeNext((String[]) cols.toArray(new String[columns.size()])); cols.clear(); //Writing the data if (data != null) { for (Object o : data) { for (Map.Entry<String, String> e : columns.entrySet()) { final Object obj = getAndInvokeGetter(o, e.getKey()); String value = getExportString(obj, dateFormat); if ("tab".equals(type)) { value = value.replace("\t", " "); } cols.add(value); } writer.writeNext((String[]) cols.toArray(new String[columns.size()])); cols.clear(); } } writer.close(); out.flush(); out.close(); } catch (Exception e) { logger.debug(FancyExceptionLogger.printException(e)); return "An error occurred."; } return out.toString(); }
From source file:com.netflix.genie.server.repository.jpa.ApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param userName The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search the command for * @return A specification object used for querying *//*from w ww .j ava2 s . c om*/ public static Specification<Application> find(final String name, final String userName, final Set<ApplicationStatus> statuses, final Set<String> tags) { return new Specification<Application>() { @Override public Predicate toPredicate(final Root<Application> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(cb.equal(root.get(Application_.name), name)); } if (StringUtils.isNotBlank(userName)) { predicates.add(cb.equal(root.get(Application_.user), userName)); } if (statuses != null && !statuses.isEmpty()) { //Could optimize this as we know size could use native array final List<Predicate> orPredicates = new ArrayList<>(); for (final ApplicationStatus status : statuses) { orPredicates.add(cb.equal(root.get(Application_.status), status)); } predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null) { for (final String tag : tags) { if (StringUtils.isNotBlank(tag)) { predicates.add(cb.isMember(tag, root.get(Application_.tags))); } } } return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; }
From source file:Main.java
/** * Searches the node for content of type Long. If non-long content is found, * it logs a warning and returns null./*from w ww . j a v a 2 s. c o m*/ */ public static String[] extractStringArrayFromElement(Node element) { // Get all the children NodeList children = element.getChildNodes(); List<String> output = new ArrayList<String>(); for (int n = 0; n < children.getLength(); n++) { Node child = children.item(n); if (child.getNodeType() == Node.ELEMENT_NODE) { output.add(extractStringFromElement(child)); } } return output.toArray(new String[output.size()]); }
From source file:Main.java
public static String[] unknownWidgetTemplates() { List<String> templates = new ArrayList<String>(); // templates.scaffolding.UnknownTemplate templates.add(dot(DEFAULT_APPLICATION_TEMPLATE_PATH, KEY_UNKNOWN + KEY_TEMPLATE)); // griffon.plugins.scaffolding.UnknownTemplate templates.add(dot(DEFAULT_TEMPLATE_PATH, KEY_UNKNOWN + KEY_TEMPLATE)); return templates.toArray(new String[templates.size()]); }
From source file:Main.java
public static String[] getNodesValue(Element node, String nodeName) { List<String> ret = new ArrayList<String>(); NodeList ndLs = node.getElementsByTagName(nodeName); for (int s = 0; s < ndLs.getLength(); s++) { Node fstNode = ndLs.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { ret.add(fstNode.getTextContent()); }/*from ww w.j a va2 s . c om*/ } return ret.toArray(new String[0]); }
From source file:com.adaptris.mail.Pop3sReceiverFactory.java
private static String[] asArray(String s) { StringTokenizer st = new StringTokenizer(s, ","); List<String> l = new ArrayList<String>(); while (st.hasMoreTokens()) { String tok = st.nextToken().trim(); if (!isEmpty(tok)) l.add(tok);/*from ww w . j a va 2s .c o m*/ } return l.toArray(new String[0]); }
From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaJobSpecs.java
/** * Generate a criteria query predicate for a where clause based on the given parameters. * * @param root The root to use * @param cb The criteria builder to use * @param id The job id/* w w w. j a v a 2 s . c o m*/ * @param name The job name * @param user The user who created the job * @param statuses The job statuses * @param tags The tags for the jobs to find * @param clusterName The cluster name * @param cluster The cluster the job should have been run on * @param commandName The command name * @param command The command the job should have been run with * @param minStarted The time which the job had to start after in order to be return (inclusive) * @param maxStarted The time which the job had to start before in order to be returned (exclusive) * @param minFinished The time which the job had to finish after in order to be return (inclusive) * @param maxFinished The time which the job had to finish before in order to be returned (exclusive) * @param grouping The job grouping to search for * @param groupingInstance The job grouping instance to search for * @return The specification */ @SuppressWarnings("checkstyle:parameternumber") public static Predicate getFindPredicate(final Root<JobEntity> root, final CriteriaBuilder cb, @Nullable final String id, @Nullable final String name, @Nullable final String user, @Nullable final Set<JobStatus> statuses, @Nullable final Set<String> tags, @Nullable final String clusterName, @Nullable final ClusterEntity cluster, @Nullable final String commandName, @Nullable final CommandEntity command, @Nullable final Instant minStarted, @Nullable final Instant maxStarted, @Nullable final Instant minFinished, @Nullable final Instant maxFinished, @Nullable final String grouping, @Nullable final String groupingInstance) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(id)) { predicates.add( JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.uniqueId), id)); } if (StringUtils.isNotBlank(name)) { predicates .add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates .add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(JobEntity_.status), status)).collect(Collectors.toList()); predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null && !tags.isEmpty()) { predicates.add( cb.like(root.get(JobEntity_.tagSearchString), JpaSpecificationUtils.getTagLikeString(tags))); } if (cluster != null) { predicates.add(cb.equal(root.get(JobEntity_.cluster), cluster)); } if (StringUtils.isNotBlank(clusterName)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.clusterName), clusterName)); } if (command != null) { predicates.add(cb.equal(root.get(JobEntity_.command), command)); } if (StringUtils.isNotBlank(commandName)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.commandName), commandName)); } if (minStarted != null) { predicates.add(cb.greaterThanOrEqualTo(root.get(JobEntity_.started), minStarted)); } if (maxStarted != null) { predicates.add(cb.lessThan(root.get(JobEntity_.started), maxStarted)); } if (minFinished != null) { predicates.add(cb.greaterThanOrEqualTo(root.get(JobEntity_.finished), minFinished)); } if (maxFinished != null) { predicates.add(cb.lessThan(root.get(JobEntity_.finished), maxFinished)); } if (grouping != null) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.grouping), grouping)); } if (groupingInstance != null) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.groupingInstance), groupingInstance)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }
From source file:Main.java
public static String[] toSelectionArgs(Object... args) { if (args == null) return null; List<String> results = new ArrayList<String>(); for (Object arg : args) { if (arg instanceof Iterable) { for (Object it : (Iterable) arg) results.add(toSelectionArg(it)); } else {//from w w w . j av a2 s. com results.add(toSelectionArg(arg)); } } return results.toArray(new String[results.size()]); }
From source file:edu.pitt.dbmi.ccd.db.specification.GroupSpecification.java
private static Predicate buildSearchSpec(Root<Group> root, CriteriaBuilder cb, Set<String> matches, Set<String> nots) { List<Predicate> predicates = new ArrayList<>(0); if (!isEmpty(matches)) { predicates.addAll(inNameOrDescription(root, cb, matches)); }/*from w w w . j av a2 s.c o m*/ if (!isEmpty(nots)) { predicates.addAll(notInNameOrDescription(root, cb, nots)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }