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:org.cleverbus.core.common.contextcall.ReflectionCallUtils.java

/**
 * Invokes target method.//from w  w  w  .java  2  s  .c  o  m
 *
 * @param params the parameters of the call
 * @param beanFactory the Spring bean factory
 * @return response
 */
public static Object invokeMethod(ContextCallParams params, BeanFactory beanFactory) {
    // find target service
    Object targetService = beanFactory.getBean(params.getTargetType());

    // determine method's argument types
    List<Class> argTypes = new ArrayList<Class>();
    for (Object arg : params.getMethodArgs()) {
        argTypes.add(arg.getClass());
    }

    // exist method?
    Method method = ReflectionUtils.findMethod(params.getTargetType(), params.getMethodName(),
            argTypes.toArray(new Class[] {}));
    if (method == null) {
        throw new IllegalStateException("there is no method '" + params.getMethodName() + "' on target type '"
                + params.getTargetType().getSimpleName() + "'");
    }

    // invoke method
    return ReflectionUtils.invokeMethod(method, targetService, params.getMethodArgs().toArray());
}

From source file:com.proofpoint.jmx.JmxHttpModule.java

@SuppressWarnings("unchecked")
private static List<Map<String, Object>> toList(TabularData data) {
    ImmutableList.Builder<Map<String, Object>> builder = ImmutableList.builder();

    // never trust JMX to do the right thing
    Set<List<?>> keySet = (Set<List<?>>) data.keySet();
    if (keySet != null) {
        for (List<?> key : keySet) {
            if (key != null && !key.isEmpty()) {
                Object[] index = key.toArray(new Object[key.size()]);
                CompositeData value = data.get(index);
                if (value != null) {
                    builder.add(toMap(value));
                }/* www. ja  v  a 2 s  . com*/
            }
        }
    }
    return builder.build();
}

From source file:fr.ippon.tatami.test.support.LdapTestServer.java

private static void injectEntry(LdifEntry entry, DirectoryService service) throws Exception {
    if (entry.isChangeAdd()) {
        ServerEntry serverEntry = service.newEntry(entry.getDn());
        for (EntryAttribute entryAttribute : entry.getEntry()) {
            List<Value> allValue = new ArrayList<Value>();
            for (Value<?> value : entryAttribute) {
                allValue.add(value);//from   w  ww.  jav a  2  s  .co m
            }
            serverEntry.add(entryAttribute.getId(), allValue.toArray(new Value[0]));
        }
        service.getAdminSession().add(serverEntry);
        // service.getAdminSession().add( new DefaultServerEntry( service.getSchemaManager(), entry.getEntry() ) );
    } else if (entry.isChangeModify()) {
        // not used, not tested ...
        service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
    } else {
        throw new IllegalArgumentException("bug");
    }
}

From source file:Main.java

public static String[] readTextFile(String filename) throws IOException {
    List<String> wordList = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new FileReader(filename));
    String line;//from   www .  j ava 2s .  co m
    while ((line = reader.readLine()) != null) {
        wordList.add(line);
    }
    reader.close();
    String[] words = new String[wordList.size()];
    wordList.toArray(words);
    return words;
}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

private static File[] loadMonitoredPaths(XMLConfiguration xml) {
    List<HierarchicalConfiguration> nodes = xml.configurationsAt("monitored-paths.path");
    List<File> paths = new ArrayList<File>();
    for (HierarchicalConfiguration node : nodes) {
        paths.add(new File(node.getString("")));
    }//from w ww.  j ava  2 s .c o  m
    return paths.toArray(new File[] {});
}

From source file:ClassUtil.java

/**
 * Retrieves all interfaces implemented by a specified interface
 * including all recursively extended interfaces and the classes supplied
 * int the parameter.//from ww w. j a v a2 s .c om
 * @param childInterfaces a set of interfaces
 * @return Class[] an array of interfaces that includes those specifed
 * in childInterfaces plus all of those interfaces' super interfaces
 */
public static Class[] getSuperInterfaces(Class[] childInterfaces) {

    List allInterfaces = new ArrayList();

    for (int i = 0; i < childInterfaces.length; i++) {
        allInterfaces.add(childInterfaces[i]);
        allInterfaces.addAll(Arrays.asList(getSuperInterfaces(childInterfaces[i].getInterfaces())));
    }

    return (Class[]) allInterfaces.toArray(new Class[allInterfaces.size()]);
}

From source file:org.apache.ambari.view.hive.client.Utils.java

/**
 * Removes the empty strings and returns back only the strings with content
 *//* w  w  w.j  a v a  2 s  .  c o  m*/
static String[] removeEmptyStrings(String[] strs) {
    List<String> nonEmptyStrings = new ArrayList<>();
    for (String str : strs) {
        if (!(str == null || str.trim().isEmpty())) {
            nonEmptyStrings.add(str.trim());
        }
    }
    return nonEmptyStrings.toArray(new String[] {});
}

From source file:com.chiorichan.util.StringUtil.java

/**
 * Scans a string list for entries that are not lower case.
 * /* w w  w. ja  va  2s .  c om*/
 * @param stringList
 *            The original list to check.
 * @return The corrected string list.
 */
public static List<String> toLowerCase(List<String> stringList) {
    String[] array = toLowerCase(stringList.toArray(new String[0]));

    try {
        stringList.clear();
    } catch (UnsupportedOperationException e) {
        // In this case we can't preserve the original list type.
        stringList = Lists.newArrayList();
    }

    for (String s : array)
        stringList.add(s);

    return stringList;
}

From source file:com.ushahidi.swiftriver.core.solr.util.QueryUtil.java

/**
 * Given a comma-separated list of search terms; 
 * <code>searchTerms</code>, converts the list to an array
 * and concatenates the elements using "AND".
 * /*from  ww  w . j a  va  2  s.c o m*/
 * If <code>searchTerm</code> comprises of only one string,
 * no modification takes place
 * 
 * @param searchTerms
 * @return
 */
public static String getQueryString(String searchTerms) {
    if (searchTerms == null || searchTerms.trim().length() == 0)
        return "*:*";

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

    // Sanitize the each keyword
    for (String keyword : searchTerms.split(",")) {
        if (searchTerms.trim().length() > 1) {
            keywordsList.add(keyword.trim());
        }
    }
    String[] keywordsArray = keywordsList.toArray(new String[keywordsList.size()]);

    return keywordsArray.length == 1 ? searchTerms : StringUtils.join(keywordsArray, " AND ");

}

From source file:jp.co.ntts.vhut.exception.DBStillReferencedRuntimeException.java

/**
 * @param target/*from  ww w. j  a va 2 s  .  c  o  m*/
 * @param referencings
 * @return
 */
private static Object[] createArgs(IIdentifiableEntity target, IIdentifiableEntity[] referencings) {
    String targetClass = target.getClass().getName();
    String targetId = target.getId().toString();
    String referencingClass = null;
    String idlist = null;
    if (referencings.length > 0) {
        referencingClass = referencings[0].getClass().getName();
        List<Long> ids = new ArrayList<Long>();
        for (IIdentifiableEntity referencig : referencings) {
            ids.add(referencig.getId());
        }
        idlist = StringUtils.join(ids.toArray(new Long[0]));
    }
    return new Object[] { targetClass, targetId, referencingClass, idlist };
}