List of usage examples for java.util List toArray
<T> T[] toArray(T[] a);
From source file:com.jayway.jaxrs.hateoas.HateoasVerbosity.java
/** * Get a HateoasVerbosity corresponding to the comma-delimited String of {@link HateoasOption} values. * * @param optionsString comma-delimited (,) or semi-colon (;) String of {@link HateoasOption} values * @return a HateoasVerbosity instance wrapping all the specified options, * or the default verbosity if an empty string is specified. * @throws IllegalArgumentException if an invalid option is supplied *//*from w w w .j a v a 2 s.c o m*/ public static HateoasVerbosity valueOf(String optionsString) { if (StringUtils.isNotBlank(optionsString)) { String[] headerSplit; if (optionsString.contains(",")) { headerSplit = StringUtils.split(optionsString, ","); } else { headerSplit = StringUtils.split(optionsString, ";"); } List<HateoasOption> options = new LinkedList<HateoasOption>(); for (String oneOption : headerSplit) { options.add(HateoasOption.valueOf(oneOption.trim())); } return new HateoasVerbosity(options.toArray(new HateoasOption[0])); } else { return defaultVerbosity; } }
From source file:com.netflix.genie.core.jpa.specifications.JpaCommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param user The name of the user who created the command * @param statuses The status of the command * @param tags The set of tags to search the command for * @return A specification object used for querying *//* w ww . j a v a 2 s .c o m*/ public static Specification<CommandEntity> find(final String name, final String user, final Set<CommandStatus> statuses, final Set<String> tags) { return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.name), name)); } if (StringUtils.isNotBlank(user)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(CommandEntity_.user), user)); } if (statuses != null && !statuses.isEmpty()) { final List<Predicate> orPredicates = statuses.stream() .map(status -> cb.equal(root.get(CommandEntity_.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(CommandEntity_.tags), JpaSpecificationUtils.getTagLikeString(tags))); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }; }
From source file:com.bosscs.spark.commons.utils.AnnotationUtils.java
/** * Utility method that filters out all the fields _not_ annotated * with the {@link com.bosscs.spark.commons.annotations.HadoopField} annotation. * * @param clazz the Class object for which we want to resolve deep fields. * @return an array of deep Field(s)./*w w w . j a v a 2 s .c o m*/ */ public static Field[] filterDeepFields(Class clazz) { Field[] fields = Utils.getAllFields(clazz); List<Field> filtered = new ArrayList<>(); for (Field f : fields) { if (f.isAnnotationPresent(HadoopField.class)) { filtered.add(f); } } return filtered.toArray(new Field[filtered.size()]); }
From source file:com.mxep.web.common.persistence.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override// w ww . j a va2s. c o m public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (Collections3.isNotEmpty(filters)) { List<Predicate> predicates = getPredicate(filters, root, query, builder); // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }
From source file:com.norconex.jefmon.model.ConfigurationDAO.java
private static String[] loadRemoteUrls(XMLConfiguration xml) { List<HierarchicalConfiguration> nodes = xml.configurationsAt("remote-instances.url"); List<String> urls = new ArrayList<String>(); for (HierarchicalConfiguration node : nodes) { urls.add(node.getString("")); }/*from w w w .j a va2s . c om*/ return urls.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
From source file:com.bluexml.xforms.messages.DefaultMessages.java
private static String[] getPropertiesAsStringArray(String fileName) { String[] lines = null;/*from w w w . j av a 2 s . co m*/ // get file stream from classPath InputStream in = DefaultMessages.class.getResourceAsStream(fileName); List<?> l = null; try { l = IOUtils.readLines(in); } catch (IOException e) { l = new ArrayList<String>(); System.err.println("Stream for default file " + fileName + " can't be oppened :" + e); } lines = l.toArray(new String[l.size()]); return lines; }
From source file:com.netflix.genie.core.jpa.specifications.JpaJobSpecs.java
/** * Generate a criteria query predicate for a where clause based on the given parameters. * * @param root The root to use/* www. ja v a 2 s .c o m*/ * @param cb The criteria builder to use * @param id The job id * @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) * @return The specification */ public static Predicate getFindPredicate(final Root<JobEntity> root, final CriteriaBuilder cb, final String id, final String name, final String user, final Set<JobStatus> statuses, final Set<String> tags, final String clusterName, final ClusterEntity cluster, final String commandName, final CommandEntity command, final Date minStarted, final Date maxStarted, final Date minFinished, final Date maxFinished) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(id)) { predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb, root.get(JobEntity_.id), 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_.tags), 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)); } return cb.and(predicates.toArray(new Predicate[predicates.size()])); }
From source file:org.eclipse.virgo.snaps.SnapsTagTests.java
private static final String[] toArray(Enumeration<?> enumeration) { List<String> list = new ArrayList<String>(); while (enumeration.hasMoreElements()) { String element = enumeration.nextElement().toString(); list.add(element);/* w ww .j a v a 2 s . c o m*/ } return list.toArray(new String[list.size()]); }
From source file:com.googlecode.jtiger.modules.ecside.core.TableModelUtils.java
/** * The value needs to be a String[]. A String, Null, or List will be * converted to a String[]. In addition it will attempt to do a String * conversion for other object types./*from w w w. ja va 2s . com*/ * * @param value The value to convert to an String[] * @return A String[] value. */ public static String[] getValueAsArray(Object value) { if (value == null) { return new String[] {}; // put in a placeholder } if (value instanceof String[]) { return (String[]) value; } else if (value instanceof List) { List valueList = (List) value; return (String[]) valueList.toArray(new String[valueList.size()]); } return new String[] { value.toString() }; }
From source file:kieker.tools.opad.timeseries.forecast.mean.MeanForecasterJava.java
/** * * @param allHistory// w ww . j av a 2 s . c om * List there null values should deltet in this function * @return List/Array with no NullValues */ public static Double[] removeNullValues(final List<Double> allHistory) { final List<Double> newList = new ArrayList<Double>(); for (final Object obj : allHistory) { if ((null != obj) && (obj instanceof Double) && !Double.isNaN((Double) obj)) { newList.add((Double) obj); } } return newList.toArray(new Double[newList.size()]); }