Example usage for java.util ArrayList remove

List of usage examples for java.util ArrayList remove

Introduction

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

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present.

Usage

From source file:com.chap.memo.memoNodes.MemoNode.java

/**
 * Remove this node.(=setting its value to null and removing all arcs) This method will delete
 * entire subgraphs. Removing large subgraphs can be
 * an expensive operation./*  www. j  a va  2  s.  c  o  m*/
 * 
 */
public void delete() {
    MemoNode current = this;
    ArrayList<UUID> todo = new ArrayList<UUID>(20);
    while (current != null) {
        UUID[] children = current.children.getNodesIds();
        UUID[] parents = current.parents.getNodesIds();
        current.update((byte[]) null);
        if (children.length > 0) {
            todo.ensureCapacity(todo.size() + children.length);
            todo.addAll(Arrays.asList(children));
            current.children.clear();
        }
        if (parents.length > 0) {
            current.parents.clear();
        }
        if (todo.size() > 0) {
            current = new MemoNode(todo.remove(0));
        } else {
            break;
        }
    }
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

private DnsClient getDnsClient(String name, int type, InetAddress dest) {
    ArrayList<DnsClient> dcs = dnsClients.get(name);
    for (int i = 0; dcs != null && i < dcs.size(); i++) {
        DnsClient dc = dcs.get(i);/*from  w ww.  j  a  v a  2s .  com*/
        if (dc.getAge() > MAX_QUERY_AGE) {
            dcs.remove(i);
            i--;
            continue;
        }
        if (type == dc.getQuery().type && (dest == null || dest.equals(dc.getDestination())))
            return dc;
    }
    return null;
}

From source file:com.qmetry.qaf.automation.step.client.text.BehaviorScanner.java

public static ArrayList<Object[]> scan(String strFile) {
    ArrayList<Object[]> rows = new ArrayList<Object[]>();
    File textFile;//from   www .  ja v  a2s . co m
    int lineNo = 0;

    BufferedReader br = null;
    try {

        logger.info("loading text file: " + strFile);
        textFile = new File(strFile);
        br = new BufferedReader(new FileReader(textFile));
        String strLine = "";
        // file line by line
        // exclude blank lines and comments
        StringBuffer currLineBuffer = new StringBuffer();
        while ((strLine = br.readLine()) != null) {
            // record line number
            lineNo++;
            /**
             * ignore if line is empty or comment line
             */
            if (!("".equalsIgnoreCase(strLine.trim())
                    || COMMENT_CHARS.contains("" + strLine.trim().charAt(0)))) {
                currLineBuffer.append((strLine.trim()));

                if (strLine.endsWith(LINE_BREAK)) {
                    /*
                     * Statement not completed. Remove line break character
                     * and continue statement reading from next line
                     */
                    currLineBuffer.delete(currLineBuffer.length() - LINE_BREAK.length(),
                            currLineBuffer.length());

                } else {
                    // process single statement
                    Object[] cols = new Object[] { "", "", "", lineNo };
                    String currLine = currLineBuffer.toString();
                    if ((StringUtil.indexOfIgnoreCase(currLine, AbstractScenarioFileParser.SCENARIO) == 0)
                            || (StringUtil.indexOfIgnoreCase(currLine,
                                    AbstractScenarioFileParser.STEP_DEF) == 0)
                            || (StringUtil.indexOfIgnoreCase(currLine, "META") == 0)) {

                        System.arraycopy(currLine.split(":", 2), 0, cols, 0, 2);

                        // append meta-data in last/scenario statement
                        if (StringUtil.indexOfIgnoreCase(((String) cols[0]).trim(), "META") == 0) {
                            Object[] row = new Object[4];
                            int prevIndex = rows.size() - 1;

                            Object[] prevRow = rows.remove(prevIndex);

                            System.arraycopy(prevRow, 0, row, 0, 2);
                            row[2] = ((String) cols[1]).trim();
                            row[3] = prevRow[3];
                            rows.add(row);
                            currLineBuffer = new StringBuffer();
                            continue;
                        }
                    } else {
                        // this is a statement
                        cols[0] = currLine;
                    }
                    rows.add(cols);
                    currLineBuffer = new StringBuffer();

                }
            }
        }
    } catch (Exception e) {
        String strMsg = "Exception while reading BDD file: " + strFile + "#" + lineNo;
        logger.error(strMsg + e);
        throw new AutomationError(strMsg, e);

    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    return rows;
}

From source file:springmvc.repository.ResultRepoDB.java

public ArrayList<HighscoreDisplay> getNewCompletionlistMulti(String classname) {
    ArrayList<Integer> gamesInOving = new ArrayList<Integer>();
    ArrayList<String> passedExercise = new ArrayList<String>();
    ArrayList<String> completionlist = new ArrayList<String>();
    ArrayList<HighscoreDisplay> nameList = new ArrayList<>();
    try {/* ww  w  .j a  va  2  s  . c  om*/
        gamesInOving = (ArrayList<Integer>) jdbcTemplateObject.query(sqlGetGamesInOving, new Object[] {},
                new GameIDMapper());
        for (int i = 0; i < gamesInOving.size(); i++) {
            if (i == 0) {
                completionlist = (ArrayList<String>) jdbcTemplateObject.query(sqlGetPassedExercise,
                        new Object[] { gamesInOving.get(i) }, new EmailMapper());
            } else {
                passedExercise = (ArrayList<String>) jdbcTemplateObject.query(sqlGetPassedExercise,
                        new Object[] { gamesInOving.get(i) }, new EmailMapper());
            }
            if (i != 0) {
                for (int c = 0; c < completionlist.size(); c++) {
                    boolean found = false;
                    for (int u = 0; u < passedExercise.size(); u++) {
                        if (completionlist.get(c).equals(passedExercise.get(u))) {
                            found = true;
                        }
                    }
                    if (found == false) {
                        completionlist.remove(c);
                    }
                }
            }
        }
        for (int i = 0; i < completionlist.size(); i++) {
            ArrayList<HighscoreDisplay> person = (ArrayList<HighscoreDisplay>) jdbcTemplateObject.query(
                    sqlGetCompletedNames, new Object[] { completionlist.get(i) }, new CompletionMapper());
            for (int u = 0; u < person.size(); u++) {
                if (person.get(u).getClassname().equals(classname)) {
                    nameList.add(person.get(u));
                }
            }
        }
    } catch (Exception e) {
    }
    return nameList;
}

From source file:com.mdground.screen.activity.MainActivity.java

private void startCallPatient(int doctorID, int opNO) {
    Integer viewPagerIndex = doctorsIndex.get(String.valueOf(doctorID));

    if (viewPagerIndex != null) {
        ((FlickerTextView) registeredViews.get(viewPagerIndex).findViewById(R.id.current_num))
                .startFlicker(String.valueOf(opNO));

        ArrayList<Appointment> appointments = new ArrayList<Appointment>();

        ArrayList<Appointment> list = allDoctorAppointmentArray.get(String.valueOf(doctorID));

        if (list != null) {
            appointments.addAll(list);//  w w  w  . j ava  2  s  .  c o m

            for (int i = 0; i < appointments.size(); i++) {
                Appointment item = appointments.get(i);
                if (item.getOPNo() == opNO) {
                    appointments.remove(i);
                    break;
                }
            }
            ((TwoWayGridView) registeredViews.get(viewPagerIndex).findViewById(R.id.gridview))
                    .setAdapter(new NumAdapter(appointments, doctorAdapter
                            .getItemViewType(viewPagerIndex) == DoctorAdapter.DOCOTOR_ITEM_SINGLE));
        }

    }
}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicReportGenerator.java

public void generateDynamicReport(String key, Map<String, String> params) {
    String html = new String();

    HttpSession session = ExecutionContext.get().getSession(false);
    PresentationTierCache ptc = ApplicationFactory.getPresentationTierCache();
    BusinessTierCache btc = ApplicationFactory.getBusinessTierCache();
    HttpServletRequest request = ExecutionContext.get().getHttpServletRequest();
    //      HttpServletResponse response = ExecutionContext.get().getHttpServletResponse();

    //lets hold a list of xml generating jobs, so we dont keep kicking off the same job
    ArrayList jobs = session.getAttribute("xmlJobs") != null ? (ArrayList) session.getAttribute("xmlJobs")
            : new ArrayList();

    //only generate XML if its not already cached...leave off for debug
    if (ptc.getNonPersistableObjectFromSessionCache(session.getId(), key) == null && !jobs.contains(key)) {
        Object o = btc.getObjectFromSessionCache(session.getId(), key);
        Finding finding = (Finding) o;/*from   w  w  w.  ja  v  a 2 s  .  co  m*/
        //generate the XML and cached it
        ReportGeneratorHelper.generateReportXML(finding);
        if (!jobs.contains(key))
            jobs.add(key);
        session.setAttribute("xmlJobs", jobs);
    }
    Object ob = ptc.getNonPersistableObjectFromSessionCache(session.getId(), key);
    if (ob != null && ob instanceof FindingReportBean) {
        try {
            FindingReportBean frb = (FindingReportBean) ob;
            Document reportXML = (Document) frb.getXmlDoc();

            html = ReportGeneratorHelper.renderReport(params, reportXML, "cc_report.xsl");

            jobs.remove(key);
            session.setAttribute("xmlJobs", jobs);
        } catch (Exception e) {
            html = "Error Generating the report.";
            StringWriter stack = new StringWriter();
            e.printStackTrace(new PrintWriter(stack));

            html = stack.toString();
        }
    } else {
        html = "Error generating the report";
    }
    //out the XHTML in the session for reference in presentation...could store in Prescache
    session.setAttribute(key + "_xhtml", html);
    return;
}

From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java

/**
 * Goes through the editor text and all the annotations to build the string that will be written to the disk.
 * Converts any special characters to their RTF tags as well.
 * /*from   w w  w .  j a v  a 2 s .c  o m*/
 * @param contents
 * @param model
 * @return
 */
private StringBuilder buildRTFString(StringBuilder contents, IAnnotationModel model) {
    StringBuilder output = new StringBuilder(HEADER);
    ArrayList<Position> positions = new ArrayList<Position>();
    ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    prepareAnnotationLists(model, positions, annotations);

    Position position = null;
    Annotation annotation = null;

    for (int i = 0; i < contents.length(); i++) {
        if (position == null) {
            for (int j = 0; j < positions.size(); j++) {
                if (positions.get(j).offset == i) {
                    position = positions.remove(j);
                    annotation = annotations.remove(j);
                    break;
                } else if (positions.get(j).offset > i) {
                    break;
                }
            }
            if (position != null) {
                output.append(getStartTagFromAnnotation(annotation));
            }
        }

        char c = contents.charAt(i);
        output.append(getMiddleChar(c));

        if (position != null && i == position.offset + position.length - 1) {
            output.append(getEndTagFromAnnotation(annotation));

            position = null;
            annotation = null;
        }

        output.append(getEndChar(c));
    }

    return output.append(FOOTER);
}

From source file:dao.DatasetsDAO.java

public static String getDatasetLogicalView() {
    List<Map<String, Object>> rows = null;
    rows = getJdbcTemplate().queryForList(GET_DATASET_LOGIC_TOP_LEVEL_NODES);
    JSONObject resultNode = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    ArrayList<JSONObject> queue = new ArrayList<JSONObject>();
    try {//from  w  w w  .  j  a v a  2 s. c  o m
        for (Map row : rows) {
            JSONObject jsonNode = new JSONObject();
            createNode(jsonNode, row);
            jsonArray.put(jsonNode);
            queue.add(jsonNode);
        }

        // width first traverse.
        while (!queue.isEmpty()) {
            JSONObject head = queue.get(0);
            queue.remove(0);

            JSONArray array = new JSONArray();
            String children = head.getString("children");
            if (children.length() > 0) {
                List<Long> ids = new ArrayList<>();
                for (String segment : children.split(",")) {
                    ids.add(Long.parseLong(segment));
                }
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("ids", ids);
                rows = getNamedParameterJdbcTemplate().queryForList(GET_DATASET_LOGIC_CHILDREN_LEVEL_NODES,
                        paramMap);
                for (Map row : rows) {
                    JSONObject jsonNode = new JSONObject();
                    createNode(jsonNode, row);
                    array.put(jsonNode);
                    queue.add(jsonNode);
                }
            }
            head.put("children", array);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    resultNode.put("children", jsonArray);
    return resultNode.toString();
}

From source file:springmvc.repository.ResultRepoDB.java

public ArrayList<HighscoreDisplay> getNewCompletionlistResemble(String classname) {
    ArrayList<Integer> gamesInOving = new ArrayList<Integer>();
    ArrayList<String> passedExercise = new ArrayList<String>();
    ArrayList<String> completionlist = new ArrayList<String>();
    ArrayList<HighscoreDisplay> nameList = new ArrayList<>();
    try {//from w ww. j a v a2  s.  c o m
        gamesInOving = (ArrayList<Integer>) jdbcTemplateObject.query(sqlGetGamesInOvingResemble,
                new Object[] {}, new GameIDMapperResemble());
        for (int i = 0; i < gamesInOving.size(); i++) {
            if (i == 0) {
                completionlist = (ArrayList<String>) jdbcTemplateObject.query(sqlGetPassedExerciseResemble,
                        new Object[] { gamesInOving.get(i) }, new EmailMapper());
            } else {
                passedExercise = (ArrayList<String>) jdbcTemplateObject.query(sqlGetPassedExerciseResemble,
                        new Object[] { gamesInOving.get(i) }, new EmailMapper());
            }
            if (i != 0) {
                for (int c = 0; c < completionlist.size(); c++) {
                    boolean found = false;
                    for (int u = 0; u < passedExercise.size(); u++) {
                        if (completionlist.get(c).equals(passedExercise.get(u))) {
                            found = true;
                        }
                    }
                    if (found == false) {
                        completionlist.remove(c);
                    }
                }
            }
        }
        for (int i = 0; i < completionlist.size(); i++) {
            ArrayList<HighscoreDisplay> person = (ArrayList<HighscoreDisplay>) jdbcTemplateObject.query(
                    sqlGetCompletedNamesResemble, new Object[] { completionlist.get(i) },
                    new CompletionMapper());
            for (int u = 0; u < person.size(); u++) {
                if (person.get(u).getClassname().equals(classname)) {
                    nameList.add(person.get(u));
                }
            }
        }
    } catch (Exception e) {
    }
    return nameList;
}

From source file:ArrayUtils.java

/**
 * Merges elements found in both of two arrays into a single array with no
 * duplicates./*from w w w .jav  a 2 s  .  co m*/
 * 
 * @param <T1>
 *            The type of the result
 * @param <T2>
 *            The type of the input arrays
 * @param type
 *            The type of the result
 * @param arrays
 *            The arrays to merge
 * @return A new array containing all common elements between
 *         <code>array1</code> and <code>array2</code>
 * @throws NullPointerException
 *             If either array is null
 */
public static <T1, T2 extends T1> T1[] mergeExclusive(Class<T1> type, T2[]... arrays) {
    if (arrays.length == 0)
        return (T1[]) Array.newInstance(type, 0);
    java.util.ArrayList<Object> retSet = new java.util.ArrayList<Object>();
    int i, j, k;
    for (j = 0; j < arrays[0].length; j++)
        retSet.add(arrays[0][j]);
    for (i = 1; i < arrays.length; i++) {
        for (j = 0; j < retSet.size(); j++) {
            boolean hasEl = false;
            for (k = 0; k < arrays[i].length; k++)
                if (equalsUnordered(retSet.get(j), arrays[i][k])) {
                    hasEl = true;
                    break;
                }
            if (!hasEl) {
                retSet.remove(j);
                j--;
            }
        }
    }
    return retSet.toArray((T1[]) Array.newInstance(type, retSet.size()));
}