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:de.tudarmstadt.ukp.experiments.argumentation.convincingness.features.POSNGramFeature.java

public static FrequencyDistribution<String> getSentencePosNGrams(JCas jcas, int minN, int maxN,
        boolean useCanonical, Paragraph paragraph) {
    FrequencyDistribution<String> result = new FrequencyDistribution<String>();

    List<String> posTagString = new ArrayList<String>();
    for (POS p : JCasUtil.selectCovered(jcas, POS.class, paragraph)) {
        if (useCanonical) {
            posTagString.add(p.getClass().getSimpleName());
        } else {/*from   w  ww  . ja v  a 2s . co m*/
            posTagString.add(p.getPosValue());
        }
    }
    String[] posAsArray = posTagString.toArray(new String[posTagString.size()]);

    for (List<String> nGram : new NGramStringListIterable(posAsArray, minN, maxN)) {
        result.inc(StringUtils.join(nGram, "_"));

    }

    return result;
}

From source file:org.jspringbot.keyword.expression.engine.function.StaticMethodUtils.java

public static Method getMethod(Class clazz, String methodSignature) {
    Matcher matcher = METHOD_SIGNATURE_PATTERN.matcher(methodSignature);

    if (matcher.find()) {
        String methodName = matcher.group(2);
        String parameterTypes = matcher.group(3);

        List<Class> types = new ArrayList<Class>();
        for (String parameterType : StringUtils.split(parameterTypes, ',')) {
            ClassEditor editor = new ClassEditor();
            editor.setAsText(parameterType);
            types.add((Class) editor.getValue());
        }/* ww w.  ja v  a 2s .co m*/

        return MethodUtils.getAccessibleMethod(clazz, methodName, types.toArray(new Class[types.size()]));
    }

    throw new IllegalStateException(String.format("Invalid method signature '%s' found.", methodSignature));
}

From source file:com.codebutler.farebot.keys.ClassicCardKeys.java

public static ClassicCardKeys fromDump(String keyType, byte[] keyData) {
    List<ClassicSectorKey> keys = new ArrayList<ClassicSectorKey>();

    int numSectors = keyData.length / KEY_LEN;
    for (int i = 0; i < numSectors; i++) {
        int start = i * KEY_LEN;
        keys.add(new ClassicSectorKey(keyType, Arrays.copyOfRange(keyData, start, start + KEY_LEN)));
    }//  w w w .  j a  va  2  s.  c om

    return new ClassicCardKeys(keys.toArray(new ClassicSectorKey[keys.size()]));
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.morpho.POSNgram.java

public static FrequencyDistribution<String> getSentencePosNGrams(JCas jcas, int minN, int maxN,
        boolean useCanonical, Sentence Sentence) {
    FrequencyDistribution<String> result = new FrequencyDistribution<>();

    List<String> posTagString = new ArrayList<>();
    for (POS p : JCasUtil.selectCovered(jcas, POS.class, Sentence)) {
        if (useCanonical) {
            posTagString.add(p.getClass().getSimpleName());
        } else {/*w  w w .  j  a va  2 s. c o  m*/
            posTagString.add(p.getPosValue());
        }
    }
    String[] posAsArray = posTagString.toArray(new String[posTagString.size()]);

    for (List<String> nGram : new NGramStringListIterable(posAsArray, minN, maxN)) {
        result.inc(StringUtils.join(nGram, NGramUtils.NGRAM_GLUE));

    }

    return result;
}

From source file:io.fabric8.maven.core.util.ClassUtil.java

private static ClassLoader[] mergeClassLoaders(List<ClassLoader> additionalClassLoaders) {
    ClassLoader[] classLoaders;/*from   w  ww  .  j  a va 2 s  . c om*/

    if (additionalClassLoaders != null && !additionalClassLoaders.isEmpty()) {
        classLoaders = ArrayUtils.addAll(getClassLoaders(),
                additionalClassLoaders.toArray(new ClassLoader[additionalClassLoaders.size()]));
    } else {
        classLoaders = getClassLoaders();
    }
    return classLoaders;
}

From source file:com.liferay.portal.test.TestUtil.java

public static ApplicationContext initSpringForPortlet(String portletName) throws Exception {
    setPortletClassLoader();// w  w w.  java 2 s.c  om
    List<String> configLocations = getPortletConfigLocations(portletName);

    BeanLocatorImpl impl = (BeanLocatorImpl) PortalBeanLocatorUtil.getBeanLocator();
    ApplicationContext parent = impl.getApplicationContext();

    String[] locations = configLocations.toArray(new String[0]);
    ApplicationContext context = new FileSystemXmlApplicationContext(locations, parent);

    return context;
}

From source file:Main.java

/**
 * Get package names of all installed apps.
 * @param with_system Mark if system apps are included or not.
 *///from  w  ww  .j av a2 s  . co m
public static String[] getAllInstalledPackageNames(Context context, boolean with_system) {
    List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(0);
    if (packages == null) {
        return null;
    }

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

    for (ApplicationInfo applicationInfo : packages) {
        //Skip over system apps.
        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1 && !with_system) {
            continue;
        }

        result.add(applicationInfo.packageName);
    }

    Collections.sort(result);

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

From source file:com.netradius.hibernate.support.HibernateUtil.java

private static List<String[]> getTables() {
    final List<String[]> rows = new ArrayList<String[]>();
    rows.add(new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS", "TYPE_CAT",
            "TYPE_SCHEM", "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION " });
    Connection con = null;//  w  w  w  .  j  a v  a2 s .  co  m
    ResultSet rs = null;
    try {
        con = getConnection();
        final DatabaseMetaData md = con.getMetaData();
        rs = md.getTables(null, null, "%", null);
        while (rs.next()) {
            List<String> s = new ArrayList<String>(10);
            for (int i = 10; i > 0; i--)
                s.add(rs.getString(i));
            rows.add(s.toArray(new String[10]));
        }
    } catch (SQLException x) {
        log.error("Error listing tables: " + x.getMessage(), x);
    } finally {
        close(con, null, rs);
    }
    return rows;
}

From source file:com.silverwrist.util.StringUtils.java

/**
 * Splits the provided text into a list, based on a given separator. The separator is not included in the
 * returned String array. The maximum number of splits to perfom can be controlled.
 *
 * @param text The string to parse./*from   ww  w .jav a 2s .c o m*/
 * @param separator Character used as the delimiter.
 * @param limit The maximum number of elements to include in the list. A zero or negative value implies no limit.
 * @return An array of parsed Strings.
 */
public static final String[] split1(String text, char separator, int limit) {
    List tmp = split1List(text, separator, limit);
    String[] rc = new String[tmp.size()];
    tmp.toArray(rc);
    return rc;

}

From source file:ExifUtils.ExifReadWrite.java

private static ArrayList<String> exifTool(List<String> parameters, File directory) {
    return exifTool(parameters.toArray(new String[0]), directory);
}