Example usage for java.util List indexOf

List of usage examples for java.util List indexOf

Introduction

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

Prototype

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:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java

private void fillSizes() {
    final String lastSelectedSize = this.lastSelectedSize;
    sizeSpinner.removeAllItems();//from w w  w.ja  v a2 s .  c o  m
    if (this.assetRoot.getCanonicalPath() == null) {
        return;
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    assetRoot = new File(assetRoot, (String) categorySpinner.getSelectedItem());
    assetRoot = new File(assetRoot, DEFAULT_RESOLUTION);
    final String assetName = (String) assetSpinner.getSelectedItem();
    final FilenameFilter drawableFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            if (!FilenameUtils.isExtension(s, "png")) {
                return false;
            }
            String filename = FilenameUtils.removeExtension(s);
            return filename.startsWith("ic_" + assetName + "_");
        }
    };
    File[] assets = assetRoot.listFiles(drawableFileNameFiler);
    Set<String> sizes = new HashSet<String>();
    for (File asset : assets) {
        String drawableName = FilenameUtils.removeExtension(asset.getName());
        String[] numbers = drawableName.replaceAll("[^-?0-9]+", " ").trim().split(" ");
        drawableName = numbers[numbers.length - 1].trim() + "dp";
        sizes.add(drawableName);
    }
    List<String> list = new ArrayList<String>();
    list.addAll(sizes);
    Collections.sort(list);
    for (String size : list) {
        sizeSpinner.addItem(size);
    }
    if (list.contains(lastSelectedSize)) {
        sizeSpinner.setSelectedIndex(list.indexOf(lastSelectedSize));
    }
}

From source file:gov.nih.nci.caarray.plugins.genepix.GprHandler.java

private void validateProbeNames(final DelimitedFileReader delimitedFileReader, final ArrayDesign arrayDesign,
        final FileValidationResult fileValidationResult) throws IOException {
    final ProbeNamesValidator probeNamesValidator = new ProbeNamesValidator(this.arrayDao, arrayDesign);
    final List<String> probeNamesBatch = new ArrayList<String>(BATCH_SIZE);
    int probeCounter = 0;
    final List<String> headers = getColumnHeaders(delimitedFileReader); // resets reader to start of data
    final int idIndex = headers.indexOf(ID_HEADER);
    while (delimitedFileReader.hasNextLine()) {
        final List<String> values = delimitedFileReader.nextLine();
        final String probeName = values.get(idIndex);
        probeNamesBatch.add(probeName);/*from ww  w  . j  a v  a  2 s.c om*/
        probeCounter++;
        if (0 == probeCounter % BATCH_SIZE) {
            probeNamesValidator.validateProbeNames(fileValidationResult, probeNamesBatch);
            probeNamesBatch.clear();
        }
    }
    if (!probeNamesBatch.isEmpty()) {
        probeNamesValidator.validateProbeNames(fileValidationResult, probeNamesBatch);
    }
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java

private void fillColors() {
    final String lastSelectedColor = this.lastSelectedColor;
    colorSpinner.removeAllItems();//  w  w  w  . j a  v a2 s .  com
    if (this.assetRoot.getCanonicalPath() == null) {
        return;
    }
    File assetRoot = new File(this.assetRoot.getCanonicalPath());
    assetRoot = new File(assetRoot, (String) categorySpinner.getSelectedItem());
    assetRoot = new File(assetRoot, DEFAULT_RESOLUTION);
    final String assetName = (String) assetSpinner.getSelectedItem();
    final String assetSize = (String) sizeSpinner.getSelectedItem();
    final FilenameFilter drawableFileNameFiler = new FilenameFilter() {
        @Override
        public boolean accept(File file, String s) {
            if (!FilenameUtils.isExtension(s, "png")) {
                return false;
            }
            String filename = FilenameUtils.removeExtension(s);
            return filename.startsWith("ic_" + assetName + "_") && filename.endsWith("_" + assetSize);
        }
    };
    File[] assets = assetRoot.listFiles(drawableFileNameFiler);
    Set<String> colors = new HashSet<String>();
    for (File asset : assets) {
        String drawableName = FilenameUtils.removeExtension(asset.getName());
        String[] color = drawableName.split("_");
        drawableName = color[color.length - 2].trim();
        colors.add(drawableName);
    }
    List<String> list = new ArrayList<String>();
    list.addAll(colors);
    Collections.sort(list);
    for (String size : list) {
        colorSpinner.addItem(size);
    }
    if (list.contains(lastSelectedColor)) {
        colorSpinner.setSelectedIndex(list.indexOf(lastSelectedColor));
    }
}

From source file:org.zlogic.vogon.web.controller.AccountsController.java

/**
 * Updates account list// ww w. j  a v  a 2s. c o m
 *
 * @param accounts the new updated accounts list
 * @param user the authenticated user
 * @return the accounts list from database after update
 */
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public @ResponseBody Collection<FinanceAccount> updateAccounts(@RequestBody Collection<FinanceAccount> accounts,
        @AuthenticationPrincipal VogonSecurityUser user) {
    List<FinanceAccount> existingAccounts = new ArrayList<>(accountRepository.findByOwner(user.getUser()));
    LinkedList<FinanceAccount> removedAccounts = new LinkedList<>(existingAccounts);
    //Merge with database
    for (FinanceAccount newAccount : accounts) {
        if (newAccount.getId() == null || !existingAccounts.contains(newAccount)) {
            FinanceAccount createdAccount = new FinanceAccount(user.getUser(), newAccount);
            accountRepository.save(createdAccount);
        } else {
            FinanceAccount existingAccount = existingAccounts.get(existingAccounts.indexOf(newAccount));
            existingAccount.merge(newAccount);
            removedAccounts.remove(newAccount);
        }
    }
    //Delete removed accounts
    for (FinanceAccount removedAccount : removedAccounts) {
        accountRepository.delete(removedAccount);
        //Delete all related transaction components
        for (FinanceTransaction transaction : transactionRepository.findByOwner(user.getUser())) {
            boolean save = false;
            for (TransactionComponent component : transaction.getComponentsForAccount(removedAccount)) {
                transaction.removeComponent(component);
                save = true;
            }
            if (save)
                transactionRepository.save(transaction);
        }
    }
    accountRepository.flush();
    transactionRepository.flush();
    return accountRepository.findByOwner(user.getUser());
}

From source file:fr.mcc.ginco.services.AlignmentServiceImpl.java

public void saveExternalThesauruses(List<Alignment> alignments) {
    List<ExternalThesaurus> externalThesaurusesToSave = new ArrayList<ExternalThesaurus>();

    for (Alignment alignment : alignments) {
        ExternalThesaurus externalThesaurus = alignment.getExternalTargetThesaurus();
        if (externalThesaurus != null) {
            if (!externalThesaurusesToSave.contains(externalThesaurus)) {
                externalThesaurusesToSave.add(externalThesaurus);
            } else {
                ExternalThesaurus existingExternalThes = externalThesaurusesToSave
                        .get(externalThesaurusesToSave.indexOf(externalThesaurus));
                alignment.setExternalTargetThesaurus(existingExternalThes);
            }/*from w ww  .  j a va 2  s  . co  m*/
        }
    }
    for (ExternalThesaurus extThesaurus : externalThesaurusesToSave) {
        externalThesaurusDAO.update(extThesaurus);
    }
}

From source file:com.boxedfolder.carrot.service.impl.AnalyticsServiceImpl.java

@Override
public List<AnalyticsTransfer> appsTriggered(DateTime from, DateTime to) {
    List<AnalyticsTransfer> output = new ArrayList<>();
    List<AnalyticsLog> logs = findAll(from, to);
    for (AnalyticsLog log : logs) {
        if (log.getApp() == null) {
            break;
        }//from w  ww .j a  v  a2  s . c om
        AnalyticsTransfer transfer = new AnalyticsTransfer();
        transfer.setId(log.getApp().getId());
        transfer.setName(log.getApp().getName());
        if (!output.contains(transfer)) {
            output.add(transfer);
        } else {
            transfer = output.get(output.indexOf(transfer));
        }
        Integer value = transfer.getCount();
        value++;
        transfer.setCount(value);
    }

    return output;
}

From source file:eu.mihosoft.vrl.v3d.Edge.java

/**
 * Returns a list of all boundary paths.
 *
 * @param boundaryEdges boundary edges (all paths must be closed)
 * @return/*  ww  w. ja va  2s .  c om*/
 */
private static List<Polygon> boundaryPaths(List<Edge> boundaryEdges) {
    List<Polygon> result = new ArrayList<>();

    boolean[] used = new boolean[boundaryEdges.size()];
    int startIndex = 0;
    Edge edge = boundaryEdges.get(startIndex);
    used[startIndex] = true;

    startIndex = 1;

    while (startIndex > 0) {
        List<Vector3d> boundaryPath = new ArrayList<>();

        while (true) {
            Edge finalEdge = edge;

            boundaryPath.add(finalEdge.p1.pos);

            System.out.print("edge: " + edge.p2.pos);

            Optional<Edge> nextEdgeResult = boundaryEdges.stream().filter(e -> finalEdge.p2.equals(e.p1))
                    .findFirst();

            if (!nextEdgeResult.isPresent()) {
                System.out.println("ERROR: unclosed path:" + " no edge found with " + finalEdge.p2);
                break;
            }

            Edge nextEdge = nextEdgeResult.get();

            int nextEdgeIndex = boundaryEdges.indexOf(nextEdge);

            if (used[nextEdgeIndex]) {
                break;
            }

            edge = nextEdge;
            System.out.println("-> edge: " + edge.p1.pos);
            used[nextEdgeIndex] = true;
        }

        if (boundaryPath.size() < 3) {
            break;
        }

        result.add(Polygon.fromPoints(boundaryPath));
        startIndex = nextUnused(used);

        if (startIndex > 0) {
            edge = boundaryEdges.get(startIndex);
            used[startIndex] = true;
        }

    }

    System.out.println("paths: " + result.size());

    return result;
}

From source file:info.magnolia.ui.vaadin.integration.jcr.AbstractJcrNodeAdapter.java

/**
 * Sorts the child nodes of {@code node} according to the passed list of identifiers {@code sortedIdentifiers}.
 *//*ww  w.ja  v  a 2  s. co m*/
private void sortChildren(Node node, List<String> sortedIdentifiers) throws RepositoryException {

    List<String> unsortedIdentifiers = new ArrayList<>();

    for (NodeIterator it = node.getNodes(); it.hasNext();) {
        unsortedIdentifiers.add(it.nextNode().getIdentifier());
    }

    for (int pos = 0; pos < sortedIdentifiers.size(); pos++) {
        String current = sortedIdentifiers.get(pos);
        int nodePos = unsortedIdentifiers.indexOf(current);

        if (nodePos != -1 || nodePos != pos) {
            Node nodeToMove = node.getSession().getNodeByIdentifier(current);
            Node target = node.getSession().getNodeByIdentifier(unsortedIdentifiers.get(pos));

            NodeUtil.moveNodeBefore(nodeToMove, target);
            String movedId = unsortedIdentifiers.remove(nodePos);
            unsortedIdentifiers.add(pos, movedId);
        }
    }
}

From source file:com.splicemachine.mrio.api.core.SMSQLUtil.java

public int[] getKeyDecodingMap(int[] keyColumnEncodingOrder, List<String> columnNames,
        List<NameType> nameTypes) {
    int[] keyDecodingMap = IntArrays.count(keyColumnEncodingOrder.length);
    for (int i = 0; i < keyColumnEncodingOrder.length; i++) {
        keyDecodingMap[i] = columnNames.indexOf(nameTypes.get(keyColumnEncodingOrder[i]).name);
    }/* ww  w. j a v  a  2 s.c  om*/
    if (LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG, "getKeyDecodingMap returns=%s", Arrays.toString(keyDecodingMap));
    return keyDecodingMap;
}

From source file:net.rim.ejde.internal.ui.preferences.PreprocessDirectiveUI.java

protected int getIndexof(PreprocessorTag tag) {
    List<PreprocessorTag> tags = getInput();
    return tags.indexOf(tag);
}