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:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport_UK1.java

/**
 *
 * @param a_SAR_File//from w w w  . j a  va2s.c o m
 * @param a_CAS_File
 * @return Object[] result where;
 * result[0] is a String[] of variable names
 * result[1] is a double[number of variables][no of data items]
 * of a_SAR_data
 * result[2] is a double[number of variables][no of data items]
 * of a_CAS_data
 * @throws IOException
 */
protected static Object[] loadDataISARHP_ISARCEP(File a_SAR_File, File a_CAS_File) throws IOException {
    Object[] result = new Object[3];

    TreeMap<String, double[]> a_SAROptimistaionConstraints_TreeMap = loadCASOptimistaionConstraints(a_SAR_File);
    TreeMap<String, double[]> a_CASOptimistaionConstraints_TreeMap = loadCASOptimistaionConstraints(a_CAS_File);

    Vector<String> variables = GeneticAlgorithm_ISARHP_ISARCEP.getVariableList();
    variables.add(0, "Zone_Code");
    String[] variableNames = new String[0];
    variableNames = variables.toArray(variableNames);
    result[0] = variableNames;

    // Format (Flip) data
    double[][] a_SAR_Data = new double[variables.size() - 1][a_SAROptimistaionConstraints_TreeMap.size()];
    double[][] a_CAS_Data = new double[variables.size() - 1][a_SAROptimistaionConstraints_TreeMap.size()];
    String oa;
    double[] a_SARExpectedRow;
    double[] a_CASObservedRow;
    int j = 0;
    Iterator<String> iterator_String = a_SAROptimistaionConstraints_TreeMap.keySet().iterator();
    while (iterator_String.hasNext()) {
        oa = iterator_String.next();
        a_SARExpectedRow = a_SAROptimistaionConstraints_TreeMap.get(oa);
        a_CASObservedRow = a_CASOptimistaionConstraints_TreeMap.get(oa);
        if (a_SARExpectedRow == null) {
            System.out.println(
                    "Warning a_SARExpectedRow == null in loadDataISARHP_ISARCEP(File,File) for OA " + oa);
        } else {
            if (a_CASObservedRow == null) {
                System.out.println(
                        "Warning a_CASObservedRow == null in loadDataISARHP_ISARCEP(File,File) for OA " + oa);
            } else {
                for (int i = 0; i < variables.size() - 1; i++) {
                    a_SAR_Data[i][j] = a_SARExpectedRow[i];
                    a_CAS_Data[i][j] = a_CASObservedRow[i];
                }
            }
        }
        j++;
    }
    result[1] = a_SAR_Data;
    result[2] = a_CAS_Data;
    return result;
}

From source file:org.sakaiproject.util.StringUtil.java

/**
 * @param source//from   ww w .j av a2  s .  co  m
 * @param splitter
 * @return
 * @deprecated use {@link org.apache.commons.lang3.StringUtils#split(String, String)}
 */
public static String[] split(String source, String splitter) {
    // hold the results as we find them
    Vector rv = new Vector();
    int last = 0;
    int next = 0;
    do {
        // find next splitter in source
        next = source.indexOf(splitter, last);
        if (next != -1) {
            // isolate from last thru before next
            rv.add(source.substring(last, next));
            last = next + splitter.length();
        }
    } while (next != -1);
    if (last < source.length()) {
        rv.add(source.substring(last, source.length()));
    }

    // convert to array
    return (String[]) rv.toArray(new String[rv.size()]);
}

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

public static JSONObject AuthSync(String url, String token, String username, Long lastsync,
        String notifications, Context context) {
    Vector<String> pNames = new Vector<String>();
    Vector<String> pVals = new Vector<String>();

    if (token != null) {
        pNames.add("token");
        pVals.add(token);/*from   w w  w.j a va  2s .c o m*/
    }
    if (username != null) {
        pNames.add("username");
        pVals.add(username);
    }
    if (lastsync != null) {
        pNames.add("lastsync");
        pVals.add(lastsync.toString());
    }
    if (lastsync != null) {
        pNames.add("lastsync");
        pVals.add(lastsync.toString());
    }
    if (notifications != null) {
        pNames.add("notifications");
        pVals.add(notifications);
    }

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

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

From source file:org.piraso.api.sql.SQLDataViewEntry.java

@JsonIgnore
public String getCSVString() throws IOException {
    if (CollectionUtils.isEmpty(records)) {
        return "";
    }/*from  www.ja  v  a  2s.  com*/

    StringWriter writer = new StringWriter();
    CSVWriter csv = new CSVWriter(writer);

    Vector<String> header = SQLParameterUtils.createHeaders(this, Integer.MAX_VALUE);
    csv.writeNext(header.toArray(new String[header.size()]));

    for (List<SQLParameterEntry> list : records) {
        List<String> row = new ArrayList<String>(list.size());
        for (SQLParameterEntry parameter : list) {
            row.add(SQLParameterUtils.toRSString(parameter));
        }

        csv.writeNext(row.toArray(new String[list.size()]));
    }

    csv.flush();
    return writer.toString();
}

From source file:org.apache.axis2.xmlbeans.CodeGenerationUtility.java

/**
 * Converts a given vector of schemaDocuments to XmlBeans processable schema objects. One
 * drawback we have here is the non-inclusion of untargeted namespaces
 *
 * @param vec//  w  w  w.  java2 s. c o m
 * @return schema array
 */
private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
    SchemaDocument[] schemaDocuments = (SchemaDocument[]) vec.toArray(new SchemaDocument[vec.size()]);
    //remove duplicates
    Vector uniqueSchemas = new Vector(schemaDocuments.length);
    Vector uniqueSchemaTns = new Vector(schemaDocuments.length);
    SchemaDocument.Schema s;
    for (int i = 0; i < schemaDocuments.length; i++) {
        s = schemaDocuments[i].getSchema();
        if (!uniqueSchemaTns.contains(s.getTargetNamespace())) {
            uniqueSchemas.add(s);
            uniqueSchemaTns.add(s.getTargetNamespace());
        } else if (s.getTargetNamespace() == null) {
            uniqueSchemas.add(s);
        }
    }
    return (SchemaDocument.Schema[]) uniqueSchemas.toArray(new SchemaDocument.Schema[uniqueSchemas.size()]);
}

From source file:com.headstrong.npi.raas.Utils.java

public static String[] vectorToStringArray(Vector<String> vec) {
    String[] returnStr = vec != null ? vec.toArray(new String[0]) : new String[0];
    return returnStr;
}

From source file:marytts.util.string.StringUtils.java

/**
 * @deprecated Unstable due to platform-specific behavior. Use {@link org.apache.commons.lang.StringUtils#split}
 *             or similar instead.//from   ww  w .  j  ava2  s .  c  om
 */
@Deprecated
public static String[] toStringArray(String allInOneLine) {
    if (allInOneLine != "") {
        Vector<String> result = new Vector<String>();

        StringTokenizer s = new StringTokenizer(allInOneLine, System.getProperty("line.separator"));
        String line = null;
        // Read until either end of file or an empty line
        while (s.hasMoreTokens() && ((line = s.nextToken()) != null) && (!line.equals("")))
            result.add(line);

        return result.toArray(new String[0]);
    } else
        return null;
}

From source file:sample.multithreading.NetworkDownloadService.java

@Override
protected void onHandleIntent(Intent paramIntent) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    String str = paramIntent.getDataString();
    URL localURL;/*from  www .j a  v  a  2  s . c o m*/
    try {
        localURL = new URL(str);
        URLConnection localURLConnection = localURL.openConnection();
        if ((localURLConnection instanceof HttpURLConnection)) {
            broadcastIntentWithState(STATE_ACTION_STARTED);
            HttpURLConnection localHttpURLConnection = (HttpURLConnection) localURLConnection;
            localHttpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
            broadcastIntentWithState(STATE_ACTION_CONNECTING);
            localHttpURLConnection.getResponseCode();
            broadcastIntentWithState(STATE_ACTION_PARSING);
            PicasaPullParser localPicasaPullParser = new PicasaPullParser();
            localPicasaPullParser.parseXml(localURLConnection.getInputStream(), this);
            broadcastIntentWithState(STATE_ACTION_WRITING);
            Vector<ContentValues> cvv = localPicasaPullParser.getImages();
            int size = cvv.size();
            ContentValues[] cvArray = new ContentValues[size];
            cvArray = cvv.toArray(cvArray);
            getContentResolver().bulkInsert(PicasaContentDB.getUriByType(this, PicasaContentDB.METADATA_QUERY),
                    cvArray);
            broadcastIntentWithState(STATE_ACTION_COMPLETE);
        }
    } catch (MalformedURLException localMalformedURLException) {
        localMalformedURLException.printStackTrace();
    } catch (IOException localIOException) {
        localIOException.printStackTrace();
    } catch (XmlPullParserException localXmlPullParserException) {
        localXmlPullParserException.printStackTrace();
    }
    Log.d(LOG_TAG, "onHandleIntent Complete");
}

From source file:com.headstrong.npi.raas.Utils.java

public static String[] deleteSection(int index, String[] strArray) {
    Vector<String> arrayVector = new Vector<String>(Arrays.asList(strArray));
    arrayVector.remove(index);//w  w w  .java  2 s .c om
    String[] returnStr = (String[]) arrayVector.toArray(new String[0]);
    return returnStr;
}

From source file:com.headstrong.npi.raas.Utils.java

public static String[] insertSection(String insertStr, String[] strArray) {
    // strArray==null assign a new array
    strArray = strArray != null ? strArray : new String[0];

    Vector<String> arrayVector = new Vector<String>(Arrays.asList(strArray));
    arrayVector.add(insertStr);/*  ww  w.  j a va 2 s . com*/
    String[] returnStr = (String[]) arrayVector.toArray(new String[0]);
    return returnStr;
}