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:de.juwimm.cms.components.remote.ComponentsServiceSpringImpl.java

/**
 * @see de.juwimm.cms.components.remote.ComponentsServiceSpring#getPerson4Name(java.lang.String,
 *      java.lang.String)/*from   www .jav a2 s .c  o  m*/
 */
@Override
protected PersonValue[] handleGetPerson4Name(String firstName, String lastName) throws Exception {
    PersonValue[] personValues = new PersonValue[0];
    try {
        UserHbm user = getUserHbmDao().load(AuthenticationHelper.getUserName());
        Collection<PersonHbm> temp = getPersonHbmDao().findByName(user.getActiveSite().getSiteId(), firstName,
                lastName);
        Iterator<PersonHbm> it = temp.iterator();
        Vector<PersonValue> vec = new Vector<PersonValue>();
        while (it.hasNext()) {
            vec.add(it.next().getDao(0));
        }
        personValues = vec.toArray(new PersonValue[0]);
    } catch (Exception e) {
        log.error("Could not get persons by name (" + firstName + " " + lastName + "): " + e.getMessage(), e);
    }
    return personValues;
}

From source file:com.sonaive.v2ex.ui.debug.RSSPullService.java

/**
 * In an IntentService, onHandleIntent is run on a background thread.  As it
 * runs, it broadcasts its current status using the LocalBroadcastManager.
 * @param workIntent The Intent that starts the IntentService. This Intent contains the
 * URL of the web site from which the RSS parser gets data.
 *//*from   w  w w.j  a  v a2s.  c o  m*/
@Override
protected void onHandleIntent(Intent workIntent) {

    BroadcastNotifier mBroadcaster = new BroadcastNotifier(this);
    // Gets a URL to read from the incoming Intent's "data" value
    String localUrlString = workIntent.getDataString();

    // Creates a projection to use in querying the modification date table in the provider.
    final String[] dateProjection = new String[] { ModiDates._ID, ModiDates.MODI_DATE };

    // A URL that's local to this method
    URL localURL;

    // A cursor that's local to this method.
    Cursor cursor = null;

    /*
     * A block that tries to connect to the Picasa featured picture URL passed as the "data"
     * value in the incoming Intent. The block throws exceptions (see the end of the block).
     */
    try {

        // Convert the incoming data string to a URL.
        localURL = new URL(localUrlString);

        /*
         * Tries to open a connection to the URL. If an IO error occurs, this throws an
         * IOException
         */
        URLConnection localURLConnection = localURL.openConnection();

        // If the connection is an HTTP connection, continue
        if ((localURLConnection instanceof HttpURLConnection)) {

            // Broadcasts an Intent indicating that processing has started.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_STARTED);

            // Casts the connection to a HTTP connection
            HttpURLConnection localHttpURLConnection = (HttpURLConnection) localURLConnection;

            // Sets the user agent for this request.
            localHttpURLConnection.setRequestProperty("User-Agent", Constants.USER_AGENT);

            /*
             * Queries the content provider to see if this URL was read previously, and when.
             * The content provider throws an exception if the URI is invalid.
             */
            cursor = getContentResolver().query(ModiDates.CONTENT_URI, dateProjection, null, null, null);

            // Flag to indicate that new metadata was retrieved
            boolean newMetadataRetrieved;

            /*
             * Tests to see if the table contains a modification date for the URL
             */
            if (null != cursor && cursor.moveToFirst()) {

                long storedModifiedDate = cursor.getLong(cursor.getColumnIndex(ModiDates.MODI_DATE));

                /*
                 * If the modified date isn't 0, sets another request property to ensure that
                 * data is only downloaded if it has changed since the last recorded
                 * modification date. Formats the date according to the RFC1123 format.
                 */
                if (0 != storedModifiedDate) {
                    localHttpURLConnection.setRequestProperty("If-Modified-Since",
                            org.apache.http.impl.cookie.DateUtils.formatDate(new Date(storedModifiedDate),
                                    org.apache.http.impl.cookie.DateUtils.PATTERN_RFC1123));
                }

                // Marks that new metadata does not need to be retrieved
                newMetadataRetrieved = false;

            } else {

                /*
                 * No modification date was found for the URL, so newmetadata has to be
                 * retrieved.
                 */
                newMetadataRetrieved = true;

            }

            // Reports that the service is about to connect to the RSS feed
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_CONNECTING);

            // Gets a response code from the RSS server
            int responseCode = localHttpURLConnection.getResponseCode();

            switch (responseCode) {

            // If the response is OK
            case HttpStatus.SC_OK:

                // Gets the last modified data for the URL
                long lastModifiedDate = localHttpURLConnection.getLastModified();

                // Reports that the service is parsing
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_PARSING);

                /*
                 * Instantiates a pull parser and uses it to parse XML from the RSS feed.
                 * The mBroadcaster argument send a broadcaster utility object to the
                 * parser.
                 */
                RSSPullParser localPicasaPullParser = new RSSPullParser();

                localPicasaPullParser.parseXml(localURLConnection.getInputStream(), mBroadcaster);

                // Reports that the service is now writing data to the content provider.
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_WRITING);

                // Gets image data from the parser
                Vector<ContentValues> imageValues = localPicasaPullParser.getImages();

                // Stores the number of images
                int imageVectorSize = imageValues.size();

                // Creates one ContentValues for each image
                ContentValues[] imageValuesArray = new ContentValues[imageVectorSize];

                imageValuesArray = imageValues.toArray(imageValuesArray);

                /*
                 * Stores the image data in the content provider. The content provider
                 * throws an exception if the URI is invalid.
                 */
                getContentResolver().bulkInsert(PicasaImages.CONTENT_URI, imageValuesArray);

                // Creates another ContentValues for storing date information
                ContentValues dateValues = new ContentValues();

                // Adds the URL's last modified date to the ContentValues
                dateValues.put(ModiDates.MODI_DATE, lastModifiedDate);

                if (newMetadataRetrieved) {

                    // No previous metadata existed, so insert the data
                    getContentResolver().insert(ModiDates.CONTENT_URI, dateValues);
                } else {

                    // Previous metadata existed, so update it.
                    getContentResolver().update(ModiDates.CONTENT_URI, dateValues,
                            ModiDates._ID + "=" + cursor.getString(cursor.getColumnIndex(ModiDates._ID)), null);
                }
                break;

            }

            // Reports that the feed retrieval is complete.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_COMPLETE);
        }

        // Handles possible exceptions
    } catch (MalformedURLException localMalformedURLException) {

        localMalformedURLException.printStackTrace();

    } catch (IOException localIOException) {

        localIOException.printStackTrace();

    } catch (XmlPullParserException localXmlPullParserException) {

        localXmlPullParserException.printStackTrace();

    } finally {

        // If an exception occurred, close the cursor to prevent memory leaks.
        if (null != cursor) {
            cursor.close();
        }
    }
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public File showFileOpenDialog(String title, File directory, Vector<FormatFilter> filters) {
    FileChooser fileChooser = createFileChooser(title, directory,
            filters.toArray(new FormatFilter[filters.size()]));

    return fileChooser.showOpenDialog(getActiveStage());
}

From source file:xiaofans.threadsample.RSSPullService.java

/**
 * In an IntentService, onHandleIntent is run on a background thread.  As it
 * runs, it broadcasts its current status using the LocalBroadcastManager.
 * @param workIntent The Intent that starts the IntentService. This Intent contains the
 * URL of the web site from which the RSS parser gets data.
 *///  w w w  . jav a  2 s .com
@Override
protected void onHandleIntent(Intent workIntent) {
    // Gets a URL to read from the incoming Intent's "data" value
    String localUrlString = workIntent.getDataString();

    // Creates a projection to use in querying the modification date table in the provider.
    final String[] dateProjection = new String[] { DataProviderContract.ROW_ID,
            DataProviderContract.DATA_DATE_COLUMN };

    // A URL that's local to this method
    URL localURL;

    // A cursor that's local to this method.
    Cursor cursor = null;

    /*
     * A block that tries to connect to the Picasa featured picture URL passed as the "data"
     * value in the incoming Intent. The block throws exceptions (see the end of the block).
     */
    try {

        // Convert the incoming data string to a URL.
        localURL = new URL(localUrlString);

        /*
         * Tries to open a connection to the URL. If an IO error occurs, this throws an
         * IOException
         */
        URLConnection localURLConnection = localURL.openConnection();

        // If the connection is an HTTP connection, continue
        if ((localURLConnection instanceof HttpURLConnection)) {

            // Broadcasts an Intent indicating that processing has started.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_STARTED);

            // Casts the connection to a HTTP connection
            HttpURLConnection localHttpURLConnection = (HttpURLConnection) localURLConnection;

            // Sets the user agent for this request.
            localHttpURLConnection.setRequestProperty("User-Agent", Constants.USER_AGENT);

            /*
             * Queries the content provider to see if this URL was read previously, and when.
             * The content provider throws an exception if the URI is invalid.
             */
            cursor = getContentResolver().query(DataProviderContract.DATE_TABLE_CONTENTURI, dateProjection,
                    null, null, null);

            // Flag to indicate that new metadata was retrieved
            boolean newMetadataRetrieved;

            /*
             * Tests to see if the table contains a modification date for the URL
             */
            if (null != cursor && cursor.moveToFirst()) {

                // Find the URL's last modified date in the content provider
                long storedModifiedDate = cursor
                        .getLong(cursor.getColumnIndex(DataProviderContract.DATA_DATE_COLUMN));

                /*
                 * If the modified date isn't 0, sets another request property to ensure that
                 * data is only downloaded if it has changed since the last recorded
                 * modification date. Formats the date according to the RFC1123 format.
                 */
                if (0 != storedModifiedDate) {
                    localHttpURLConnection.setRequestProperty("If-Modified-Since",
                            org.apache.http.impl.cookie.DateUtils.formatDate(new Date(storedModifiedDate),
                                    org.apache.http.impl.cookie.DateUtils.PATTERN_RFC1123));
                }

                // Marks that new metadata does not need to be retrieved
                newMetadataRetrieved = false;

            } else {

                /*
                 * No modification date was found for the URL, so newmetadata has to be
                 * retrieved.
                 */
                newMetadataRetrieved = true;

            }

            // Reports that the service is about to connect to the RSS feed
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_CONNECTING);

            // Gets a response code from the RSS server
            int responseCode = localHttpURLConnection.getResponseCode();

            switch (responseCode) {

            // If the response is OK
            case HttpStatus.SC_OK:

                // Gets the last modified data for the URL
                long lastModifiedDate = localHttpURLConnection.getLastModified();

                // Reports that the service is parsing
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_PARSING);

                /*
                 * Instantiates a pull parser and uses it to parse XML from the RSS feed.
                 * The mBroadcaster argument send a broadcaster utility object to the
                 * parser.
                 */
                RSSPullParser localPicasaPullParser = new RSSPullParser();

                localPicasaPullParser.parseXml(localURLConnection.getInputStream(), mBroadcaster);

                // Reports that the service is now writing data to the content provider.
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_WRITING);

                // Gets image data from the parser
                Vector<ContentValues> imageValues = localPicasaPullParser.getImages();

                // Stores the number of images
                int imageVectorSize = imageValues.size();

                // Creates one ContentValues for each image
                ContentValues[] imageValuesArray = new ContentValues[imageVectorSize];

                imageValuesArray = imageValues.toArray(imageValuesArray);

                /*
                 * Stores the image data in the content provider. The content provider
                 * throws an exception if the URI is invalid.
                 */
                getContentResolver().bulkInsert(DataProviderContract.PICTUREURL_TABLE_CONTENTURI,
                        imageValuesArray);

                // Creates another ContentValues for storing date information
                ContentValues dateValues = new ContentValues();

                // Adds the URL's last modified date to the ContentValues
                dateValues.put(DataProviderContract.DATA_DATE_COLUMN, lastModifiedDate);

                if (newMetadataRetrieved) {

                    // No previous metadata existed, so insert the data
                    getContentResolver().insert(DataProviderContract.DATE_TABLE_CONTENTURI, dateValues);

                } else {

                    // Previous metadata existed, so update it.
                    getContentResolver().update(DataProviderContract.DATE_TABLE_CONTENTURI, dateValues,
                            DataProviderContract.ROW_ID + "="
                                    + cursor.getString(cursor.getColumnIndex(DataProviderContract.ROW_ID)),
                            null);
                }
                break;

            }

            // Reports that the feed retrieval is complete.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_COMPLETE);
        }

        // Handles possible exceptions
    } catch (MalformedURLException localMalformedURLException) {

        localMalformedURLException.printStackTrace();

    } catch (IOException localIOException) {

        localIOException.printStackTrace();

    } catch (XmlPullParserException localXmlPullParserException) {

        localXmlPullParserException.printStackTrace();

    } finally {

        // If an exception occurred, close the cursor to prevent memory leaks.
        if (null != cursor) {
            cursor.close();
        }
    }
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

protected File[] showMultiFileOpenDialog(String title, File directory, Vector<FormatFilter> filters) {
    FileChooser fileChooser = createFileChooser(title, directory,
            filters.toArray(new FormatFilter[filters.size()]));
    List<File> files = fileChooser.showOpenMultipleDialog(getActiveStage());

    if (files == null)
        return new File[0];

    return files.toArray(new File[files.size()]);
}

From source file:com.ricemap.spateDB.util.CommandLineArguments.java

public Prism[] getPrisms() {
    Vector<Prism> Prisms = new Vector<Prism>();
    for (String arg : args) {
        if (arg.startsWith("rect:") || arg.startsWith("prism:") || arg.startsWith("mbr:")) {
            Prism rect = new Prism();
            rect.fromText(new Text(arg.substring(arg.indexOf(':') + 1)));
            Prisms.add(rect);//from   ww w.j ava  2 s .com
        }
    }
    return Prisms.toArray(new Prism[Prisms.size()]);
}

From source file:com.example.android.threadsample.RSSPullService.java

/**
 * In an IntentService, onHandleIntent is run on a background thread.  As it
 * runs, it broadcasts its current status using the LocalBroadcastManager.
 * @param workIntent The Intent that starts the IntentService. This Intent contains the
 * URL of the web site from which the RSS parser gets data.
 *///from  w  w w .  j a v a  2s  .  co m
@Override
protected void onHandleIntent(Intent workIntent) {
    // Gets a URL to read from the incoming Intent's "data" value
    String localUrlString = workIntent.getDataString();

    // Creates a projection to use in querying the modification date table in the provider.
    final String[] dateProjection = new String[] { DataProviderContract.ROW_ID,
            DataProviderContract.DATA_DATE_COLUMN };

    // A URL that's local to this method
    URL localURL;

    // A cursor that's local to this method.
    Cursor cursor = null;

    /*
     * A block that tries to connect to the Picasa featured picture URL passed as the "data"
     * value in the incoming Intent. The block throws exceptions (see the end of the block).
     */
    try {

        // Convert the incoming data string to a URL.
        localURL = new URL(localUrlString);

        /*
         * Tries to open a connection to the URL. If an IO error occurs, this throws an
         * IOException
         */
        URLConnection localURLConnection = localURL.openConnection();

        // If the connection is an HTTP connection, continue
        if ((localURLConnection instanceof HttpURLConnection)) {

            // Broadcasts an Intent indicating that processing has started.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_STARTED);

            // Casts the connection to a HTTP connection
            HttpURLConnection localHttpURLConnection = (HttpURLConnection) localURLConnection;

            // Sets the user agent for this request.
            localHttpURLConnection.setRequestProperty("User-Agent", Constants.USER_AGENT);

            /*
             * Queries the content provider to see if this URL was read previously, and when.
             * The content provider throws an exception if the URI is invalid.
             */
            cursor = getContentResolver().query(DataProviderContract.DATE_TABLE_CONTENTURI, dateProjection,
                    null, null, null);

            // Flag to indicate that new metadata was retrieved
            boolean newMetadataRetrieved;

            /*
             * Tests to see if the table contains a modification date for the URL
             */
            if (null != cursor && cursor.moveToFirst()) {

                // Find the URL's last modified date in the content provider
                long storedModifiedDate = cursor
                        .getLong(cursor.getColumnIndex(DataProviderContract.DATA_DATE_COLUMN));

                /*
                 * If the modified date isn't 0, sets another request property to ensure that
                 * data is only downloaded if it has changed since the last recorded
                 * modification date. Formats the date according to the RFC1123 format.
                 */
                if (0 != storedModifiedDate) {
                    localHttpURLConnection.setRequestProperty("If-Modified-Since",
                            org.apache.http.impl.cookie.DateUtils.formatDate(new Date(storedModifiedDate),
                                    org.apache.http.impl.cookie.DateUtils.PATTERN_RFC1123));
                }

                // Marks that new metadata does not need to be retrieved
                newMetadataRetrieved = false;

            } else {

                /*
                 * No modification date was found for the URL, so newmetadata has to be
                 * retrieved.
                 */
                newMetadataRetrieved = true;

            }

            // Reports that the service is about to connect to the RSS feed
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_CONNECTING);

            // Gets a response code from the RSS server
            int responseCode = localHttpURLConnection.getResponseCode();

            switch (responseCode) {

            // If the response is OK
            case HttpStatus.SC_OK:

                // Gets the last modified data for the URL
                long lastModifiedDate = localHttpURLConnection.getLastModified();

                // Reports that the service is parsing
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_PARSING);

                /*
                 * Instantiates a pull parser and uses it to parse XML from the RSS feed.
                 * The mBroadcaster argument send a broadcaster utility object to the
                 * parser.
                 */
                RSSPullParser localPicasaPullParser = new RSSPullParser();

                try {
                    localPicasaPullParser.parseXml(localURLConnection.getInputStream(), mBroadcaster);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                // Reports that the service is now writing data to the content provider.
                mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_WRITING);

                // Gets image data from the parser
                Vector<ContentValues> imageValues = localPicasaPullParser.getImages();

                // Stores the number of images
                int imageVectorSize = imageValues.size();

                // Creates one ContentValues for each image
                ContentValues[] imageValuesArray = new ContentValues[imageVectorSize];

                imageValuesArray = imageValues.toArray(imageValuesArray);

                /*
                 * Stores the image data in the content provider. The content provider
                 * throws an exception if the URI is invalid.
                 */
                getContentResolver().bulkInsert(DataProviderContract.PICTUREURL_TABLE_CONTENTURI,
                        imageValuesArray);

                // Creates another ContentValues for storing date information
                ContentValues dateValues = new ContentValues();

                // Adds the URL's last modified date to the ContentValues
                dateValues.put(DataProviderContract.DATA_DATE_COLUMN, lastModifiedDate);

                if (newMetadataRetrieved) {

                    // No previous metadata existed, so insert the data
                    getContentResolver().insert(DataProviderContract.DATE_TABLE_CONTENTURI, dateValues);

                } else {

                    // Previous metadata existed, so update it.
                    getContentResolver().update(DataProviderContract.DATE_TABLE_CONTENTURI, dateValues,
                            DataProviderContract.ROW_ID + "="
                                    + cursor.getString(cursor.getColumnIndex(DataProviderContract.ROW_ID)),
                            null);
                }
                break;

            }

            // Reports that the feed retrieval is complete.
            mBroadcaster.broadcastIntentWithState(Constants.STATE_ACTION_COMPLETE);
        }

        // Handles possible exceptions
    } catch (MalformedURLException localMalformedURLException) {

        localMalformedURLException.printStackTrace();

    } catch (IOException localIOException) {

        localIOException.printStackTrace();

    } catch (XmlPullParserException localXmlPullParserException) {

        localXmlPullParserException.printStackTrace();

    } finally {

        // If an exception occurred, close the cursor to prevent memory leaks.
        if (null != cursor) {
            cursor.close();
        }
    }
}

From source file:com.ricemap.spateDB.util.CommandLineArguments.java

public Path[] getPaths() {
    Vector<Path> inputPaths = new Vector<Path>();
    for (String arg : args) {
        if (arg.startsWith("-") && arg.length() > 1) {
            // Skip
        } else if (arg.indexOf(':') != -1 && arg.indexOf(":/") == -1) {
            // Skip
        } else {//from   www  .j  a v  a2 s . c  o  m
            inputPaths.add(new Path(arg));
        }
    }
    return inputPaths.toArray(new Path[inputPaths.size()]);
}

From source file:tools.httpserver.custom.ScriptList.java

/**
 * Update GreasySpoon service scripts based on provided parameters
 * @param params_values   String table with each line composed of "param=value"
 * @param requestmode Set if information concerns REQMOD scripts or not (if not, means RESPMOD scripts)
 *//*from  w  w w  .j a  va  2  s.  c o m*/
public static void update(String[] params_values, boolean requestmode) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    for (String s : params_values) {
        String[] values = s.split("=");
        if (values.length == 1) {
            table.put(values[0], "");
        } else if (values.length == 2) {
            values[0] = values[0].replace("+", " ");
            table.put(values[0], values[1]);
        }
    }
    Vector<SpoonScript> todelete = new Vector<SpoonScript>();
    Vector<SpoonScript> scripts = new Vector<SpoonScript>(
            Arrays.asList(requestmode ? icap.services.GreasySpoon.reqSpoonScripts
                    : icap.services.GreasySpoon.respSpoonScripts));

    boolean deleted = false;
    for (SpoonScript script : scripts) {

        String name = script.getFile().getName().toLowerCase();
        if (table.get("delete_" + name) != null) {
            todelete.add(script);
            deleted = true;
            continue;
        }
        boolean newstatus = false;
        if (table.get("enable_" + name) != null) {
            newstatus = true;
        }
        if (script.getStatus() != newstatus) {
            script.setStatus(newstatus);
            script.saveWithNewStatus();
        }
    }
    for (SpoonScript script : todelete) {
        scripts.remove(script);
        script.getFile().delete();
        if (script.getFile().getName().endsWith(".java")) {
            String classname = script.getFile().getParent() + "/nativejava/"
                    + ((JavaSpoonScript) script).getInternalName() + ".class";
            new File(classname).delete();
        }
    }
    if (deleted) {
        if (requestmode) {
            icap.services.GreasySpoon.reqSpoonScripts = scripts.toArray(new SpoonScript[0]);
        } else {
            icap.services.GreasySpoon.respSpoonScripts = scripts.toArray(new SpoonScript[0]);
        }
    }

}

From source file:edu.umn.cs.spatialHadoop.CommandLineArguments.java

public Rectangle[] getRectangles() {
    Vector<Rectangle> rectangles = new Vector<Rectangle>();
    for (String arg : args) {
        if (arg.startsWith("rect:") || arg.startsWith("rectangle:") || arg.startsWith("mbr:")) {
            Rectangle rect = new Rectangle();
            rect.fromText(new Text(arg.substring(arg.indexOf(':') + 1)));
            rectangles.add(rect);//from w  w w. j  av  a 2  s  . c  o  m
        }
    }
    return rectangles.toArray(new Rectangle[rectangles.size()]);
}