Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:tdunnick.jphineas.console.queue.Charts.java

/**
 * Sort and setup chart data by "constraint"
 * //from   w  ww  .  jav a  2  s  . c  o m
 * @param r list of constraint, time pairs
 * @param ends ending date for list
 * @param days covered by list
 * @return bar chart data
 */
private CategoryDataset createBarChartDataset(ArrayList<String[]> r, long ends, long days) {
    ArrayList<String> constraints = new ArrayList<String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // first time through just collect the constraint names
    for (int i = 0; i < r.size(); i++) {
        String[] item = r.get(i);
        String k = item[0];
        if (!constraints.contains(k))
            constraints.add(k);
    }
    long interval = days * MS;
    long start = ends - interval;
    interval /= 5;
    int[] counts = new int[constraints.size()];
    for (int i = 0; i < constraints.size(); i++)
        counts[i] = 0;
    for (int i = 0; i < r.size(); i++) {
        String[] item = r.get(i);
        long d = Long.parseLong(item[1]);
        if (d > start) {
            addBarData(dataset, constraints, start, counts);
            start += interval;
        }
        counts[constraints.indexOf(item[0])]++;
    }
    addBarData(dataset, constraints, start, counts);
    while ((start += interval) < ends)
        addBarData(dataset, constraints, start, counts);
    return dataset;
}

From source file:tdunnick.phinmsx.model.Charts.java

private XYSeriesCollection createLineChartDataset(ArrayList r, long ends, long days) {
    ArrayList constraints = new ArrayList();
    XYSeriesCollection dataset = new XYSeriesCollection();

    // first time through just collect the constraint names
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        String k = (String) item[0];
        if (!constraints.contains(k)) {
            constraints.add(k);//from  w w  w . j  av  a2s . c  om
            dataset.addSeries(new XYSeries(k));
        }
    }
    long interval = days * MS;
    long start = ends - interval;
    interval /= 5;
    int[] counts = new int[constraints.size()];
    for (int i = 0; i < constraints.size(); i++)
        counts[i] = 0;
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        long d = Long.parseLong(item[1]);
        if (d > start) {
            addLineData(dataset, start, counts);
            start += interval;
        }
        int j = constraints.indexOf(item[0]);
        if (j >= 0)
            counts[j]++;
    }
    addLineData(dataset, start, counts);
    while ((start += interval) < ends)
        addLineData(dataset, start, counts);
    return dataset;
}

From source file:com.xandrev.jdorg.main.ExecutorService.java

private void applyOrganizers(File initialFolder) {
    ArrayList<String> list = new ArrayList<String>();
    for (Organizer org : organizerList) {
        logger.info("Organizer: " + org.getClass().toString());
        Collection<File> fileList = org.getFiles(initialFolder);
        if (fileList != null) {
            for (File fd : fileList) {
                String folder = org.generateFolder(fd.getName());
                if (folder != null && !list.contains(fd.getAbsolutePath())) {
                    list.add(fd.getAbsolutePath());
                    logger.info("Folder: " + folder);
                    logger.info("Root Folder: " + folder);
                    String finalPath = finalDirectory + File.separator + folder;
                    File dirPath = new File(finalPath);
                    logger.info("Final Path: " + finalPath);
                    if (!dirPath.exists()) {
                        boolean result = dirPath.mkdirs();
                        logger.debug("Resultado de la creacion de directorios: " + result);
                    }/*from   www .  j  a v  a 2s . c o m*/
                    File finalFile = new File(finalPath + File.separator + fd.getName());
                    if (!finalFile.exists()) {
                        try {
                            logger.info("Final path not exist. Copying the file at: "
                                    + finalFile.getAbsolutePath());
                            String origPath = fd.getAbsolutePath();
                            String origHash = calculateHash(fd);
                            logger.debug("Original hash: " + origHash);
                            boolean renamed = fd.renameTo(finalFile);
                            boolean deleted = false;
                            boolean copied = false;
                            logger.info("Renamed attempt result successfully: " + renamed);
                            if (!renamed) {
                                logger.info("Trying to copy the file to: " + finalFile.getAbsolutePath());
                                FileUtils.copyFile(fd, finalFile);
                                copied = finalFile.exists();
                                if (copied) {
                                    String finalHash = calculateHash(finalFile);
                                    logger.debug("Final hash: " + finalHash);
                                    if (origHash != null && origHash.equals(finalHash)) {
                                        deleted = fd.delete();
                                        logger.info("Copy finished: " + finalFile.getAbsolutePath());
                                    } else {
                                        logger.info("Copy finisehd with error because hash are not equals");
                                        finalFile.delete();
                                    }
                                }

                            }

                            logger.info(i18n.getLocalizerText("file.rename.1") + fd.getAbsolutePath()
                                    + i18n.getLocalizerText("file.rename.2") + finalFile.getAbsolutePath());
                            logger.info("Starting to audit the file organized");
                            org.audit(auditService, origPath, finalPath, renamed, copied, deleted);
                            logger.info("Audit the file organized completed");
                        } catch (IOException ex) {
                            logger.error(ex);
                        }
                    }

                    if (!fd.delete()) {
                        try {
                            FileDeleteStrategy.FORCE.delete(fd);
                        } catch (IOException e) {
                            logger.error(e);
                        }
                    }

                }
            }
        }
    }

}

From source file:tdunnick.phinmsx.model.Charts.java

/**
 * Sort and setup chart data by "constraint"
 * /*ww w  . j  a va2s  . c  o  m*/
 * @param r list of constraint, time pairs
 * @param ends ending date for list
 * @param days covered by list
 * @return bar chart data
 */
private CategoryDataset createBarChartDataset(ArrayList r, long ends, long days) {
    ArrayList constraints = new ArrayList();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // first time through just collect the constraint names
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        String k = (String) item[0];
        if (!constraints.contains(k))
            constraints.add(k);
    }
    long interval = days * MS;
    long start = ends - interval;
    interval /= 5;
    int[] counts = new int[constraints.size()];
    for (int i = 0; i < constraints.size(); i++)
        counts[i] = 0;
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        long d = Long.parseLong(item[1]);
        if (d > start) {
            addBarData(dataset, constraints, start, counts);
            start += interval;
        }
        counts[constraints.indexOf(item[0])]++;
    }
    addBarData(dataset, constraints, start, counts);
    while ((start += interval) < ends)
        addBarData(dataset, constraints, start, counts);
    return dataset;
}

From source file:com.k42b3.aletheia.protocol.http.HttpProtocol.java

public void run() {
    try {//ww w .jav  a2  s  . c o m
        // get socket
        Socket socket = this.getSocket();
        conn.bind(socket, params);

        // build request
        BasicHttpRequest request;

        if (!this.getRequest().getBody().isEmpty()) {
            request = new BasicHttpEntityEnclosingRequest(this.getRequest().getMethod(),
                    this.getRequest().getPath());
        } else {
            request = new BasicHttpRequest(this.getRequest().getMethod(), this.getRequest().getPath());
        }

        // add headers
        String boundary = null;
        ArrayList<String> ignoreHeader = new ArrayList<String>();
        ignoreHeader.add("Content-Length");
        ignoreHeader.add("Expect");

        LinkedList<Header> headers = this.getRequest().getHeaders();

        for (int i = 0; i < headers.size(); i++) {
            if (!ignoreHeader.contains(headers.get(i).getName())) {
                // if the content-type header gets set the conent-length
                // header is automatically added
                request.addHeader(headers.get(i));
            }

            if (headers.get(i).getName().equals("Content-Type")
                    && headers.get(i).getValue().startsWith("multipart/form-data")) {
                String header = headers.get(i).getValue().substring(headers.get(i).getValue().indexOf(";") + 1)
                        .trim();

                if (!header.isEmpty()) {
                    String parts[] = header.split("=");

                    if (parts.length >= 2) {
                        boundary = parts[1];
                    }
                }
            }
        }

        // set body
        if (request instanceof BasicHttpEntityEnclosingRequest && boundary != null) {
            boundary = "--" + boundary;
            StringBuilder body = new StringBuilder();
            String req = this.getRequest().getBody();

            int i = 0;
            String partHeader;
            String partBody;

            while ((i = req.indexOf(boundary, i)) != -1) {
                int hPos = req.indexOf("\n\n", i + 1);
                if (hPos != -1) {
                    partHeader = req.substring(i + boundary.length() + 1, hPos).trim();
                } else {
                    partHeader = null;
                }

                int bpos = req.indexOf(boundary, i + 1);
                if (bpos != -1) {
                    partBody = req.substring(hPos == -1 ? i : hPos + 2, bpos);
                } else {
                    partBody = req.substring(hPos == -1 ? i : hPos + 2);
                }

                if (partBody.equals(boundary + "--")) {
                    body.append(boundary + "--" + "\r\n");
                    break;
                } else if (!partBody.isEmpty()) {
                    body.append(boundary + "\r\n");
                    if (partHeader != null && !partHeader.isEmpty()) {
                        body.append(partHeader.replaceAll("\n", "\r\n"));
                        body.append("\r\n");
                        body.append("\r\n");
                    }
                    body.append(partBody);
                }

                i++;
            }

            this.getRequest().setBody(body.toString().replaceAll("\r\n", "\n"));

            HttpEntity entity = new StringEntity(this.getRequest().getBody());

            ((BasicHttpEntityEnclosingRequest) request).setEntity(entity);
        } else if (request instanceof BasicHttpEntityEnclosingRequest) {
            HttpEntity entity = new StringEntity(this.getRequest().getBody());

            ((BasicHttpEntityEnclosingRequest) request).setEntity(entity);
        }

        logger.info("> " + request.getRequestLine().getUri());

        // request
        request.setParams(params);
        httpexecutor.preProcess(request, httpproc, context);

        HttpResponse response = httpexecutor.execute(request, conn, context);
        response.setParams(params);
        httpexecutor.postProcess(response, httpproc, context);

        logger.info("< " + response.getStatusLine());

        // update request headers 
        LinkedList<Header> header = new LinkedList<Header>();
        Header[] allHeaders = request.getAllHeaders();

        for (int i = 0; i < allHeaders.length; i++) {
            header.add(allHeaders[i]);
        }

        this.getRequest().setHeaders(header);

        // create response
        this.response = new Response(response);

        // call callback
        callback.onResponse(this.request, this.response);
    } catch (Exception e) {
        Aletheia.handleException(e);
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
            Aletheia.handleException(e);
        }
    }
}

From source file:afest.datastructures.tree.decision.erts.grower.AERTGrower.java

/**
 * Return the constant attributes in the set, assuming that the attributes contained in constantAttributes are already constant.
 * @param <T> Type of ITrainingPoints used by the Extra Trees.
 * @param set set for which to find the constant attributes.
 * @param constantAttributes set of attributes that are already constant.
 * @param attributeList list of all attributes present in each point in the set.
 * @return the constant attributes in the set, assuming that the attributes contained in constantAttributes are already constant.
 *///from  ww w . j  a v a2 s .c om
private <T extends ITrainingPoint<R, O>> ArrayList<R> getConstantAttributes(Collection<T> set,
        ArrayList<R> constantAttributes, ArrayList<R> attributeList) {
    ArrayList<R> newConstantAttributes = new ArrayList<R>(constantAttributes);

    T firstT = set.iterator().next();
    // For each possible attribute in the points
    for (R anAttribute : attributeList) {
        // If it was not already constant
        if (!newConstantAttributes.contains(anAttribute)) {
            // verify if it is now constant
            boolean isConstant = true;
            for (T aT : set) {
                if (firstT.getValue(anAttribute) != aT.getValue(anAttribute)) {
                    isConstant = false;
                    break;
                }
            }
            if (isConstant) {
                newConstantAttributes.add(anAttribute);
            }
        }
    }
    return newConstantAttributes;
}

From source file:it.unipr.ce.dsg.s2p.peer.PeerListManager.java

/**
 * Get the list with max <code>number</code> descriptor
 * /*from   ww w.j  av a2 s. c o  m*/
 * @param number the number max of element returned in the list
 * @return PeerListManager PeerListManager
 */
public PeerListManager getRandomPeers(int number) {

    if (number > 0) {
        //create new list
        PeerListManager newPeerList = new PeerListManager(number);
        Iterator<String> iter = this.keySet().iterator();

        //create array list to contain random key generated 
        ArrayList<Integer> arrayRdmNumber = new ArrayList<Integer>(number);
        //get the size of peer list
        int nKeys = this.size();
        //initialize random number
        int rdmNumber = 0;

        //create a list of random number
        while (arrayRdmNumber.size() < number) {

            rdmNumber = (int) (Math.random() * nKeys);
            //if rdmNumber not exists add 
            if (!arrayRdmNumber.contains(rdmNumber))
                arrayRdmNumber.add(rdmNumber);

        }

        // initialize index for while  
        int i = 0;
        while (iter.hasNext()) {

            //set current key
            String key = iter.next();
            //if key is equal to random key add it into the list
            if (arrayRdmNumber.contains(i)) {

                newPeerList.put(key, this.get(key));
            }
            i++;
        }

        return newPeerList;

    } else
        return null;

}

From source file:edu.brandeis.cs.nlp.mae.model.Tag.java

protected Set<String> checkRequiredAtts() {
    Set<String> underspec = new TreeSet<>();
    ArrayList<AttributeType> existingAtts = new ArrayList<>();
    for (Attribute att : getAttributes()) {
        // this for each loop always goes through all items,
        // making sure DAO connection is closed after iteration.
        if (att.getValue() != null && att.getValue().length() > 0) {
            existingAtts.add(att.getAttributeType());
        }//from   w w  w  .  j  a v  a 2s . c  om
    }
    for (AttributeType attType : getTagtype().getAttributeTypes()) {
        if (attType.isRequired() && !existingAtts.contains(attType)) {
            underspec.add(attType.getName());
        }
    }
    return underspec;
}

From source file:tdunnick.jphineas.console.queue.Charts.java

private XYSeriesCollection createLineChartDataset(ArrayList<String[]> r, long ends, long days) {
    ArrayList<String> constraints = new ArrayList<String>();
    XYSeriesCollection dataset = new XYSeriesCollection();

    // first time through just collect the constraint names
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        String k = (String) item[0];
        if (!constraints.contains(k)) {
            constraints.add(k);//from ww  w  .j a v a2 s  . c  o  m
            dataset.addSeries(new XYSeries(k));
        }
    }
    long interval = days * MS;
    long start = ends - interval;
    interval /= 5;
    int[] counts = new int[constraints.size()];
    for (int i = 0; i < constraints.size(); i++)
        counts[i] = 0;
    for (int i = 0; i < r.size(); i++) {
        String[] item = (String[]) r.get(i);
        long d = Long.parseLong(item[1]);
        if (d > start) {
            addLineData(dataset, start, counts);
            start += interval;
        }
        int j = constraints.indexOf(item[0]);
        if (j >= 0)
            counts[j]++;
    }
    addLineData(dataset, start, counts);
    while ((start += interval) < ends)
        addLineData(dataset, start, counts);
    return dataset;
}

From source file:SecurityGiver.java

public void processDictionary() throws JSONException, IOException {
    //ArrayList<String> keys = new ArrayList<String>();
    //ArrayList<Integer> values = new ArrayList<Integer>();
    HashMap<String, Integer> processedDictionary = new HashMap<String, Integer>();
    ArrayList<String> locales = new ArrayList<String>(Arrays.asList(Locale.getISOCountries()));
    ArrayList<String> queries = new ArrayList<String>(Arrays.asList(d_queryString));

    for (String line : allDescriptions) {
        String[] words = line.split(" ");
        for (String word : words)
            if (!queries.contains(word) && (!locales.contains(word))) {
                if (processedDictionary.get(word) == null)
                    processedDictionary.put(word, 1);
                else
                    processedDictionary.put(word, processedDictionary.get(word) + 1);
            }//from  w  w  w. ja  va 2s .  c o m

    }
    //JSONObject obj = new JSONObject();
    //for (String s : processedDictionary.keySet()) {
    //    int val = processedDictionary.get(s);
    //if (!d_ignore[0].toLowerCase().contains(s.toLowerCase()) && (val > 5)) obj.put(s, val);

    //}
    FileWriter file = new FileWriter("dataForCloud.json");

    //file.write(obj.toString(3));

    try {
        file.write("{");
        //quick and dirty fix
        int i = processedDictionary.size();
        //JSONObject obj = new JSONObject();
        for (String s : processedDictionary.keySet()) {
            i--;
            Integer val = processedDictionary.get(s);
            if ((val > 1 || i == 1) && (!search.toLowerCase().contains(s.toLowerCase()))) {
                //file.write("{text: \""+s+"\", weight: "+val.toString()+"}");
                file.write("\"" + s + "\"" + ":" + "\"" + val.toString() + "\"");
                if (i > 1)
                    file.write(",\n");
            }
            //"{text: "+s, " weight: "+val.toString()+"}");
        }
        file.write("}");
        System.out.println("Successfully printed");

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        file.flush();
        file.close();
    }

}