Example usage for java.util ArrayList clear

List of usage examples for java.util ArrayList clear

Introduction

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

Prototype

public void clear() 

Source Link

Document

Removes all of the elements from this list.

Usage

From source file:com.cloudera.impala.testutil.ImpalaJdbcClient.java

/**
 * Executes one or more queries using the given ImpalaJdbcClient. Multiple queries
 * should be seperated using semi-colons.
 * @throws SQLException/*from   w  w w  .  jav a  2 s  .  c  o  m*/
 */
private static void execQuery(ImpalaJdbcClient client, String queryString)
        throws SQLException, NumberFormatException {

    String[] queries = queryString.trim().split(";");
    for (String query : queries) {
        query = query.trim();
        if (query.indexOf(" ") > -1) {
            if (query.substring(0, query.indexOf(" ")).equalsIgnoreCase("use")) {
                String[] split_query = query.split(" ");
                String db_name = split_query[split_query.length - 1];
                client.changeDatabase(db_name);
                client.getStatement().close();
                continue;
            }
        }
        long startTime = System.currentTimeMillis();
        ResultSet res = client.execQuery(query);
        ResultSetMetaData meta = res.getMetaData();
        ArrayList<String> arrayList = Lists.newArrayList();

        // This token (and the [END] token) are used to help parsing the result output
        // for test verification purposes.
        LOG.info("----[START]----");
        int rowCount = 0;
        while (res.next()) {
            arrayList.clear();
            for (int i = 1; i <= meta.getColumnCount(); ++i) {
                // Format the value based on the column type
                String colVal = formatColumnValue(res.getString(i), meta.getColumnTypeName(i));
                arrayList.add(colVal);
            }
            LOG.info(Joiner.on(",").join(arrayList));
            ++rowCount;
        }
        LOG.info("----[END]----");
        long endTime = System.currentTimeMillis();
        float seconds = (endTime - startTime) / 1000F;
        LOG.info("Returned " + rowCount + " row(s) in " + seconds + "s");

        // TODO: To work around a JDBC driver issue (CDH-10035), make sure the Statement
        // is closed after every query.
        client.getStatement().close();
    }
}

From source file:Main.java

public static void sortObjectArrayListsSimple(ArrayList masterList, String paramName, ArrayList... listsIn) {
    int count = masterList.size();
    for (ArrayList al : listsIn) {
        if (al.size() != count || count == 0) {
            System.out.println("counts of lists are not the same, did not sort");
            return;
        }//from ww  w.  j  ava2 s . com
    }
    ArrayList<ArrayList> result = sortObjectArrayListSimpleMaster(masterList, paramName);
    masterList.clear();
    for (Object o : result.get(0))
        masterList.add(o);
    //masterList = result.get(0);
    ArrayList[] orderedLists = new ArrayList[listsIn.length];
    for (int i = 0; i < listsIn.length; i++)
        orderedLists[i] = new ArrayList();
    for (int i = 0; i < result.get(1).size(); i++) {
        int index = (Integer) result.get(1).get(i);
        for (int j = 0; j < listsIn.length; j++) {
            orderedLists[j].add(listsIn[j].get(index));
        }
    }

    for (int i = 0; i < listsIn.length; i++) {
        listsIn[i].clear();
        for (int j = 0; j < orderedLists[i].size(); j++) {
            listsIn[i].add(orderedLists[i].get(j));
        }
    }
}

From source file:com.mediatek.mms.util.VCardUtils.java

public static void deleteVCardTempFiles(Context context, ArrayList<String> files) {
    for (int i = 0; i < files.size(); i++) {
        deleteVCardTempFile(context, files.get(i));
    }// w  w  w .ja  v  a 2s  . c o  m
    files.clear();
}

From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader.java

static FileObject[] resolve(FileSystemManager vfs, String uris, ArrayList<FileObject> pathsToMonitor)
        throws FileSystemException {
    if (uris == null)
        return new FileObject[0];

    ArrayList<FileObject> classpath = new ArrayList<FileObject>();

    pathsToMonitor.clear();

    for (String path : uris.split(",")) {

        path = path.trim();//  w  w w  .  j  a  v a2  s  . c  om

        if (path.equals(""))
            continue;

        path = AccumuloClassLoader.replaceEnvVars(path, System.getenv());

        FileObject fo = vfs.resolveFile(path);

        switch (fo.getType()) {
        case FILE:
        case FOLDER:
            classpath.add(fo);
            pathsToMonitor.add(fo);
            break;
        case IMAGINARY:
            // assume its a pattern
            String pattern = fo.getName().getBaseName();
            if (fo.getParent() != null && fo.getParent().getType() == FileType.FOLDER) {
                pathsToMonitor.add(fo.getParent());
                FileObject[] children = fo.getParent().getChildren();
                for (FileObject child : children) {
                    if (child.getType() == FileType.FILE && child.getName().getBaseName().matches(pattern)) {
                        classpath.add(child);
                    }
                }
            } else {
                log.warn("ignoring classpath entry " + fo);
            }
            break;
        default:
            log.warn("ignoring classpath entry " + fo);
            break;
        }

    }

    return classpath.toArray(new FileObject[classpath.size()]);
}

From source file:core.Utility.java

private static ArrayList<String> getSynonymsWordnet(String _word) {
    ArrayList<String> _list = new ArrayList();

    File f = new File("WordNet\\2.1\\dict");
    System.setProperty("wordnet.database.dir", f.toString());
    WordNetDatabase database = WordNetDatabase.getFileInstance();
    Synset[] synsets = database.getSynsets(_word);

    if (synsets.length > 0) {
        HashSet hs = new HashSet();
        for (Synset synset : synsets) {
            String[] wordForms = synset.getWordForms();
            _list.addAll(Arrays.asList(wordForms));
        }//ww w . j  ava2s .com

        hs.addAll(_list);
        _list.clear();
        _list.addAll(hs);
    }

    return _list;
}

From source file:com.rbsoftware.pfm.personalfinancemanager.utils.Utils.java

/**
 * Parsing string to retrieve document data
 *///  w  w  w  .  j  ava2s .co m
public static ArrayList<String> getItem(ArrayList<String> reportResult, int i) {
    ArrayList<String> item = new ArrayList<>();
    item.add(0, "0");
    item.add(1, MainActivity.defaultCurrency);
    item.add(2, "Never");
    for (String listItem : reportResult) {
        String[] parts = listItem.split("-");
        int position = Integer.valueOf(parts[0]);
        if (i == position) {
            item.clear();
            item.add(0, parts[2]);
            item.add(1, parts[3]);
            /* Recursion disabled in version 1.0
            TODO enable recursion in future versions
            item.add(2,parts[4]);
            */
            item.add(2, "Never");
        }

    }

    return item;
}

From source file:Main.java

public static int getFrequentElement(int[] bcp) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;//from  www  .  ja  v a  2 s.  c o  m

    for (int col = 0; col < bcp.length; col++) {
        //System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(bcp[col])) {
            map.put(bcp[col], id++);
            count.add(1);
            uniId.add(bcp[col]);
        } else {
            no = map.get(bcp[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    //System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    return maxId;
}

From source file:Main.java

public static boolean getFrequentElementBinary(int[] sample) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;//from   w w w. j  a  va 2 s  .com

    for (int col = 0; col < sample.length; col++) {
        // System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(sample[col])) {
            map.put(sample[col], id++);
            count.add(1);
            uniId.add(sample[col]);
        } else {
            no = map.get(sample[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    // System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    if (maxId == 1)
        return true;
    else
        return false;
}

From source file:Main.java

public static void stripDuplicateAttributes(Node node, Node parent) {

    // The output depends on the type of the node
    switch (node.getNodeType()) {
    case Node.DOCUMENT_NODE: {
        Document doc = (Document) node;
        Node child = doc.getFirstChild();
        while (child != null) {
            stripDuplicateAttributes(child, node);
            child = child.getNextSibling();
        }/*  ww  w. j  a  v  a 2 s. co  m*/
        break;
    }

    case Node.ELEMENT_NODE: {
        Element elt = (Element) node;
        NamedNodeMap attrs = elt.getAttributes();

        ArrayList nodesToRemove = new ArrayList();
        int nodesToRemoveNum = 0;

        for (int i = 0; i < attrs.getLength(); i++) {
            final Node a = attrs.item(i);

            for (int j = 0; j < attrs.getLength(); j++) {
                final Node b = attrs.item(j);

                //if there are two attributes with same name
                if (i != j && (a.getNodeName().equals(b.getNodeName()))) {
                    nodesToRemove.add(b);
                    nodesToRemoveNum++;
                }
            }
        }

        for (int i = 0; i < nodesToRemoveNum; i++) {
            Attr nodeToDelete = (Attr) nodesToRemove.get(i);
            Element nodeToDeleteParent = (Element) node; // nodeToDelete.getParentNode();
            nodeToDeleteParent.removeAttributeNode(nodeToDelete);
        }

        nodesToRemove.clear();

        Node child = elt.getFirstChild();
        while (child != null) {
            stripDuplicateAttributes(child, node);
            child = child.getNextSibling();
        }

        break;
    }

    default:
        //do nothing
        break;
    }
}

From source file:edu.cudenver.bios.matrix.OrthogonalPolynomials.java

/**
 * Create a within or between subject contrast (C) for polynomial trends
 * for an arbitrary list of factors.  The returned collection includes
 * the grand mean contrast, all 1-factor main effect contrasts, and
 * all possible interaction contrasts/*from   ww  w .  j  a v a  2s  .  c o  m*/
 * 
 * @param factorList list of factors, including name and value information
 * @return polynomial contrast collection.
 * @throws IllegalArgumentException
 */
public static OrthogonalPolynomialContrastCollection buildContrastCollection(List<Factor> factorList,
        boolean between) throws IllegalArgumentException {
    if (factorList == null || factorList.size() <= 0)
        throw new IllegalArgumentException("no factors specified");

    ArrayList<RealMatrix> zeroTrendList = new ArrayList<RealMatrix>(factorList.size());
    ArrayList<RealMatrix> factorTrendList = new ArrayList<RealMatrix>(factorList.size());
    for (Factor factor : factorList) {
        double[] centered = centerAndScale(factor.getValues());
        RealMatrix poly = OrthogonalPolynomials.orthogonalPolynomialCoefficients(centered, centered.length - 1);
        zeroTrendList.add(poly.getColumnMatrix(0));
        factorTrendList.add(poly.getSubMatrix(0, poly.getRowDimension() - 1, 1, poly.getColumnDimension() - 1));
    }

    OrthogonalPolynomialContrastCollection results = new OrthogonalPolynomialContrastCollection();
    /*
     * We need to create contrasts for every possible combination of
     * zero and factor trends.  The possible combinations can be  
     * enumerated by the binary representation of the numbers
     * 0 - 2^(#factors).  In this case, 0 indicates that the zero-trend contrast should
     * be included in the Kronecker product for a given factor, and 1 indicates that the 
     * factor trend contrast should be included in the Kronecker product.
     */
    ArrayList<RealMatrix> kroneckerList = new ArrayList<RealMatrix>(factorList.size());
    ArrayList<Factor> activeFactorList = new ArrayList<Factor>(factorList.size());
    // build the grand mean
    for (RealMatrix zeroTrend : zeroTrendList)
        kroneckerList.add(zeroTrend);
    if (between)
        results.addContrast(
                new OrthogonalPolynomialContrast(MatrixUtils.getKroneckerProduct(kroneckerList).transpose()));
    else
        results.addContrast(new OrthogonalPolynomialContrast(MatrixUtils.getKroneckerProduct(kroneckerList)));
    // loop over the remaining contrasts
    int totalContrasts = (int) Math.pow(2.0, (double) factorList.size());
    for (int i = 1; i < totalContrasts; i++) {
        kroneckerList.clear();
        activeFactorList.clear();
        int mask = 1;
        for (int factorIdx = 0; factorIdx < factorList.size(); factorIdx++, mask *= 2) {
            if ((i & mask) != 0) {
                kroneckerList.add(factorTrendList.get(factorIdx));
                activeFactorList.add(factorList.get(factorIdx));
            } else {
                kroneckerList.add(zeroTrendList.get(factorIdx));
            }
        }
        // add the appropriate contrast type
        // note that if "i" is a power of 2 then we have a  main effect contrast, else interaction
        RealMatrix contrast = null;
        if (between)
            contrast = MatrixUtils.getKroneckerProduct(kroneckerList).transpose();
        else
            contrast = MatrixUtils.getKroneckerProduct(kroneckerList);
        results.addContrast(new OrthogonalPolynomialContrast(
                ((i & (i - 1)) == 0 ? ContrastType.MAIN_EFFECT : ContrastType.INTERACTION), activeFactorList,
                contrast));
    }

    return results;
}