List of usage examples for java.util List toArray
<T> T[] toArray(T[] a);
From source file:com.espertech.esper.epl.parse.ASTGraphHelper.java
private static String[] parseParamsStreamNames(Tree paramsRoot) { List<String> paramNames = new ArrayList<String>(1); for (int i = 0; i < paramsRoot.getChildCount(); i++) { Tree child = paramsRoot.getChild(i); if (child.getType() == EsperEPL2GrammarParser.CLASS_IDENT) { paramNames.add(child.getText()); }/* w w w.j a v a2 s. c o m*/ } return paramNames.toArray(new String[paramNames.size()]); }
From source file:com.liferay.blade.tests.BladeCLI.java
public static String execute(File workingDir, String... bladeArgs) throws Exception { String bladeCLIJarPath = getLatestBladeCLIJar(); List<String> command = new ArrayList<>(); command.add("java"); command.add("-jar"); command.add(bladeCLIJarPath);/*from www. j ava2 s . co m*/ for (String arg : bladeArgs) { command.add(arg); } Process process = new ProcessBuilder(command.toArray(new String[0])).directory(workingDir).start(); process.waitFor(); InputStream stream = process.getInputStream(); String output = new String(IO.read(stream)); InputStream errorStream = process.getErrorStream(); String errors = new String(IO.read(errorStream)); assertTrue(errors, errors == null || errors.isEmpty()); output = StringUtil.toLowerCase(output); return output; }
From source file:Main.java
public static Element[] getChildrenByAttrubte(Element parent, String attrName, String attrValue) { NodeList nodes = parent.getChildNodes(); int len = nodes.getLength(); Element temp;/*from www.j a v a 2s. c om*/ List<Element> list = new ArrayList<Element>(len); if (nodes != null && len > 0) { for (int i = 0; i < len; i++) { if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) { temp = (Element) nodes.item(i); if (getAttribute(temp, attrName).equalsIgnoreCase(attrValue)) list.add(temp); } } } return list.toArray(new Element[list.size()]); }
From source file:ai.grakn.migration.base.MigrationCLI.java
private static List<String[]> extractOptionsFromConfiguration(String path, String[] args) { // check file exists File configuration = new File(path); if (!configuration.exists()) { throw new RuntimeException("Could not find configuration file " + path); }/* ww w. j a v a2 s . c om*/ try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configuration), Charset.defaultCharset())) { List<Map<String, String>> config = (List<Map<String, String>>) new Yaml().load(reader); List<String[]> options = new ArrayList<>(); for (Map<String, String> c : config) { List<String> parameters = new ArrayList<>(Arrays.asList(args)); c.entrySet().stream().flatMap(m -> Stream.of("-" + m.getKey(), m.getValue())) .forEach(parameters::add); options.add(parameters.toArray(new String[parameters.size()])); } return options; } catch (IOException e) { throw new RuntimeException("Could not parse configuration file."); } }
From source file:org.wallride.repository.PageSpecifications.java
public static Specification<Page> children(Page page, boolean includeUnpublished) { return (root, query, cb) -> { query.distinct(true);//from ww w . j a v a 2s .c om List<Predicate> predicates = new ArrayList<>(); predicates.add(cb.equal(root.get(Page_.parent).get(Page_.id), page.getId())); if (!includeUnpublished) { predicates.add(cb.equal(root.get(Page_.status), Page.Status.PUBLISHED)); } query.orderBy(cb.asc(root.get(Page_.lft))); return cb.and(predicates.toArray(new Predicate[0])); }; }
From source file:SocketFetcher.java
/** * Parse a string into whitespace separated tokens and return the tokens in an * array./*from w w w . j a va2 s. com*/ */ private static String[] stringArray(String s) { StringTokenizer st = new StringTokenizer(s); List tokens = new ArrayList(); while (st.hasMoreTokens()) tokens.add(st.nextToken()); return (String[]) tokens.toArray(new String[tokens.size()]); }
From source file:ch.systemsx.cisd.openbis.generic.server.authorization.DefaultReturnValueFilter.java
private final static <T> T[] proceedArray(final PersonPE person, final Method method, final IValidator<T> validator, final T[] returnValue) { if (returnValue.length == 0) { return returnValue; }//from w ww .j ava 2s .c o m final List<T> list = FilteredList.decorate(returnValue, new ValidatorAdapter<T>(validator, person)); final T[] array = castToArray(Array.newInstance(returnValue.getClass().getComponentType(), list.size())); final T[] newValue = castToArray(list.toArray(array)); int diff = returnValue.length - newValue.length; if (diff > 0) { operationLog.info(String.format(FILTER_APPLIED_ON_ARRAY, MethodUtils.describeMethod(method), diff)); } return newValue; }
From source file:com.openlegacy.enterprise.ide.eclipse.editors.pages.details.jpa.FieldsJpaManyToOneFieldDetailsPage.java
private static String[] getFetchTypeItems() { List<String> list = new ArrayList<String>(); list.add(FetchType.EAGER.toString()); list.add(FetchType.LAZY.toString()); return list.toArray(new String[] {}); }
From source file:com.adguard.commons.utils.ReservedDomains.java
/** * Initializes/*from w ww. j av a 2 s. c om*/ */ private static synchronized void initialize() { try { if (reservedDomainNames != null) { // Double check return; } LOG.info("Initialize ReservedDomains object"); InputStream inputStream = ReservedDomains.class.getResourceAsStream("/effective_tld_names.dat"); InputStreamReader reader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(reader); List<String> domains = new ArrayList<>(); String line; while ((line = bufferedReader.readLine()) != null) { line = line.trim(); if (!StringUtils.isBlank(line)) { domains.add(line); } } reservedDomainNames = new String[domains.size()]; domains.toArray(reservedDomainNames); Arrays.sort(reservedDomainNames); LOG.info("ReservedDomains object has been initialized"); } catch (Exception ex) { throw new RuntimeException("Cannot initialize reserved domains collection", ex); } }
From source file:org.opensprout.osaf.util.WebServiceUtils.java
public static <T, S> T[] copyToDto(List<S> list, Class<T> dtoclass, T[] blankArray, CopyBeanToDtoTemplate<S, T> template) { List<T> dtos = new ArrayList<T>(); for (S source : list) { T dto;//from ww w . j a va 2s .com try { dto = (T) dtoclass.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } BeanUtils.copyProperties(source, dto); if (template != null) template.copy(source, dto); dtos.add(dto); } return dtos.toArray(blankArray); }