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.comcast.oscar.sql.queries.PacketCableSqlQuery.java

/**
4 variable ClassOfService subtypes 7 1.0                                      (4,'4',0,'ClassOfService','',0,variable,integer,1.0);
 s 1 1 ClassId uint8 1.0                                                       (5,'1',4,'ClassId','',0,1,integer,1.0);
 s 2 4 MaxDownstreamRate uint32 1.0                                            (6,'2',4,'MaxDownstreamRate','',0,4,integer,1.0);
 s 3 4 MaxUpstreamRate uint32 1.0                                              (7,'3',4,'MaxUpstreamRate','',0,4,integer,1.0);
 s 4 1 UpstreamChannelPriority uint8 1.0                                       (8,'4',4,'UpstreamChannelPriority','',0,1,integer,1.0);
 s 5 4 MinUpstreamRate uint32 1.0                                              (9,'5',4,'MinUpstreamRate','',0,4,integer,1.0);
 s 6 2 MaxUpstreamBurst uint16 1.0                                             (10,'6',4,'MaxUpstreamBurst','',0,2,integer,1.0);
 s 7 1 CoSPrivacyEnable boolean 1.0                                            (11,'7',4,'CoSPrivacyEnable','',0,1,integer,1.0);
<p>//w  w  w . j a va 2 s  .  c  o  m
24 variable UpstreamServiceFlow subtypes 28 1.1                               (151,'24',0,'UpstreamServiceFlow','',0,variable,integer,1.1);
 s 1 2 SfReference uint16 1.1                                                  (152,'1',151,'SfReference','',0,2,integer,1.1);
 s 4 variable SfClassName null_terminated_string 1.1                           (153,'4',151,'SfClassName','',0,variable,integer,1.1);
 s 5 variable SfErrorEncoding subtypes 3 1.1                                   (154,'5',151,'SfErrorEncoding','',0,variable,integer,1.1);
   s s 1 1 ErroredParameter uint8 1.1                                            (155,'1',154,'ErroredParameter','',0,1,integer,1.1);
   s s 2 1 ErrorCode uint8 1.1                                                   (156,'2',154,'ErrorCode','',0,1,integer,1.1);
   s s 3 variable ErrorMessage null_terminated_string 1.1                        (157,'3',154,'ErrorMessage','',0,variable,integer,1.1);
 s 6 1 SfQosSetType uint8 1.1                                                  (158,'6',151,'SfQosSetType','',0,1,integer,1.1);
<p>
+------------------------------+----------------------+------+-----+---------+----------------+
| Field                        | Type                 | Null | Key | Default | Extra          |
+------------------------------+----------------------+------+-----+---------+----------------+
| ID                           | int(10) unsigned     | NO   | PRI | NULL    | auto_increment | 
| TYPE                         | smallint(5) unsigned | NO   |     | NULL    |                | 
| PARENT_ID                    | int(10) unsigned     | YES  |     | NULL    |                | 
| TLV_NAME                     | varchar(50)          | NO   |     | NULL    |                | 
| TLV_DESCRIPTION              | text                 | NO   |     | NULL    |                | 
| LENGTH_MIN                   | smallint(5) unsigned | NO   |     | NULL    |                | 
| LENGTH_MAX                   | smallint(5) unsigned | NO   |     | NULL    |                | 
| DATA_TYPE                    | varchar(50)          | YES  |     | NULL    |                | 
| BYTE_LENGTH                  | tinyint(3) unsigned  | NO   |     | NULL    |                | 
| MIN_SUPPORTED_DOCSIS_VERSION | varchar(50)          | NO   |     | NULL    |                | 
+------------------------------+----------------------+------+-----+---------+----------------+
<p>
 * @param iRowID
 * @param iParentID
 * @param aliTlvEncodeHistory
        
        
 * @return JSONObject
 * @throws JSONException */
private JSONObject recursiveTlvDefinitionBuilder(Integer iRowID, Integer iParentID,
        ArrayList<Integer> aliTlvEncodeHistory) throws JSONException {

    Statement parentCheckStatement = null, getRowDefinitionStatement = null;

    ResultSet resultSetParentCheck = null, resultSetGetRowDefinition = null;

    aliTlvEncodeHistory.add(getTypeFromRowID(iParentID));

    String sqlQuery;

    JSONObject tlvJsonObj = null;

    // This query will check for child rows that belong to a parent row
    sqlQuery = "SELECT " + "   ID ," + "   TYPE ," + "   TLV_NAME," + "   PARENT_ID " + "FROM "
            + "   PACKET_CABLE_TLV_DEFINITION " + "WHERE " + "   PARENT_ID = '" + iRowID + "'";

    try {

        //Create statement
        parentCheckStatement = sqlConnection.createStatement();

        //Get Result Set of Query
        resultSetParentCheck = parentCheckStatement.executeQuery(sqlQuery);

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

    /* ******************************************************************************************************
     * If resultSet return an empty, this means that the row does not have a child and is not a Major TLV
     * *****************************************************************************************************/

    try {

        if ((SqlConnection.getRowCount(resultSetParentCheck) == 0) && (iParentID != MAJOR_TLV)) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT * FROM " + "   PACKET_CABLE_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            //Create statement to get Rows from ROW ID's
            getRowDefinitionStatement = sqlConnection.createStatement();

            //Get Result Set
            resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery);

            //Advance to next index in result set, this is needed
            resultSetGetRowDefinition.next();

            /*************************************************
             *             Assemble JSON OBJECT
             *************************************************/

            tlvJsonObj = new JSONObject();

            tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(Dictionary.TLV_NAME,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME));
            tlvJsonObj.put(Dictionary.LENGTH_MIN,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN));
            tlvJsonObj.put(Dictionary.LENGTH_MAX,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX));
            tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS));
            tlvJsonObj.put(Dictionary.DATA_TYPE,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE));
            tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false);
            tlvJsonObj.put(Dictionary.BYTE_LENGTH,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH));

            aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(PacketCableSqlQueryConstants.PARENT_TYPE_LIST, aliTlvEncodeHistory);

            if (debug)
                System.out.println(tlvJsonObj.toString());

        } else if (iParentID == MAJOR_TLV) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT * FROM " + "   DOCSIS_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            getRowDefinitionStatement = sqlConnection.createStatement();

            resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery);

            resultSetGetRowDefinition.next();

            /*************************************************
             *             Assemble JSON OBJECT
             *************************************************/

            tlvJsonObj = new JSONObject();

            tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(Dictionary.TLV_NAME,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME));
            tlvJsonObj.put(Dictionary.LENGTH_MIN,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN));
            tlvJsonObj.put(Dictionary.LENGTH_MAX,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX));
            tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS));
            tlvJsonObj.put(Dictionary.DATA_TYPE,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE));
            tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false);
            tlvJsonObj.put(Dictionary.BYTE_LENGTH,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH));

            aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(PacketCableSqlQueryConstants.PARENT_TYPE_LIST, aliTlvEncodeHistory);

            if (debug)
                System.out.println(tlvJsonObj.toString());
        }

        if (SqlConnection.getRowCount(resultSetParentCheck) > 0) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT " + "   TYPE , " + "   TLV_NAME," + "   PARENT_ID" + " FROM "
                    + "   DOCSIS_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            try {

                Integer iParentIdTemp = null;

                JSONArray tlvJsonArray = new JSONArray();

                while (resultSetParentCheck.next()) {

                    iParentIdTemp = resultSetParentCheck.getInt("PARENT_ID");

                    ArrayList<Integer> aliTlvEncodeHistoryNext = new ArrayList<Integer>();

                    aliTlvEncodeHistoryNext.addAll(aliTlvEncodeHistory);

                    if (debug)
                        System.out.println("aliTlvEncodeHistoryNext: " + aliTlvEncodeHistoryNext);

                    aliTlvEncodeHistoryNext.remove(aliTlvEncodeHistoryNext.size() - 1);

                    //Keep processing each row using recursion until you get to to the bottom of the tree
                    tlvJsonArray.put(
                            recursiveTlvDefinitionBuilder(resultSetParentCheck.getInt(Dictionary.DB_TBL_COL_ID),
                                    iParentIdTemp, aliTlvEncodeHistoryNext));
                }

                //Get Parent Definition
                tlvJsonObj = getRowDefinitionViaRowId(iParentIdTemp);

                tlvJsonObj.put(PacketCableSqlQueryConstants.SUBTYPE_ARRAY, tlvJsonArray);

            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return tlvJsonObj;
}

From source file:com.sbcc.edu.jrollspellchecker.MainWindow.java

public void spellCheck(ArrayList<String> text) {
    //edit this to make it highlight the selected word in the arrayList
    //raise a dialogue box with the word to edit
    index = spellChecker.spellCheck(text);

    if (index <= 0)
        return;//from   w  w  w.j  a v a 2s  .c  o  m
    else {
        for (int i = 0; i <= index; i++)
            text.remove(i);
        spellCheck(text);
    }

}

From source file:com.xpn.xwiki.plugin.chronopolys.FolderManager.java

public ArrayList<Object> getProjectContainerChilds(String uid, XWikiContext context) throws XWikiException {
    ArrayList<Object> containers = this.getProjectContainers(context);
    projectContainerComparator comp = new projectContainerComparator();
    Object obj;// ww  w . jav a2  s . c o  m

    for (int i = 0; i < containers.size(); i++) {
        obj = containers.get(i);
        if (!uid.equals(obj.getProperty("parent").getValue().toString())) {
            containers.remove(i);
            i--;
        }
    }
    Collections.sort(containers, comp);
    return containers;
}

From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java

public void saveSelectedIndex() {
    ArrayList<OSIProjectInfo> loadProjectsList = new ArrayList<OSIProjectInfo>();
    for (OSIProjectInfo pi : projectsListInfo) {
        if (pi.isManaged()) {
            if (!pi.isLoaded()) {
                pi = ProjectAPIWrapper.loadAnalysisInfo(pi);
                loadProjectsList.add(pi);
            }/*from   w  w w  .  j  a  va2  s.c  o  m*/
            pi.setProjectAnalysisInfo(pi.isAnalyzed());
        }
    }

    while (loadProjectsList.size() > 0) {
        for (int i = loadProjectsList.size() - 1; i >= 0; i--) {
            if (loadProjectsList.get(i).isLoaded()) {
                loadProjectsList.get(i).getProjectAnalysisInfo()
                        .setAnalysisStatus(loadProjectsList.get(i).isAnalyzed());
                loadProjectsList.remove(i);
            }
        }
    }
}

From source file:com.compomics.pride_asa_pipeline.core.logic.modification.PTMMapper.java

/**
 * Processes all mods before they are set to the modification profile
 * modification profile. Unknown PTMs are added to the unknown PTMs
 * arraylist./*from   w w  w  . ja  v a 2s  .c om*/
 *
 * @param modificationMap hashmap containing modification names and their
 * fixed/variable status
 * @param unknownPtms the list of unknown PTMS, updated during this method
 * @return the filled up modification profile
 */
public PtmSettings buildTotalModProfile(HashMap<String, Boolean> modificationMap,
        ArrayList<String> unknownPtms) {
    PtmSettings modProfile = new PtmSettings();
    for (String aModificationName : modificationMap.keySet()) {
        if (!addPTMToProfile(modProfile, modificationMap, aModificationName)) {
            factory.convertPridePtm(aModificationName, modProfile, unknownPtms,
                    modificationMap.get(aModificationName));
        }
        //check if the unknowns have an alternative and retry them...
        for (String anUnknownPTM : unknownPtms) {
            String temp = lookupRealModName(anUnknownPTM);
            if (addPTMToProfile(modProfile, modificationMap, temp)) {
                unknownPtms.remove(anUnknownPTM);
            }
            ;
        }
    }
    return modProfile;
}

From source file:com.comcast.oscar.sql.queries.DocsisSqlQuery.java

/**
 * //from w  ww.  j  av  a2  s . co  m
 * @param iRowID
 * @param iParentID
 * @param aliTlvEncodeHistory   
 * @return JSONObject
 * @throws JSONException */
private JSONObject recursiveTlvDefinitionBuilder(Integer iRowID, Integer iParentID,
        ArrayList<Integer> aliTlvEncodeHistory) throws JSONException {

    Statement parentCheckStatement = null, getRowDefinitionStatement = null;

    ResultSet resultSetParentCheck = null, resultSetGetRowDefinition = null;

    aliTlvEncodeHistory.add(getTypeFromRowID(iParentID));

    String sqlQuery;

    JSONObject tlvJsonObj = null;

    // This query will check for child rows that belong to a parent row
    sqlQuery = "SELECT " + "   ID ," + "   TYPE ," + "   TLV_NAME," + "   PARENT_ID " + "FROM "
            + "   DOCSIS_TLV_DEFINITION " + "WHERE " + "   PARENT_ID = '" + iRowID + "'";

    try {

        //Create statement
        parentCheckStatement = sqlConnection.createStatement();

        //Get Result Set of Query
        resultSetParentCheck = parentCheckStatement.executeQuery(sqlQuery);

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

    /* ******************************************************************************************************
     * If resultSet return an empty, this means that the row does not have a child and is not a Major TLV
     * *****************************************************************************************************/

    try {

        if ((SqlConnection.getRowCount(resultSetParentCheck) == 0) && (iParentID != MAJOR_TLV)) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT * FROM " + "   DOCSIS_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            //Create statement to get Rows from ROW ID's
            getRowDefinitionStatement = sqlConnection.createStatement();

            //Get Result Set
            resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery);

            //Advance to next index in result set, this is needed
            resultSetGetRowDefinition.next();

            /*************************************************
             *             Assemble JSON OBJECT
             *************************************************/

            tlvJsonObj = new JSONObject();

            tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(Dictionary.TLV_NAME,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME));
            tlvJsonObj.put(Dictionary.LENGTH_MIN,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN));
            tlvJsonObj.put(Dictionary.LENGTH_MAX,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX));
            tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS));
            tlvJsonObj.put(Dictionary.DATA_TYPE,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE));
            tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false);
            tlvJsonObj.put(Dictionary.BYTE_LENGTH,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH));

            aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(Dictionary.PARENT_TYPE_LIST, aliTlvEncodeHistory);

            if (debug)
                System.out.println(tlvJsonObj.toString());

        } else if (iParentID == MAJOR_TLV) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT * FROM " + "   DOCSIS_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            getRowDefinitionStatement = sqlConnection.createStatement();

            resultSetGetRowDefinition = getRowDefinitionStatement.executeQuery(sqlQuery);

            resultSetGetRowDefinition.next();

            /*************************************************
             *             Assemble JSON OBJECT
             *************************************************/

            tlvJsonObj = new JSONObject();

            tlvJsonObj.put(Dictionary.TYPE, resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TYPE));
            tlvJsonObj.put(Dictionary.TLV_NAME,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_TLV_NAME));
            tlvJsonObj.put(Dictionary.LENGTH_MIN,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MIN));
            tlvJsonObj.put(Dictionary.LENGTH_MAX,
                    resultSetGetRowDefinition.getInt(Dictionary.DB_TBL_COL_LENGTH_MAX));
            tlvJsonObj.put(Dictionary.SUPPORTED_VERSIONS,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_SUPPORTED_VERSIONS));
            tlvJsonObj.put(Dictionary.DATA_TYPE,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_DATA_TYPE));
            tlvJsonObj.put(Dictionary.ARE_SUBTYPES, false);
            tlvJsonObj.put(Dictionary.BYTE_LENGTH,
                    resultSetGetRowDefinition.getString(Dictionary.DB_TBL_COL_BYTE_LENGTH));

            aliTlvEncodeHistory.add(resultSetGetRowDefinition.getInt("TYPE"));
            tlvJsonObj.put(Dictionary.PARENT_TYPE_LIST, aliTlvEncodeHistory);

            if (debug)
                System.out.println(tlvJsonObj.toString());
        }

        if (SqlConnection.getRowCount(resultSetParentCheck) > 0) {

            // This query will check for child rows that belong to a parent row
            sqlQuery = "SELECT " + "   TYPE , " + "   TLV_NAME," + "   PARENT_ID" + " FROM "
                    + "   DOCSIS_TLV_DEFINITION " + "   WHERE ID = '" + iRowID + "'";

            try {

                Integer iParentIdTemp = null;

                JSONArray tlvJsonArray = new JSONArray();

                while (resultSetParentCheck.next()) {

                    iParentIdTemp = resultSetParentCheck.getInt(Dictionary.DB_TBL_COL_PARENT_ID);

                    ArrayList<Integer> aliTlvEncodeHistoryNext = new ArrayList<Integer>();

                    aliTlvEncodeHistoryNext.addAll(aliTlvEncodeHistory);

                    if (debug)
                        System.out.println("aliTlvEncodeHistoryNext: " + aliTlvEncodeHistoryNext);

                    aliTlvEncodeHistoryNext.remove(aliTlvEncodeHistoryNext.size() - 1);

                    //Keep processing each row using recursion until you get to to the bottom of the tree
                    tlvJsonArray.put(
                            recursiveTlvDefinitionBuilder(resultSetParentCheck.getInt(Dictionary.DB_TBL_COL_ID),
                                    iParentIdTemp, aliTlvEncodeHistoryNext));
                }

                //Get Parent Definition
                tlvJsonObj = getRowDefinitionViaRowId(iParentIdTemp);

                tlvJsonObj.put(Dictionary.SUBTYPE_ARRAY, tlvJsonArray);

            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return tlvJsonObj;
}

From source file:it.infn.ct.GridEngine.Data.JSagaDataManagement.java

public URI upload(java.net.URL source, String relativeLocation, String commonName, String tcpAddress,
        int GridInteractionId, String userDescription) throws DataError {
    ArrayList<URI> srms = null;
    URI uriSrm = null;//from w w  w.  j  a  v  a2  s .  co  m

    try {
        srms = new java.util.ArrayList<URI>(bdii.querySRMURIs(sessionM.getUserVO()));
    } catch (Exception e) {
        log.error(e);
        throw new DataError(e.getMessage());
    }
    Random rdm = new Random();
    while (srms.size() > 0) {
        int idxSrm = rdm.nextInt(srms.size());
        try {
            uriSrm = new URI(srms.get(idxSrm).toString().concat(relativeLocation));
            copyFile(URLFactory.createURL(source.toString()), URLFactory.createURL(uriSrm.toString()),
                    commonName, tcpAddress, GridInteractionId, userDescription);
            break;
        } catch (BadParameterException e) {
            log.error(e);
            srms.remove(idxSrm);
        } catch (NoSuccessException e) {
            log.error(e);
            srms.remove(idxSrm);
        } catch (URISyntaxException e) {
            log.error(e);
            srms.remove(idxSrm);
        }

    }
    if (srms.size() == 0)
        throw new DataError("All available storage fails");

    return uriSrm;

}

From source file:br.unicamp.cst.learning.QLearning.java

/**
* Returns the maximum Q value for sl. /*from w  ww . j  ava 2s . c  o  m*/
* @param sl
* @return Q Value
*/
public double maxQsl(String sl) {
    double maxQinSl = 0;
    String maxAl = "";
    double val = 0;
    if (this.Q.get(sl) != null) {
        HashMap<String, Double> tempSl = this.Q.get(sl);
        ArrayList<String> tempA = new ArrayList<String>();
        tempA.addAll(this.actionsList);

        // Finds out the action with maximum value for sl
        Iterator<Entry<String, Double>> it = tempSl.entrySet().iterator();

        while (it.hasNext()) {
            Entry<String, Double> pairs = it.next();
            val = pairs.getValue();
            tempA.remove(pairs.getKey());
            if (val > maxQinSl) {
                maxAl = pairs.getKey();
                maxQinSl = val;
            }
        }
        if (!tempA.isEmpty() && maxQinSl < 0) {
            maxQinSl = 0;
        } //Assigning 0 to unknown state/action pair
    }
    return maxQinSl;
}

From source file:com.l2jfrozen.gameserver.geo.pathfinding.PathFinding.java

public final Node[] searchByClosest(final Node start, final Node end) {
    // Note: This is the version for cell-based calculation, harder
    // on cpu than from block-based pathnode files. However produces better routes.

    // Always continues checking from the closest to target non-blocked
    // node from to_visit list. There's extra length in path if needed
    // to go backwards/sideways but when moving generally forwards, this is extra fast
    // and accurate. And can reach insane distances (try it with 8000 nodes..).
    // Minimum required node count would be around 300-400.
    // Generally returns a bit (only a bit) more intelligent looking routes than
    // the basic version. Not a true distance image (which would increase CPU
    // load) level of intelligence though.

    // List of Visited Nodes
    final CellNodeMap known = CellNodeMap.newInstance();
    // List of Nodes to Visit
    final ArrayList<Node> to_visit = L2Collections.newArrayList();
    to_visit.add(start);//  www.  j  av  a2 s.c o m
    known.add(start);
    try {
        final int targetx = end.getNodeX();
        final int targety = end.getNodeY();
        final int targetz = end.getZ();
        int dx, dy, dz;
        boolean added;
        int i = 0;
        while (i < 3500) {
            if (to_visit.isEmpty()) {
                // No Path found
                return null;
            }

            final Node node = to_visit.remove(0);

            i++;

            node.attachNeighbors();
            if (node.equals(end)) {
                // path found! note that node z coordinate is updated only in attach
                // to improve performance (alternative: much more checks)
                // LOGGER.info("path found, i:"+i);
                return constructPath(node);
            }

            final Node[] neighbors = node.getNeighbors();
            if (neighbors == null)
                continue;
            for (final Node n : neighbors) {
                if (!known.contains(n)) {
                    added = false;
                    n.setParent(node);
                    dx = targetx - n.getNodeX();
                    dy = targety - n.getNodeY();
                    dz = targetz - n.getZ();
                    n.setCost(dx * dx + dy * dy + dz / 2 * dz/* +n.getCost() */);
                    for (int index = 0; index < to_visit.size(); index++) {
                        // supposed to find it quite early..
                        if (to_visit.get(index).getCost() > n.getCost()) {
                            to_visit.add(index, n);
                            added = true;
                            break;
                        }
                    }
                    if (!added)
                        to_visit.add(n);
                    known.add(n);
                }
            }
        }
        // No Path found
        // LOGGER.info("no path found");
        return null;
    } finally {
        CellNodeMap.recycle(known);
        L2Collections.recycle(to_visit);
    }
}

From source file:extractcode.TraversalFiles.java

public static void fileList(File inputFile, int node, ArrayList<String> path, String folderPath) {
    node++;/*w w w  . j a v  a 2 s . c o m*/
    File[] files = inputFile.listFiles();
    if (!inputFile.exists()) {
        System.out.println("File doesn't exist!");
    } else if (inputFile.isDirectory()) {
        path.add(inputFile.getName());

        for (File f : files) {
            for (int i = 0; i < node - 1; i++) {
                System.out.print(" ");
            }
            System.out.print("|-" + f.getPath());

            String ext = FilenameUtils.getExtension(f.getName());
            if (ext.equals("java")) {
                try {
                    System.out.println(" => extracted");

                    //Get extracted file location and add it to output file name,
                    //in order to avoid files in different folder 
                    //have the same name.
                    String fileLocation = "";
                    for (String tmpPath : path) {
                        fileLocation += "-" + tmpPath;
                    }

                    String outFilePath = folderPath + "/" + f.getName() + fileLocation + "-allcode.txt";

                    //create output file
                    File outputFile = new File(outFilePath);
                    if (outputFile.createNewFile()) {
                        System.out.println("Create successful: " + outputFile.getName());
                    }

                    //extract comments
                    ExtractCode.extractCode(f, outputFile);
                } catch (IOException ex) {
                    Logger.getLogger(TraversalFiles.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                System.out.println();
            }
            fileList(f, node, path, folderPath);
        }
        path.remove(node - 1);
    }
}