Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

In this page you can find the example usage for java.util List toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:fi.foyt.fni.utils.licenses.CreativeCommonsUtils.java

public static String createLicenseUrl(boolean attribution, boolean derivatives, boolean shareAlike,
        boolean commercial) {
    List<String> properties = new ArrayList<String>();
    if (attribution) {
        properties.add("by");
    }//from  w  w  w.  ja v  a  2  s.  co  m

    if (!commercial) {
        properties.add("nc");
    }

    if (!derivatives) {
        properties.add("nd");
    }

    if (shareAlike) {
        properties.add("sa");
    }

    return createLicenseUrl(true, properties.toArray(new String[0]), null, null);
}

From source file:com.norconex.collector.core.pipeline.importer.SaveDocumentStage.java

private static String[] splitLargeSegment(String segment) {
    if (segment.length() <= MAX_SEGMENT_LENGTH) {
        return new String[] { segment };
    }//from  w w  w .j  a v  a 2  s.  c o  m

    List<String> segments = new ArrayList<>();
    StringBuilder b = new StringBuilder(segment);
    while (b.length() > MAX_SEGMENT_LENGTH) {
        segments.add(b.substring(0, MAX_SEGMENT_LENGTH));
        b.delete(0, MAX_SEGMENT_LENGTH);
    }
    segments.add(b.substring(0));
    return segments.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}

From source file:ddf.catalog.source.solr.provider.SolrProviderTestBase.java

protected static void deleteAll(int methodNameIndex) throws IngestException, UnsupportedQueryException {
    messageBreak(Thread.currentThread().getStackTrace()[methodNameIndex].getMethodName() + "()");

    QueryImpl query;/*ww w .  ja v a  2  s .  c  o m*/
    SourceResponse sourceResponse;
    query = new QueryImpl(filterBuilder.attribute(Metacard.ID).is().like().text("*"));
    query.setPageSize(ALL_RESULTS);
    sourceResponse = provider.query(new QueryRequestImpl(query));

    List<String> ids = new ArrayList<>();
    for (Result r : sourceResponse.getResults()) {
        ids.add(r.getMetacard().getId());
    }

    LOGGER.info("Records found for deletion: {}", ids);

    provider.delete(new DeleteRequestImpl(ids.toArray(new String[ids.size()])));

    LOGGER.info("Deletion complete. -----------");
}

From source file:Main.java

public static String[] readLines(InputStream is) throws IOException {

    URL url = null;/* www . j a  v  a2s  .  c  o  m*/

    BufferedReader bufferedReader = null;

    bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    // new InputStreamReader(new FileInputStream(filename), "iso-8859-1"));
    List<String> lines = new ArrayList<String>();
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {

        if (line.startsWith("<item>")) {
            String[] trim = line.split(">");
            String[] tmp = trim[1].split("</");
            lines.add(tmp[0]);
        }
    }
    bufferedReader.close();
    return lines.toArray(new String[lines.size()]);
}

From source file:jp.co.golorp.emarf.util.StringUtil.java

/**
 * @param value/* ww  w. j  av  a2  s  .  c  o  m*/
 *            
 * @return ?
 */
public static String[] toStringArray(final Object value) {

    String[] values = null;

    if (value instanceof String[]) {
        values = (String[]) value;
    } else if (value instanceof Object[]) {
        List<String> valueList = new ArrayList<String>();
        for (Object o : (Object[]) value) {
            valueList.add(String.valueOf(o));
        }
        values = valueList.toArray(new String[valueList.size() - 1]);
    } else if (value instanceof List) {
        List<?> valueList = (List<?>) value;
        if (valueList.size() > 0) {
            values = valueList.toArray(new String[valueList.size() - 1]);
        }
    } else if (value != null) {
        values = new String[] { String.valueOf(value) };
    }

    return values;
}

From source file:com.netflix.genie.server.repository.jpa.ClusterSpecs.java

/**
 * Get all the clusters given the specified parameters.
 *
 * @param commandId The id of the command that is registered with this cluster
 * @param statuses The status of the cluster
 * @return The specification//from  www  . j a va2  s  .co  m
 */
public static Specification<Cluster> findClustersForCommand(final String commandId,
        final Set<ClusterStatus> statuses) {
    return new Specification<Cluster>() {
        @Override
        public Predicate toPredicate(final Root<Cluster> root, final CriteriaQuery<?> cq,
                final CriteriaBuilder cb) {
            final List<Predicate> predicates = new ArrayList<>();
            final Join<Cluster, Command> commands = root.join(Cluster_.commands);

            predicates.add(cb.equal(commands.get(Command_.id), commandId));

            if (statuses != null && !statuses.isEmpty()) {
                //Could optimize this as we know size could use native array
                final List<Predicate> orPredicates = new ArrayList<>();
                for (final ClusterStatus status : statuses) {
                    orPredicates.add(cb.equal(root.get(Cluster_.status), status));
                }
                predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()])));
            }

            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
        }
    };
}

From source file:de.forsthaus.example.RandomDataEngine.java

private static String[] createStringArray(String name) {
    try {//  www .j  av a  2 s .com
        final InputStream inputStream = RandomDataEngine.class.getResourceAsStream("/example/" + name);
        try {
            final BufferedReader lr = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

            final List<String> r = new ArrayList<String>();
            String str;
            while ((str = lr.readLine()) != null) {
                if (StringUtils.isBlank(str)) {
                    continue;
                }
                r.add(str);
            }
            return r.toArray(new String[r.size()]);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.adobe.acs.commons.util.CookieUtil.java

/**
 * Remove the Cookies whose names match the provided Regex from Response
 *
 * @param request  Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 * @param regexes  Regex to find Cookies to drop
 * @return Number of Cookies dropped//  w w w . j  a v a  2 s . c om
 */
public static int dropCookiesByRegexArray(final HttpServletRequest request, final HttpServletResponse response,
        final String cookiePath, final String[] regexes) {
    int count = 0;
    if (regexes == null) {
        return count;
    }
    final List<Cookie> cookies = new ArrayList<Cookie>();

    for (final String regex : regexes) {
        cookies.addAll(getCookies(request, regex));
    }

    return dropCookies(response, cookies.toArray(new Cookie[cookies.size()]), cookiePath);
}

From source file:Main.java

/**
 * Get all the matches for {@code string} compiled by {@code pattern}. If 
 * {@code isGlobal} is true, the return results will only include the 
 * group 0 matches. It is similar to string.match(regexp) in JavaScript.
 * //w w  w  .  j ava 2s .  co  m
 * @param pattern the regexp
 * @param string the string
 * @param isGlobal similar to JavaScript /g flag
 * 
 * @return all matches
 */
public static String[] match(Pattern pattern, String string, boolean isGlobal) {
    if (pattern == null) {
        throw new NullPointerException("argument 'pattern' cannot be null");
    }
    if (string == null) {
        throw new NullPointerException("argument 'string' cannot be null");
    }

    List<String> matchesList = new ArrayList<String>();

    Matcher matcher = pattern.matcher(string);
    while (matcher.find()) {
        matchesList.add(matcher.group(0));
        if (!isGlobal) {
            for (int i = 1, iEnd = matcher.groupCount(); i <= iEnd; i++) {
                matchesList.add(matcher.group(i));
            }
        }
    }

    return matchesList.toArray(new String[matchesList.size()]);
}

From source file:org.querybyexample.jpa.JpaUtil.java

public static String[] toNames(SingularAttribute<?, ?>... attributes) {
    List<String> ret = newArrayList();
    for (SingularAttribute<?, ?> attribute : attributes) {
        ret.add(attribute.getName());/*from w ww.j av a 2s .co  m*/
    }
    return ret.toArray(new String[ret.size()]);
}