Example usage for java.util Vector toArray

List of usage examples for java.util Vector toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.

Usage

From source file:id.nci.stm_9.SelectPublicKeyFragment.java

/**
 * Returns all selected user ids/*  ww w .  j a  v  a2  s.  c om*/
 * 
 * @return
 */
public String[] getSelectedUserIds() {
    Vector<String> userIds = new Vector<String>();
    for (int i = 0; i < mListView.getCount(); ++i) {
        if (mListView.isItemChecked(i)) {
            userIds.add((String) mAdapter.getUserId(i));
        }
    }

    // make empty array to not return null
    String userIdArray[] = new String[0];
    return userIds.toArray(userIdArray);
}

From source file:gsn.vsensor.TestStreamExporterVirtualSensor.java

public void testLogStatementIntoMySQLDB() {
    StreamExporterVirtualSensor vs = new StreamExporterVirtualSensor();
    // configure parameters
    ArrayList<KeyValue> params = new ArrayList<KeyValue>();
    params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_URL, url));
    params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_USER, user));
    params.add(new KeyValueImp(StreamExporterVirtualSensor.PARAM_PASSWD, passwd));
    config.setMainClassInitialParams(params);
    vs.setVirtualSensorConfiguration(config);
    vs.initialize();/* ww w.  j  av  a2s  .c  om*/

    // configure datastream
    Vector<DataField> fieldTypes = new Vector<DataField>();
    Object[] data = null;

    for (String type : DataTypes.TYPE_NAMES)
        fieldTypes.add(new DataField(type, type, type));
    int i = 0;
    for (Object value : DataTypes.TYPE_SAMPLE_VALUES)
        data[i++] = value;

    long timeStamp = new Date().getTime();
    StreamElement streamElement = new StreamElement(fieldTypes.toArray(new DataField[] {}),
            (Serializable[]) data, timeStamp);

    // give datastream to vs
    vs.dataAvailable(streamName, streamElement);

    // clean up and control
    boolean result = true;
    try {
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        Connection connection = DriverManager.getConnection(url, user, passwd);
        Statement statement = connection.createStatement();
        statement.execute("SELECT * FROM " + streamName);
        System.out.println("result" + result);
        result = statement.getResultSet().last();
        System.out.println("result" + result);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        result = false;
    }
    assertTrue(result);
}

From source file:org.marketcetera.util.file.SmartLinksDirectoryWalkerTest.java

@Test
public void nonexistentFiles() throws Exception {
    ListWalker walker = new ListWalker(false);
    walker.apply(TEST_NONEXISTENT_FILE);
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertEquals(-1, walker.getMaxDepth());

    Vector<String> results = new Vector<String>();
    walker = new ListWalker(true);
    walker.apply(TEST_NONEXISTENT_FILE, results);
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, results.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
    assertEquals(-1, walker.getMaxDepth());
}

From source file:org.mycore.common.xml.MCREntityResolver.java

private MCREntityResolver() {
    Enumeration<URL> systemResources;
    try {/*  w w w .j  a v a  2  s  . co  m*/
        systemResources = this.getClass().getClassLoader().getResources("catalog.xml");
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }
    Vector<String> catalogURIs = new Vector<>();
    while (systemResources.hasMoreElements()) {
        URL catalogURL = systemResources.nextElement();
        LOGGER.info("Using XML catalog: " + catalogURL);
        catalogURIs.add(catalogURL.toString());
    }
    String[] catalogs = catalogURIs.toArray(new String[catalogURIs.size()]);
    catalogResolver = new XMLCatalogResolver(catalogs);
    int cacheSize = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "StaticFiles.CacheSize", 100);
    bytesCache = new MCRCache<String, InputSourceProvider>(cacheSize, "EntityResolver Resources");
}

From source file:org.marketcetera.util.file.SmartLinksDirectoryWalkerTest.java

@Test
public void singleFile() throws Exception {
    ListWalker walker = new ListWalker(false);
    walker.apply(TEST_ROOT + TEST_FILE);
    assertArrayPermutation(new String[] { TEST_FILE }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertEquals(0, walker.getMaxDepth());

    Vector<String> results = new Vector<String>();
    walker = new ListWalker(false);
    walker.apply(TEST_ROOT + TEST_FILE, results);
    assertArrayPermutation(new String[] { TEST_FILE }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertArrayPermutation(new String[] { TEST_FILE }, results.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
    assertEquals(0, walker.getMaxDepth());

    walker = new ListWalker(true);
    walker.apply(TEST_ROOT + TEST_FILE);
    assertArrayPermutation(new String[] { TEST_FILE }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertEquals(0, walker.getMaxDepth());

    results = new Vector<String>();
    walker = new ListWalker(true);
    walker.apply(TEST_ROOT + TEST_FILE, results);
    assertArrayPermutation(new String[] { TEST_FILE }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertArrayPermutation(new String[] { TEST_FILE }, results.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
    assertEquals(0, walker.getMaxDepth());
}

From source file:org.yawlfoundation.yawl.digitalSignature.DigitalSignature.java

private PrivateKey getPrivateKey() {
    KeyStore keystore = null;/*from  w  w w. j a  va2s. c  om*/

    try {
        char[] password = _Password.toCharArray();
        String _alias = "";
        _Password = null;
        keystore = KeyStore.getInstance("PKCS12");

        keystore.load(new FileInputStream(_Pathway + _P12), password);

        Enumeration enumeration = keystore.aliases();
        Vector vectaliases = new Vector();
        while (enumeration.hasMoreElements())
            vectaliases.add(enumeration.nextElement());

        String[] aliases = (String[]) (vectaliases.toArray(new String[0]));
        for (int i = 0; i < aliases.length; i++)
            if (keystore.isKeyEntry(aliases[i])) {
                _alias = aliases[i];
                break;
            }
        PrivateKey pk = (PrivateKey) keystore.getKey(_alias, password);
        password = null;
        return pk;

    } catch (Exception e) {
        System.out.println("Error: " + "Invalid pkcs#12 Certificate");
        return null;
    }

}

From source file:hudson.plugins.dimensionsscm.ArtifactUploader.java

/**
 * Default constructor./*from w w  w . ja va2  s  .  c  o m*/
 */
@DataBoundConstructor
public ArtifactUploader(String[] patterns, boolean fTip, boolean fMerge, String part) {
    // Check the folders specified have data specified
    if (patterns != null) {
        Logger.Debug("patterns are populated");
        Vector<String> x = new Vector<String>();
        for (int t = 0; t < patterns.length; t++) {
            if (StringUtils.isNotEmpty(patterns[t]))
                x.add(patterns[t]);
        }
        this.patterns = (String[]) x.toArray(new String[1]);
    } else {
        this.patterns[0] = ".*";
    }

    this.forceCheckIn = fTip;
    this.forceTip = fMerge;
    this.owningPart = part;
}

From source file:org.marketcetera.util.file.SmartLinksDirectoryWalkerTest.java

@Test
public void singleLink() throws Exception {
    assumeTrue(OperatingSystem.LOCAL.isUnix());

    ListWalker walker = new ListWalker(false);
    walker.apply(TEST_ROOT_UNIX + TEST_LINK_PATH);
    assertArrayPermutation(new String[] { TEST_LINK_NAME }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertEquals(0, walker.getMaxDepth());

    Vector<String> results = new Vector<String>();
    walker = new ListWalker(false);
    walker.apply(TEST_ROOT_UNIX + TEST_LINK_PATH, results);
    assertArrayPermutation(new String[] { TEST_LINK_NAME }, walker.getFiles());
    assertArrayPermutation(ArrayUtils.EMPTY_STRING_ARRAY, walker.getDirectories());
    assertArrayPermutation(new String[] { TEST_LINK_NAME }, results.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
    assertEquals(0, walker.getMaxDepth());

    walker = new ListWalker(true);
    walker.apply(TEST_ROOT_UNIX + TEST_LINK_PATH);
    assertArrayPermutation(new String[] { TEST_LINK_CONTENTS }, walker.getFiles());
    assertArrayPermutation(new String[] { TEST_LINK_NAME }, walker.getDirectories());
    assertEquals(1, walker.getMaxDepth());

    results = new Vector<String>();
    walker = new ListWalker(true);
    walker.apply(TEST_ROOT_UNIX + TEST_LINK_PATH, results);
    assertArrayPermutation(new String[] { TEST_LINK_CONTENTS }, walker.getFiles());
    assertArrayPermutation(new String[] { TEST_LINK_NAME }, walker.getDirectories());
    assertArrayPermutation(new String[] { TEST_LINK_NAME, TEST_LINK_CONTENTS },
            results.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
    assertEquals(1, walker.getMaxDepth());
}

From source file:com.thinkbiganalytics.nifi.v2.ingest.GetTableData.java

private String[] parseFields(String selectFields) {

    Validate.notEmpty(selectFields);//from  ww  w.  ja va 2 s. com
    Vector<String> fields = new Vector<>();
    String[] values = selectFields.split("\n");
    for (int i = 0; i < values.length; i++) {
        fields.add(values[i].trim());
    }
    return fields.toArray(new String[0]);
}

From source file:nz.net.catalyst.MaharaDroid.upload.http.RestClient.java

public static JSONObject UploadArtifact(String url, String token, String username, String blog, boolean draft,
        boolean allowcomments, String foldername, String tags, String filename, String title,
        String description, Context context) {
    Vector<String> pNames = new Vector<String>();
    Vector<String> pVals = new Vector<String>();

    if (title != null) {
        pNames.add("title");
        pVals.add(title);//from ww w.  j  a v a2s  .  co m
    }
    if (description != null) {
        pNames.add("description");
        pVals.add(description);
    }
    if (token != null) {
        pNames.add("token");
        pVals.add(token);
    }
    if (username != null) {
        pNames.add("username");
        pVals.add(username);
    }
    if (foldername != null) {
        pNames.add("foldername");
        pVals.add(foldername);
    }
    if (tags != null) {
        pNames.add("tags");
        pVals.add(tags);
    }
    if (filename != null) {
        pNames.add("filename");
        pVals.add(filename);
    }
    if (blog != null) {
        pNames.add("blog");
        pVals.add(blog);
    }
    if (draft) {
        pNames.add("draft");
        pVals.add("true");
    }
    if (allowcomments) {
        pNames.add("allowcomments");
        pVals.add("true");
    }

    String[] paramNames, paramVals;
    paramNames = paramVals = new String[] {};
    paramNames = pNames.toArray(paramNames);
    paramVals = pVals.toArray(paramVals);

    return CallFunction(url, paramNames, paramVals, context);
}