Example usage for java.util ArrayList indexOf

List of usage examples for java.util ArrayList indexOf

Introduction

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

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:xmlconverter.controller.logic.GetFileCount.java

/**
 * Creates Document so that XML file can be filled with information. Here
 * where it all begins. Those if statements will first check if files[] is
 * not empty then loop trough files[] and get path of every directory. In
 * the process it passes list of child files/directories paths ("depending
 * on the filter that is used") of a parent file to method called
 * writeFile(). Before that happens it checks if here are any duplicate
 * files that have been handed to the method(It should not happen). After
 * this operation is done it call itself again. Till every folder has been
 * visited.//from w  w  w .j a  va 2 s.c o m
 *
 * @param site
 * @throws javax.xml.transform.TransformerException
 * @throws javax.xml.parsers.ParserConfigurationException
 * @throws org.xml.sax.SAXException
 * @throws java.io.IOException
 */
public void writeFile(Site site)
        throws TransformerException, DOMException, ParserConfigurationException, IOException, SAXException {
    ArrayList<String> detectionList = site.getSiteAsArrayList();
    File startPath = bean.getEnvBean().getSiteDir();

    Collection<File> startFiles = FileUtils.listFilesAndDirs(startPath, FalseFileFilter.FALSE,
            DirectoryFileFilter.DIRECTORY);
    File[] startFilesSorted = startFiles.toArray(new File[startFiles.size()]);
    Arrays.sort(startFilesSorted);

    for (File path : startFilesSorted) {
        //Start of the file
        CreateGraphicsNode createGraphicsNode = new CreateGraphicsNode();

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        Document doc = docBuilder.newDocument();

        Element root = doc.createElement("GraphicsContainerNode");
        Element startMelder = doc.createElement("GraphicsNode");
        Element endMelder = doc.createElement("GraphicsNode");
        doc.appendChild(root);

        //This method also does update. It is actually enables other method to 
        //do update if flag is set to 1
        File[] pathFiles = path.listFiles(directoryFilter);
        Arrays.sort(pathFiles);

        for (File desc : pathFiles) {
            root.appendChild(createGraphicsNode.getGraphicsNode(doc, desc, home));
        }

        if (path.getName().contains("Automatische Gruppe") || path.getName().contains("Manuelle Gruppe")) {
            ArrayList<String> detectionObjects = new ArrayList<>();
            String pattern = path.getName().trim();
            int index = detectionList.indexOf(pattern);

            while (detectionList.get(index + 1).contains("Manual")
                    || detectionList.get(index + 1).contains("Automatic")) {
                detectionObjects.add(detectionList.get(index + 1));
                detectionObjects.add(detectionList.get(index + 2));
                index += 2;
            }
            //This is more efficient way to retrieve information! o guess that helped. 
            if (!detectionObjects.isEmpty()) {
                int end = path.getName().indexOf("_");
                String mg = path.getName().substring(0, end);
                String start;
                String ending;
                if ((maNumber + 1) >= 10) {
                    start = (maNumber + 1) + "/11*" + mg + "             ..";
                    ending = (maNumber + 1) + "/11*" + mg + "             00";
                } else {
                    start = "0" + (maNumber + 1) + "/11*" + mg + "             ..";
                    ending = "0" + (maNumber + 1) + "/11*" + mg + "             00";
                }
                startMelder.setAttribute("id", start);
                startMelder.setAttribute("name", start);
                root.appendChild(startMelder);
                for (int i = 0; i < detectionObjects.size(); i += 2) {
                    root.appendChild(createGraphicsNode.getMelderGruppeNode(doc, detectionObjects.get(i),
                            path.getName(), maNumber, detectionObjects.get(i + 1)));
                }
                endMelder.setAttribute("id", ending);
                endMelder.setAttribute("name", ending);
                root.appendChild(endMelder);
            }
        }

        String formatedFileName = path.getAbsolutePath().replace("", "ae").replace("", "ss")
                .replace("", "ue").replace("", "oe");
        String formatedName = path.getName().replace("", "ae").replace("", "ss").replace("", "ue")
                .replace("", "oe");

        File toCheck;
        if (path.getAbsolutePath().endsWith(".xml")) {
            toCheck = path;
        } else {
            toCheck = new File(formatedFileName + slash + formatedName + ".xml");
        }

        //End Of the File
        //Flag 0 - Default 1 - Override 2 - Update
        if (flag != 2) {
            writeDocument(doc, path);
        }
        if (flag == 2) {
            if (toCheck.exists()) {
                //If it existas that measns it could need some updating
                updateSite(doc, toCheck);
            } else {
                //if not then file can be created and doesnt need to be updated.
                writeDocument(doc, path);
            }
        }
    }
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

private void ensureUniqueAndIndexingBlocking(String id, JsonObject data, Boolean isNew,
        AsyncResultHandler<String> resultHandler) {
    Async.waterfall().<String>task(t -> {
        RBatch batch = redissonOther.createBatch();
        ArrayList<String> pList = new ArrayList();
        try {/*from w  w w. ja  v a  2 s .co m*/
            prepareEnsureUnique(id, data, batch, pList, null);
        } catch (RepositoryException ex) {
            t.handle(Future.failedFuture(ex));
            return;
        }
        if (pList.isEmpty()) {
            t.handle(Future.succeededFuture());
            return;
        }
        batch.executeAsync().addListener(future -> {
            if (future.isSuccess() && future.get() != null) {
                List<String> result = (List<String>) future.get();
                Stream<String> filter = pList.stream().filter(
                        p -> result.get(pList.indexOf(p)) != null && !result.get(pList.indexOf(p)).equals(id));//uniques are ensured by using putIfAbsent and all results should be null or itself to indicate no violation.
                Object[] filterArray = filter.toArray();
                if (filterArray.length != 0) {
                    t.handle(Future.succeededFuture(
                            new JsonObject().put("uniqueViolation", Json.encode(filterArray)).encode()));
                    //now undo these things.
                    ArrayList<String> undoList = pList.stream()
                            .filter(p -> result.get(pList.indexOf(p)) == null
                                    || result.get(pList.indexOf(p)).equals(id))
                            .collect(Collectors.toCollection(ArrayList::new));
                    Async.<Void>waterfall().<Void>task(task -> {
                        RBatch b = redissonOther.createBatch();
                        try {
                            prepareUndoUnique(id, data, b, undoList, null);
                        } catch (RepositoryException ex) {
                            task.handle(Future.failedFuture(ex));
                        }
                        b.executeAsync().addListener(fu -> {
                            task.handle(fu.isSuccess() ? Future.succeededFuture((Void) fu.get())
                                    : Future.failedFuture(fu.cause()));
                        });
                    }).run(run -> {
                        logger.debug("Parallel undo indexing [id: " + id + "] "
                                + (run.succeeded() ? "successed." : "failed."));
                    });
                } else {
                    t.handle(Future.succeededFuture());
                }
            } else {
                t.handle(Future.failedFuture(!future.isSuccess() ? future.cause().fillInStackTrace()
                        : new RepositoryException("No unique check result returned")));
            }
        });
    }).<String>task((violations, t) -> {
        if (violations != null) {
            t.handle(Future.failedFuture(violations));
            return;
        } else {
            t.handle(Future.succeededFuture());
        }
        //parallel indexing
        Async.<Void>waterfall().<T>task(task -> {
            if (!isNew) {
                fetch(id, Boolean.TRUE, task);
            } else {
                task.handle(Future.succeededFuture(null));
            }
        }).<Void>task((r, task) -> {
            reIndex(id, r, data, isNew, ri -> {
                task.handle(
                        ri.succeeded() ? Future.succeededFuture(ri.result()) : Future.failedFuture(ri.cause()));
            });
        }).run(run -> {
            logger.debug("Parallel Indexing [id: " + id + "] " + (run.succeeded() ? "successed." : "failed."),
                    run.cause());
        });
    }).run(resultHandler);

}

From source file:ac.robinson.mediaphone.MediaPhoneActivity.java

/**
 * Switch from one frame to another. Will call onBackPressed() on the calling activity
 * /*w  w w.java  2  s. c o  m*/
 * @param currentFrameId
 * @param buttonId
 * @param idExtra
 * @param showOptionsMenu
 * @param targetActivityClass
 * @return
 */
protected boolean switchFrames(String currentFrameId, int buttonId, int idExtra, boolean showOptionsMenu,
        Class<?> targetActivityClass) {
    if (currentFrameId == null) {
        return false;
    }
    ContentResolver contentResolver = getContentResolver();
    FrameItem currentFrame = FramesManager.findFrameByInternalId(contentResolver, currentFrameId);
    ArrayList<String> narrativeFrameIds = FramesManager.findFrameIdsByParentId(contentResolver,
            currentFrame.getParentId());
    int currentPosition = narrativeFrameIds.indexOf(currentFrameId);
    int newFramePosition = -1;
    int inAnimation = R.anim.slide_in_from_right;
    int outAnimation = R.anim.slide_out_to_left;
    switch (buttonId) {
    case R.id.menu_previous_frame:
        if (currentPosition > 0) {
            newFramePosition = currentPosition - 1;
        }
        inAnimation = R.anim.slide_in_from_left;
        outAnimation = R.anim.slide_out_to_right;
        break;
    case R.id.menu_next_frame:
        if (currentPosition < narrativeFrameIds.size() - 1) {
            newFramePosition = currentPosition + 1;
        }
        break;
    }
    if (newFramePosition >= 0) {
        final Intent nextPreviousFrameIntent = new Intent(MediaPhoneActivity.this, targetActivityClass);
        nextPreviousFrameIntent.putExtra(getString(idExtra), narrativeFrameIds.get(newFramePosition));

        // this allows us to prevent showing first activity launch hints repeatedly
        nextPreviousFrameIntent.putExtra(getString(R.string.extra_switched_frames), true);

        // for API 11 and above, buttons are in the action bar, so this is unnecessary
        if (showOptionsMenu && Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            nextPreviousFrameIntent.putExtra(getString(R.string.extra_show_options_menu), true);
        }

        startActivity(nextPreviousFrameIntent); // no result so that the original can exit (TODO: will it?)
        closeOptionsMenu(); // so onBackPressed doesn't just do this
        onBackPressed();
        overridePendingTransition(inAnimation, outAnimation);
        return true;
    } else {
        UIUtilities.showToast(MediaPhoneActivity.this, R.string.next_previous_no_more_frames);
        return false;
    }
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return map of the nodes./*w  w  w.ja v  a  2s. c  o m*/
 * dict<original_network_id::original_node_id, federated_node_id>
 */
protected Map<String, String> getNwNodesFed() {
    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(ORIGINAL_NETWORK);
    HashMap<String, ArrayList<String>> nodeTable = conversionTable().getNode();

    Map<String, String> nwcNodes = new HashMap<>();
    for (String orgNode : nodeTable.keySet()) {
        String[] nwcId = orgNode.split("::"); // nwcId::nodeId
        if (nwcIds.indexOf(nwcId[0]) < 0) {
            continue;
        }
        ArrayList<String> fedNodes = nodeTable.get(orgNode);
        String[] fedNode = fedNodes.get(0).split("::"); // nwcId::nodeId
        nwcNodes.put(orgNode, fedNode[1]);
    }
    return nwcNodes;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of flows. dict<original_network_id::original_flow_id, federated_flow_id>
 *//* w  w w. j a  va  2 s. c o m*/
protected Map<String, String> getNwFlowsFed() {
    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(ORIGINAL_NETWORK);
    HashMap<String, ArrayList<String>> flowTable = conversionTable().getFlow();

    Map<String, String> nwcFlows = new HashMap<>();
    for (String orgFlow : flowTable.keySet()) {
        String[] nwcId = orgFlow.split("::"); // nwcId::flowId
        if (nwcIds.indexOf(nwcId[0]) < 0) {
            continue;
        }
        ArrayList<String> fedFlows = flowTable.get(orgFlow);
        String[] fedFlow = fedFlows.get(0).split("::"); // nwcId::flowId
        nwcFlows.put(orgFlow, fedFlow[1]);
    }
    return nwcFlows;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of links. dict<original_network_id::original_link_id, federated_link_id>
 *///from w w w.  ja  va2s.co  m
protected Map<String, String> getNwLinksFed() {
    logger.debug("");

    ArrayList<String> nwcIds = conversionTable().getConnectionList(ORIGINAL_NETWORK);
    HashMap<String, ArrayList<String>> linkTable = conversionTable().getLink();

    Map<String, String> nwcLinks = new HashMap<>();
    for (String orgLink : linkTable.keySet()) {
        String[] nwcId = orgLink.split("::"); // nwcId::linkId
        if (nwcIds.indexOf(nwcId[0]) < 0) {
            continue;
        }
        ArrayList<String> fedLinks = linkTable.get(orgLink);
        String[] fedLink = fedLinks.get(0).split("::"); // nwcId::linkId
        nwcLinks.put(orgLink, fedLink[1]);
    }
    return nwcLinks;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of nodes.//from  www.  j a  v  a2  s  .c  o m
 * dict<federated_node_id, (original_network_id, original_node_id)>
 */
protected Map<String, ArrayList<String>> getNwNodesOrigin() {

    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(FEDERATED_NETWORK);
    HashMap<String, ArrayList<String>> nodeTable = conversionTable().getNode();

    Map<String, ArrayList<String>> nwcNodes = new HashMap<>();
    for (String key : nodeTable.keySet()) {
        String[] fedNode = key.split("::"); // nwcId::nodeId
        if (nwcIds.indexOf(fedNode[0]) < 0) {
            continue;
        }
        ArrayList<String> orgNodes = nodeTable.get(key);
        String[] orgNode = orgNodes.get(0).split("::"); // nwcId::nodeId
        nwcNodes.put(fedNode[1], new ArrayList<>(Arrays.asList(orgNode)));
    }
    return nwcNodes;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of links. dict<federated_link_id, list[(original_network_id, original_link_id)]>
 */// w w w  .  jav  a 2 s  .  co  m
protected Map<String, ArrayList<String>> getNwLinksOrigin() {

    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(FEDERATED_NETWORK);
    HashMap<String, ArrayList<String>> linkTable = conversionTable().getLink();

    Map<String, ArrayList<String>> nwcLinks = new HashMap<>();
    for (String key : linkTable.keySet()) {
        String[] fedLink = key.split("::"); // nwcId::linkId
        if (nwcIds.indexOf(fedLink[0]) < 0) {
            continue;
        }
        ArrayList<String> orgLinks = linkTable.get(key);
        String[] orgLink = orgLinks.get(0).split("::"); // nwcId::linkId
        nwcLinks.put(fedLink[1], new ArrayList<>(Arrays.asList(orgLink)));
    }
    return nwcLinks;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of Flows. dict<federated_flow_id, [(original_network_id, original_flow_id)]>
 *//*from   w w  w  .j  ava  2s . c om*/
protected Map<String, ArrayList<Object>> getNwFlowsOrigin() {
    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(FEDERATED_NETWORK);
    HashMap<String, ArrayList<String>> flowTable = conversionTable().getFlow();

    Map<String, ArrayList<Object>> nwcFlows = new HashMap<>();
    for (String key : flowTable.keySet()) {
        String[] fedFlow = key.split("::"); // nwcId::flowId
        if (nwcIds.indexOf(fedFlow[0]) < 0) {
            continue;
        }
        ArrayList<String> orgFlows = flowTable.get(key);
        ArrayList<Object> orgFlowArray = new ArrayList<>();
        for (String orgFlowStr : orgFlows) {
            String[] orgFlow = orgFlowStr.split("::"); // nwcId::flowId
            orgFlowArray.add(new ArrayList<>(Arrays.asList(orgFlow)));
        }
        nwcFlows.put(fedFlow[1], orgFlowArray);
    }
    return nwcFlows;
}

From source file:org.o3project.odenos.component.federator.Federator.java

/**
 *
 * @return Map of ports.//ww w.  ja v  a  2 s  .  c  o m
 * dict<federated_node_id::federated_port_id, (org_network_id, org_node_id, org_port_id)>
 */
protected Map<String, ArrayList<String>> getNwPortsOrigin() {

    logger.debug("");
    ArrayList<String> nwcIds = conversionTable().getConnectionList(FEDERATED_NETWORK);
    HashMap<String, ArrayList<String>> portTable = conversionTable().getPort();

    Map<String, ArrayList<String>> nwcPorts = new HashMap<>();
    for (String key : portTable.keySet()) {
        String[] fedPort = key.split("::"); // nwcId::nodeId::portId
        if (nwcIds.indexOf(fedPort[0]) < 0) {
            continue;
        }
        ArrayList<String> orgPorts = portTable.get(key);
        String[] orgPort = orgPorts.get(0).split("::"); // nwcId::nodeId::portId
        nwcPorts.put(fedPort[1] + "::" + fedPort[2], new ArrayList<>(Arrays.asList(orgPort)));
    }
    return nwcPorts;
}