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:fr.dyade.aaa.util.MySqlDBRepository.java

/**
 * Gets a list of persistent objects that name corresponds to prefix.
 *
 * @return The list of corresponding names.
 *//*from  w  ww . jav a 2  s  .co  m*/
public String[] list(String prefix) throws IOException {
    try {
        // Creating a statement lets us issue commands against the connection.
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery("SELECT name FROM JoramDB WHERE name LIKE '" + prefix + "%'");

        Vector v = new Vector();
        while (rs.next()) {
            v.add(rs.getString(1));
        }
        rs.close();
        s.close();

        String[] result = new String[v.size()];
        result = (String[]) v.toArray(result);

        return result;
    } catch (SQLException sqle) {
        if (sqle instanceof com.mysql.jdbc.CommunicationsException && !reconnectLoop) {
            logger.log(BasicLevel.WARN, "Database reconnection problem at list, Reconnecting");
            reconnection();
            reconnectLoop = true;
            String[] result = list(prefix);
            reconnectLoop = false;
            return result;
        }

        if (reconnectLoop)
            logger.log(BasicLevel.WARN, "Database reconnection problem at list");

        logger.log(BasicLevel.WARN, "list, problem list " + prefix);
        sqle.printStackTrace();
        throw new IOException(sqle.getMessage());
    } catch (Exception e) {
        logger.log(BasicLevel.WARN, "list, problem list " + prefix + " in e with " + e.getMessage());
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
}

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

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

        File selectedFile = fileChooser.showSaveDialog(getActiveStage());

        if (selectedFile == null)
            return null;

        List<String> extensions = fileChooser.getSelectedExtensionFilter().getExtensions();
        String extension = extensions.get(0).replace("*", "");

        String fileName = selectedFile.getName();
        if (!fileName.toLowerCase().endsWith(extension.toLowerCase())) {
            selectedFile = getFileWithExtension(selectedFile, extension);

            if (!selectedFile.exists())
                return selectedFile;

            if (confirmDlg(getCurrentActiveFrame().getSwingFrame(), "OverWriteExistingFile"))
                return selectedFile;
        } else {/* ww w  . j ava 2 s .  c om*/
            return selectedFile;
        }

        directory = selectedFile.getParentFile();
    }
}

From source file:net.sf.mzmine.project.impl.StorableScan.java

/**
 * @return Returns scan datapoints over certain intensity
 *///from   w w  w  . j a v  a2  s  . c o m
public @Nonnull DataPoint[] getDataPointsOverIntensity(double intensity) {
    int index;
    Vector<DataPoint> points = new Vector<DataPoint>();
    DataPoint dataPoints[] = getDataPoints();

    for (index = 0; index < dataPoints.length; index++) {
        if (dataPoints[index].getIntensity() >= intensity) {
            points.add(dataPoints[index]);
        }
    }

    DataPoint pointsOverIntensity[] = points.toArray(new DataPoint[0]);

    return pointsOverIntensity;
}

From source file:org.viafirma.nucleo.X509.X509Handler.java

/**
 * Retorna la cadena de confianza asociada al certificado indicado
 * utilizando como base el conjunto de certificados de confianza de la
 * plataforma.//from w  w w. ja v a 2s.  c o m
 * 
 * @param certificadosConfianza conjunto de certificados de confianza que se pueden utilizar.
 * @param certificadoInicial Certificado inicio del camino de validacin
 * @return
 * @throws ExcepcionErrorInterno Alguno de los certificados asociados no es de confianza.
 */
public X509Certificate[] obtenerPath(X509Certificate certificadoInicial, Set<TrustAnchor> certificadosConfianza)
        throws ExcepcionErrorInterno {
    Vector<X509Certificate> vector = new Vector<X509Certificate>();
    // el primer elemento es el certificado inicial.
    vector.add(0, certificadoInicial);

    // Recupera el certificado emisor del certificado indicado
    X509Certificate certificadoEmisor = getEmisor(certificadoInicial, certificadosConfianza);
    for (int i = 1; certificadoEmisor != null; i++) {
        vector.add(i, certificadoEmisor);
        certificadoEmisor = getEmisor(certificadoEmisor, certificadosConfianza);
    }
    return vector.toArray(new X509Certificate[0]);
}

From source file:net.aepik.alasca.gui.ldap.SchemaObjectEditorFrame.java

/**
 * Initialize graphical components with values.
 *//*ww  w .  ja  v a2  s .  c  o m*/
private void init() {
    String objectType = this.objetSchema.getType();
    SchemaSyntax syntax = objetSchema.getSyntax();
    String[] params_name = syntax.getParameters(objectType);

    if (params_name == null || params_name.length == 0) {
        return;
    }

    this.labels = new Hashtable<String, JComponent>();
    this.values = new Hashtable<String, JComponent>();
    this.valuesPresent = new Hashtable<String, JCheckBox>();
    Vector<String> parametresEffectues = new Vector<String>();

    for (int i = 0; i < params_name.length; i++) {
        if (parametresEffectues.contains(params_name[i])) {
            continue;
        }

        JComponent label = null;
        JComponent composant = null;
        JCheckBox checkbox = new JCheckBox();
        String[] param_values;
        String[] param_others = syntax.getOthersParametersFor(objectType, params_name[i]);

        // If SUP parameters, add corresponding object names.
        if (params_name[i].compareTo("SUP") == 0) {
            SchemaObject[] objects = this.schema.getObjectsInOrder(objectType);
            param_values = new String[objects.length];
            for (int j = 0; j < objects.length; j++) {
                param_values[j] = objects[j].getNameFirstValue();
            }
        }

        // Else, read the syntax to find needed values.
        else {
            param_values = syntax.getParameterDefaultValues(objectType, params_name[i]);
        }

        // Plusieurs clefs.
        // C'est une liste de clefs possibles.
        if (param_others != null && param_others.length > 1) {
            label = new JComboBox(param_others);
            composant = new JLabel();
            boolean ok = false;

            for (int j = 0; j < param_others.length && !ok; j++) {
                if (objetSchema.isKeyExists(param_others[j])) {
                    ok = true;
                    ((JComboBox) label).setSelectedItem(param_others[j]);
                    checkbox.setSelected(true);
                }
            }
            for (int j = 0; j < param_others.length; j++) {
                parametresEffectues.add(param_others[j]);
            }

        }

        // Aucune valeur possible
        // La prsence du paramtre suffit => JCheckBox.
        else if (param_values.length == 0) {
            label = new JLabel(params_name[i]);
            composant = new JLabel("");
            parametresEffectues.add(params_name[i]);
            checkbox.setSelected(objetSchema.isKeyExists(params_name[i]));

        }

        // Une valeur, on regarde si c'est une valeur prcise.
        // - Si c'est une chane qui peut tre quelconque => JTextField.
        // - Si la valeur est en fait un objet => JTextField + Objet.
        else if (param_values.length == 1 && param_values[0] != null) {
            String tmp = objetSchema.isKeyExists(params_name[i])
                    ? objetSchema.getValue(params_name[i]).toString()
                    : param_values[0];

            label = new JLabel(params_name[i]);
            composant = new JTextField(tmp, 30);
            parametresEffectues.add(params_name[i]);
            checkbox.setSelected(objetSchema.isKeyExists(params_name[i]));

        }

        // Plusieurs valeurs.
        // C'est une liste de choix possibles => JComboBox.
        else if (param_values.length > 1) {
            String tmp = objetSchema.isKeyExists(params_name[i])
                    ? objetSchema.getValue(params_name[i]).toString()
                    : param_values[0];

            if (!ArrayUtils.contains(param_values, tmp)) {
                Vector<String> list = new Vector<String>();
                for (String param_value : param_values) {
                    list.add(param_value);
                }
                list.add(0, tmp);
                param_values = list.toArray(new String[0]);
            }

            label = new JLabel(params_name[i]);
            composant = new JComboBox(param_values);
            ((JComboBox) composant).setEditable(true);
            ((JComboBox) composant).setSelectedItem(tmp);
            parametresEffectues.add(params_name[i]);
            checkbox.setSelected(objetSchema.isKeyExists(params_name[i]));
        }

        // Set elements into the frame.
        if (composant != null && label != null) {
            this.labels.put(params_name[i], label);
            this.values.put(params_name[i], composant);
            this.valuesPresent.put(params_name[i], checkbox);
            SchemaValue v = syntax.createSchemaValue(objectType, params_name[i], null);
            if (v.isValues() && !(composant instanceof JComboBox)) {
                composant.setEnabled(false);
            }
        }
    } // end for
}

From source file:org.eclipse.jubula.autagent.commands.StartRcpAutServerCommand.java

/**
 * {@inheritDoc}//  w w  w. j  a v a 2 s.  c  o  m
 */
protected String[] createEnvArray(Map<String, String> parameters, boolean isAgentSet) {

    String[] envArray = super.createEnvArray(parameters, isAgentSet);
    if (envArray == null) {
        envArray = EnvironmentUtils.propToStrArray(EnvironmentUtils.getProcessEnvironment(),
                IStartAut.PROPERTY_DELIMITER);
    }
    Vector<String> envList = new Vector<String>(Arrays.asList(envArray));
    envList.addAll(getConnectionProperties(parameters, StartSwtAutServerCommand.ENV_VALUE_SEP));

    if (MonitoringUtil.shouldAndCanRunWithMonitoring(parameters)) {
        String monAgent = this.getMonitoringAgent(parameters);
        if (monAgent != null) {
            StringBuffer sb = new StringBuffer();
            sb.append(JAVA_OPTIONS_INTRO);
            sb.append(monAgent);
            envList.add(sb.toString());
            envArray = super.createEnvArray(parameters, true);
        }
    }
    envArray = envList.toArray(new String[envList.size()]);

    return envArray;
}

From source file:net.aepik.alasca.gui.util.LoadFileFrame.java

/**
 * Load a file.//from www . j  a v  a 2 s  . c  om
 */
public boolean loadFile(String filename, String syntaxe) {
    if (!(new File(filename)).exists()) {
        this.errorMessage = "Le fichier n'existe pas.";
        return false;
    }
    try {
        SchemaSyntax syntax = Schema.getSyntax(syntaxe);
        SchemaFile schemaFile = Schema.createAndLoad(syntax, filename, true);
        Schema schema = schemaFile.getSchema();
        if (schema == null) {
            String message = "";
            if (schemaFile.isError()) {
                message += "\n\n" + "Line " + schemaFile.getErrorLine() + ":\n" + schemaFile.getErrorMessage();
            }
            this.errorMessage = "Le format du fichier est incorrect." + message;
            return false;
        }
        if (manager.isSchemaIdExists((new File(filename)).getName())) {
            this.errorMessage = "Le fichier est dj ouvert.";
            return false;
        }
        Vector<String> files = Pref.getVector(Pref.PREF_LASTOPENFILES);
        Vector<String> syntaxes = Pref.getVector(Pref.PREF_LASTOPENSYNTAXES);
        int index = files.indexOf(filename);
        if (index >= 0) {
            files.removeElementAt(index);
            syntaxes.removeElementAt(index);
        }
        files.add(filename);
        syntaxes.add(syntaxe);
        if (files.size() > 10) {
            files.removeElementAt(0);
            syntaxes.removeElementAt(0);
        }
        Pref.set(Pref.PREF_LASTOPENFILES, files.toArray(new String[0]));
        Pref.set(Pref.PREF_LASTOPENSYNTAXES, syntaxes.toArray(new String[0]));
        manager.addSchema((new File(filename)).getName(), schema);
    } catch (Exception e) {
        e.printStackTrace();
        this.errorMessage = "Une erreur inattendue est survenue.";
        return false;
    }
    return true;
}

From source file:kenh.expl.impl.ExpLParser.java

/**
 * Get the parameters for function, use ',' to split each parameter.
 * @param parameter//from   w w w. j  a v a 2  s .  com
 * @return
 */
private static String[] splitParameter(String parameter) throws UnsupportedExpressionException {
    Vector<String> params = new Vector();

    StringBuffer param = new StringBuffer();
    int count = 0;
    for (int scan = 0; scan < parameter.length(); scan++) {
        char c = parameter.charAt(scan);

        if (c == ',') {
            if (count > 0) {
                param.append(c);
            } else {
                params.add(param.toString());
                param = new StringBuffer();
            }
        } else if (c == '{') {
            count++;
            param.append(c);
        } else if (c == '}') {
            count--;
            param.append(c);
            if (count < 0) {
                UnsupportedExpressionException e = new UnsupportedExpressionException("Missing '{'.");
                e.push(parameter);
                throw e;
            }
        } else {
            param.append(c);
        }
    }

    if (count > 0) {
        UnsupportedExpressionException e = new UnsupportedExpressionException("Missing '}'.");
        e.push(parameter);
        throw e;
    }

    String lastParam = param.toString();

    if (params.size() == 0 && lastParam.equals("")) {
        // '()' only, mean no parameter
    } else {
        params.add(lastParam);
    }

    return params.toArray(new String[] {});
}

From source file:org.apache.cactus.WebResponse.java

/**
 * @return the text of the response (excluding headers) as an array of
 *         strings (each string is a separate line from the output stream).
 *//*from w  w w . j  av a 2s . c o  m*/
public String[] getTextAsArray() {
    Vector lines = new Vector();

    try {
        // Read content first
        if (this.content == null) {
            getText();
        }

        BufferedReader input = new BufferedReader(new StringReader(this.content));
        String str;

        while (null != (str = input.readLine())) {
            lines.addElement(str);
        }

        input.close();
    } catch (IOException e) {
        throw new ChainedRuntimeException(e);
    }

    // Dummy variable to explicitely tell the object type to copy.
    String[] dummy = new String[lines.size()];

    return (String[]) (lines.toArray(dummy));
}

From source file:com.w20e.socrates.model.ExpressionCompiler.java

/**
 * Enable multiple arguments to our two-operand summation.
 * /*from  ww  w .  j  a  v a 2s.c  o m*/
 * @param i
 *            pointer in argument array
 * @param arg0
 *            operands
 * @return Sum expression
 */
private Expression sum(final int i, final Object[] arg0) {

    Sum op = new Sum();

    Vector<Expression> args = new Vector<Expression>();

    for (Object arg : arg0) {

        args.add((Expression) arg);
    }

    op.setOperands(args.toArray(new Expression[args.size()]));

    return op;
}