Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <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:ResourceBundleSupport.java

private static String[] parseVersions(String version) {
    if (version == null) {
        return new String[0];
    }/*  w  w w  . j  a v a 2 s  .  co  m*/

    final ArrayList versions = new ArrayList();
    final StringTokenizer strtok = new StringTokenizer(version, ".");
    while (strtok.hasMoreTokens()) {
        versions.add(strtok.nextToken());
    }
    return (String[]) versions.toArray(new String[versions.size()]);
}

From source file:com.tesora.dve.sql.schema.cache.NonMTCachedPlan.java

@SuppressWarnings("rawtypes")
private SchemaCacheKey[] buildTableKeySet(ListSet<TableKey> tabs) {
    ArrayList<SchemaCacheKey<?>> buf = new ArrayList<SchemaCacheKey<?>>();

    for (TableKey tk : tabs) {
        SchemaCacheKey<?> sck = tk.getCacheKey();
        buf.add(sck);/*  w ww. ja  v a 2 s.  co  m*/
    }
    return buf.toArray(new SchemaCacheKey[0]);
}

From source file:com.technophobia.substeps.model.Arguments.java

public static String[] getArgs(final String patternString, final String sourceString,
        final String[] keywordPrecedence, Config cfg) {

    log.debug("Arguments getArgs String[] with pattern: " + patternString + " and sourceStr: " + sourceString);

    String[] rtn = null;//from w ww .  j  a v a2s .c  o  m

    ArrayList<String> argsList = null;

    String patternCopy = patternString;
    if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) {
        //
        for (String s : keywordPrecedence) {

            patternCopy = StringUtils.removeStart(patternCopy, s);
        }

        patternCopy = "(?:" + StringUtils.join(keywordPrecedence, "|") + ")" + patternCopy;
    }

    final Pattern pattern = Pattern.compile(patternCopy);
    final Matcher matcher = pattern.matcher(sourceString);

    final int groupCount = matcher.groupCount();

    // TODO - this doesn't work if we're not doing strict matching
    if (matcher.find()) {

        for (int i = 1; i <= groupCount; i++) {
            final String arg = substituteValues(matcher.group(i), cfg);

            if (arg != null) {
                if (argsList == null) {
                    argsList = new ArrayList<>();
                }
                argsList.add(arg);
            }
        }
    }

    if (argsList != null) {
        rtn = argsList.toArray(new String[argsList.size()]);

        if (log.isDebugEnabled()) {

            final StringBuilder buf = new StringBuilder();
            buf.append("returning args: ");

            for (final String s : argsList) {

                buf.append("[").append(s).append("] ");
            }

            log.debug(buf.toString());
        }

    }

    return rtn;
}

From source file:org.sonar.plugins.buildstability.BuildStabilityChart.java

private void configureRenderer(CategoryPlot plot, String colors) {
    ColoredBarRenderer renderer = new ColoredBarRenderer();

    String[] pairs = StringUtils.split(colors, ";");
    ArrayList<Paint> paints = new ArrayList<Paint>();
    for (String pair : pairs) {
        String[] keyValue = StringUtils.split(pair, "=");
        paints.add("r".equals(keyValue[1]) ? Color.RED : Color.GREEN);
    }//from   w  w w.j a  va  2  s. co  m

    renderer.setColors(paints.toArray(new Paint[paints.size()]));
    renderer.setDrawBarOutline(true);
    renderer.setSeriesItemLabelsVisible(0, true);
    renderer.setItemMargin(0);
    plot.setRenderer(renderer);
}

From source file:gsn.wrappers.GPSGenerator.java

public boolean initialize() {
    AddressBean addressBean = getActiveAddressBean();
    if (addressBean.getPredicateValue("rate") != null) {
        samplingRate = ParamParser.getInteger(addressBean.getPredicateValue("rate"), DEFAULT_SAMPLING_RATE);
        if (samplingRate <= 0) {
            logger.warn(//from  www  .  j  a v a  2 s .  c  o  m
                    "The specified >sampling-rate< parameter for the >MemoryMonitoringWrapper< should be a positive number.\nGSN uses the default rate ("
                            + DEFAULT_SAMPLING_RATE + "ms ).");
            samplingRate = DEFAULT_SAMPLING_RATE;
        }
    }
    if (addressBean.getPredicateValue("picture") != null) {
        String picture = addressBean.getPredicateValue("picture");
        File pictureF = new File(picture);
        if (!pictureF.isFile() || !pictureF.canRead()) {
            logger.warn("The GPSGenerator can't access the specified picture file. Initialization failed.");
            return false;
        }
        try {
            BufferedInputStream fis = new BufferedInputStream(new FileInputStream(pictureF));
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4 * 1024];
            while (fis.available() > 0)
                outputStream.write(buffer, 0, fis.read(buffer));
            fis.close();
            this.picture = outputStream.toByteArray();
            outputStream.close();
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage(), e);
            return false;
        } catch (IOException e) {
            logger.warn(e.getMessage(), e);
            return false;
        }
    } else {
        logger.warn("The >picture< parameter is missing from the GPSGenerator wrapper.");
        return false;
    }
    ArrayList<DataField> output = new ArrayList<DataField>();
    for (int i = 0; i < FIELD_NAMES.length; i++)
        output.add(new DataField(FIELD_NAMES[i], FIELD_TYPES_STRING[i], FIELD_DESCRIPTION[i]));
    outputStrcture = output.toArray(new DataField[] {});
    return true;
}

From source file:com.cloudera.sqoop.hive.TableDefWriter.java

/**
 * Get the column names to import.// www  .j  av a  2 s . c  om
 */
private String[] getColumnNames() {
    String[] colNames = options.getColumns();
    if (null != colNames) {
        return colNames; // user-specified column names.
    } else if (null != externalColTypes) {
        // Test-injection column mapping. Extract the col names from this.
        ArrayList<String> keyList = new ArrayList<String>();
        for (String key : externalColTypes.keySet()) {
            keyList.add(key);
        }

        return keyList.toArray(new String[keyList.size()]);
    } else if (null != inputTableName) {
        return connManager.getColumnNames(inputTableName);
    } else {
        return connManager.getColumnNamesForQuery(options.getSqlQuery());
    }
}

From source file:com.ikon.util.MailUtils.java

/**
 * Conversion from array of Recipient to array of Strings.
 *//*  w w w  . ja  v  a 2s  .  c  om*/
private static String[] recipientToString(List<RecipientEntry> recipEntries) {
    ArrayList<String> list = new ArrayList<String>();

    if (recipEntries != null) {
        for (RecipientEntry re : recipEntries) {
            list.add(re.getToName() + " <" + re.getToEmail() + ">");
        }
    }

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

From source file:net.ostis.scpdev.wizards.AbstractScFileNewWizardPage.java

/**
 * Sets the template options in the passed list (swt)
 */// ww  w  .ja  v  a 2 s .  c  o m
private void fillTemplateOptions(TemplatePersistenceData[] templateData, List list) {
    name2templateData = new TreeMap<String, TemplatePersistenceData>();

    String[] neededContextTypes = getContextTypes();

    for (TemplatePersistenceData data : templateData) {
        for (int i = 0; i < neededContextTypes.length; i++) {
            if (data.getTemplate().getContextTypeId().equals(neededContextTypes[i])) {
                String name = data.getTemplate().getName();
                name2templateData.put(name, data);
                break;
            }
        }
    }

    ArrayList<String> lst = new ArrayList<String>(name2templateData.keySet());
    list.setItems(lst.toArray(new String[lst.size()]));
    list.setSelection(0);
}

From source file:org.jenkinsci.plugins.htpasswd.HtPasswdSecurityRealm.java

private GrantedAuthority[] getUserGroups(final String username) {
    try {/*  w w w. ja  va 2s. c o  m*/
        HtGroupFile htgroups = getHtGroupFile();
        List<String> groups = htgroups.getGroups(username);
        ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(groups.size());
        for (String group : groups) {
            authorities.add(new GrantedAuthorityImpl(group));
        }
        return authorities.toArray(GRANTED_AUTHORITY_TYPE);
    } catch (Exception ex) {
        return GRANTED_AUTHORITY_TYPE;
    }
}

From source file:io.pivotal.spring.cloud.service.eureka.SanitizingEurekaInstanceConfigBeanTest.java

private SanitizingEurekaInstanceConfigBean createBeanWithProps(String... pairs) {
    this.ctx = new AnnotationConfigApplicationContext();

    ArrayList<String> pairs1 = new ArrayList();

    for (String pair : pairs) {
        pairs1.add(pair);/*from   ww  w. j  av  a2s.  c  o  m*/
    }
    pairs1.add("sanitizingEurekaInstanceConfigBean.integration.test:true");
    EnvironmentTestUtils.addEnvironment(ctx, pairs1.toArray(new String[pairs1.size()]));
    this.ctx.register(Context.class);
    this.ctx.refresh();

    return this.ctx.getBean(SanitizingEurekaInstanceConfigBean.class);
}