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:com.moviejukebox.tools.OverrideTools.java

/**
 * Check the priority of a property to set.
 *
 * @param property the property to test//from www .j a va2s  .  com
 * @param actualSource the actual source
 * @param newSource the new source
 * @return true, if new source has higher property than actual source, else false
 */
private static boolean hasHigherPriority(final OverrideFlag overrideFlag, final String actualSource,
        final String newSource, boolean isTV) {
    // check sources
    if (StringTools.isNotValidString(newSource)) {
        // new source is not valid
        // -> actual source has higher priority
        return Boolean.FALSE;
    } else if (StringTools.isNotValidString(actualSource)) {
        // actual source is not valid
        // -> new source has higher priority
        return Boolean.TRUE;
    } else if (actualSource.equalsIgnoreCase(newSource)) {
        // same source may override itself
        return Boolean.TRUE;
    }

    // both sources are valid so get priorities
    List<String> priorities;
    if (isTV) {
        priorities = TV_PRIORITIES_MAP.get(overrideFlag);
    } else {
        priorities = MOVIE_PRIORITIES_MAP.get(overrideFlag);
    }

    // get and check new priority
    int newPrio = priorities.indexOf(newSource.toUpperCase());
    if (newPrio == -1) {
        // priority for new source not found
        // -> actual source has higher priority
        return Boolean.FALSE;
    }

    // check actual priority
    int actualPrio = priorities.indexOf(actualSource.toUpperCase());
    if ((actualPrio == -1) || (newPrio <= actualPrio)) {
        // -> new source has higher priority
        return Boolean.TRUE;
    }

    // -> actual source has higher priority
    return Boolean.FALSE;
}

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

public static List<Polygon> toPolygons(List<Edge> boundaryEdges, Plane plane) {

    List<Vector3d> boundaryPath = new ArrayList<>();

    boolean[] used = new boolean[boundaryEdges.size()];
    Edge edge = boundaryEdges.get(0);/*from  w  ww. jav a 2s.  co m*/
    used[0] = true;
    while (true) {
        Edge finalEdge = edge;

        boundaryPath.add(finalEdge.p1.pos);

        int nextEdgeIndex = boundaryEdges
                .indexOf(boundaryEdges.stream().filter(e -> finalEdge.p2.equals(e.p1)).findFirst().get());

        if (used[nextEdgeIndex]) {
            //                System.out.println("nexIndex: " + nextEdgeIndex);
            break;
        }
        //            System.out.print("edge: " + edge.p2.pos);
        edge = boundaryEdges.get(nextEdgeIndex);
        //            System.out.println("-> edge: " + edge.p1.pos);
        used[nextEdgeIndex] = true;
    }

    List<Polygon> result = new ArrayList<>();

    System.out.println("#bnd-path-length: " + boundaryPath.size());

    result.add(toPolygon(boundaryPath, plane));

    return result;
}

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

public static List<Polygon> _toPolygons(List<Edge> boundaryEdges, Plane plane) {

    List<Vector3d> boundaryPath = new ArrayList<>();

    boolean[] used = new boolean[boundaryEdges.size()];
    Edge edge = boundaryEdges.get(0);/*from w  w w.j a v  a  2s  .  c  om*/
    used[0] = true;
    while (true) {
        Edge finalEdge = edge;

        boundaryPath.add(finalEdge.p1.pos);

        int nextEdgeIndex = boundaryEdges
                .indexOf(boundaryEdges.stream().filter(e -> finalEdge.p2.equals(e.p1)).findFirst().get());

        if (used[nextEdgeIndex]) {
            //                System.out.println("nexIndex: " + nextEdgeIndex);
            break;
        }
        //            System.out.print("edge: " + edge.p2.pos);
        edge = boundaryEdges.get(nextEdgeIndex);
        //            System.out.println("-> edge: " + edge.p1.pos);
        used[nextEdgeIndex] = true;
    }

    List<Polygon> result = new ArrayList<>();

    System.out.println("#bnd-path-length: " + boundaryPath.size());

    result.add(toPolygon(boundaryPath, plane));

    return result;
}

From source file:org.jfree.chart.demo.SampleYSymbolicDataset.java

/**
 * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
 * order that they share the same symbolic value list.
 * <P>/*  ww w.j  a  v a  2s.  c  o  m*/
 * The sharing symbolic value list is obtained adding the symbolic data list of the fist data set to the symbolic data list of the second data set.
 * <P>
 * This function is use with the <I>combined plot</I> functions of JFreeChart.
 * 
 * @param dataset1
 *           the first data set to combine.
 * @param dataset2
 *           the second data set to combine.
 * @return the shared symbolic array.
 */
public static String[] combineYSymbolicDataset(final YisSymbolic dataset1, final YisSymbolic dataset2) {

    final SampleYSymbolicDataset sDataset1 = (SampleYSymbolicDataset) dataset1;
    final SampleYSymbolicDataset sDataset2 = (SampleYSymbolicDataset) dataset2;
    final String[] sDatasetSymbolicValues1 = sDataset1.getYSymbolicValues();
    final String[] sDatasetSymbolicValues2 = sDataset2.getYSymbolicValues();

    // Combine the two list of symbolic value of the two data set
    final int s1length = sDatasetSymbolicValues1.length;
    final int s2length = sDatasetSymbolicValues2.length;
    final List ySymbolicValuesCombined = new Vector();
    for (int i = 0; i < s1length; i++) {
        ySymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
    }
    for (int i = 0; i < s2length; i++) {
        if (!ySymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
            ySymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
        }
    }

    // Change the Integer reference of the second data set
    int newIndex;
    for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
        for (int j = 0; j < sDataset2.getItemCount(i); j++) {
            newIndex = ySymbolicValuesCombined.indexOf(sDataset2.getYSymbolicValue(i, j));
            sDataset2.setYValue(i, j, new Integer(newIndex));
        }
    }

    // Set the new list of symbolic value on the two data sets
    final String[] ySymbolicValuesCombinedA = new String[ySymbolicValuesCombined.size()];
    ySymbolicValuesCombined.toArray(ySymbolicValuesCombinedA);
    sDataset1.setYSymbolicValues(ySymbolicValuesCombinedA);
    sDataset2.setYSymbolicValues(ySymbolicValuesCombinedA);

    return ySymbolicValuesCombinedA;
}

From source file:edu.wpi.checksims.algorithm.output.SimilarityMatrix.java

/**
 * Fill the results matrix//from www  .  j a  v  a  2 s  . c o  m
 *
 * NOTE that this is inefficient; we calculate twice for each pair, as (i,j) and (j,i).
 * If speed optimizations are required, recommend starting here.
 *
 * @param submissions Submissions to generate results matrix from
 * @param algorithm Algorithm to use when detecting plagiarism
 * @return Array of algorithm results, with results[i,j] being the results of comparing students i and j
 */
public static SimilarityMatrix generate(Set<Submission> submissions, SimilarityDetector algorithm) {
    checkNotNull(submissions);
    checkArgument(submissions.size() >= 2);
    checkNotNull(algorithm);

    Logger logs = LoggerFactory.getLogger(SimilarityMatrix.class);

    float[][] results = new float[submissions.size()][submissions.size()];
    logs.debug("Sorting submissions prior to algorithm pass...");
    List<Submission> submissionsSorted = Ordering
            .from((Submission a, Submission b) -> a.getName().compareTo(b.getName()))
            .immutableSortedCopy(submissions);

    // Generate all possible unordered pairs of submissions
    Set<Submission> submissionsAsSet = ImmutableSet.copyOf(submissions);
    Set<Pair<Submission, Submission>> pairs = PairGenerator.generatePairs(submissionsAsSet);

    // Get results for all possible pairs of submissions
    Set<AlgorithmResults> algorithmResults = AlgorithmRunner.runAlgorithm(pairs, algorithm);

    // First, zero the diagonal of the results array
    for (int i = 0; i < submissionsSorted.size(); i++) {
        results[i][i] = 0.00f; // Same submission, ignore
    }

    // For each result, fill corresponding spots in the results matrix
    algorithmResults.stream().forEach((result) -> {
        int indexFirst = submissionsSorted.indexOf(result.a);
        int indexSecond = submissionsSorted.indexOf(result.b);

        if (indexFirst == -1) {
            throw new RuntimeException("Could not find index of submission " + result.a.getName());
        } else if (indexSecond == -1) {
            throw new RuntimeException("Could not find index of submission " + result.b.getName());
        }

        results[indexFirst][indexSecond] = result.percentMatchedA();
        results[indexSecond][indexFirst] = result.percentMatchedB();
    });

    logs.info("Done performing similarity detection");

    return new SimilarityMatrix(submissionsSorted, results);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.vendors.VendorHelper.java

/**
 * Save the request parameters from the Basic Info page
 */// ww  w  . j a va 2s.co m
public static Rating saveRating(Rating rating, HttpServletRequest request, String userId, Task task)
        throws EnvoyServletException {
    String rate = (String) request.getParameter("ratingField");
    String comment = (String) request.getParameter("comment");
    if (rating == null) {
        rating = new Rating(Integer.parseInt(rate), userId, comment, task);
    } else {
        // if there is a task being used - must refresh it
        // and mark it and the rating as editable/clones.
        // otherwise the change will be made on the one copy in
        // the main cache. need to make the change out of the
        // cache and the commit will merge the copies.
        if (task != null) {
            try {
                // refresh it and clone it
                task = ServerProxy.getTaskManager().getTask(task.getId(), true);
                List ratings = task.getRatings();
                // refresh the rating
                rating = (Rating) ratings.get(ratings.indexOf(rating));
            } catch (Exception e) {
                throw new EnvoyServletException(e);
            }
        }
        rating.updateRating(Integer.parseInt(rate), comment, userId);
    }
    return rating;
}

From source file:googleranking.processing.GoogleData.java

public int getRankingForDomain(String Domain) {
    List<String> links = getLinksInPage();
    return links.indexOf(Domain) + 1;
}

From source file:org.jfree.chart.demo.SampleXYSymbolicDataset.java

/**
 * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
 * order that they share the same X symbolic value list.
 * <P>//  w w w  .  j  a v  a 2  s.  c om
 * The sharing X symbolic value list is obtained adding the X symbolic data list of the fist data set to the X symbolic data list of the second data set.
 * <P>
 * This function is use with the <I>combined plot</I> functions of JFreeChart.
 * 
 * @param dataset1
 *           the first data set to combine.
 * @param dataset2
 *           the second data set to combine.
 * @return the shared X symbolic array.
 */
public static String[] combineXSymbolicDataset(final XisSymbolic dataset1, final XisSymbolic dataset2) {
    final SampleXYSymbolicDataset sDataset1 = (SampleXYSymbolicDataset) dataset1;
    final SampleXYSymbolicDataset sDataset2 = (SampleXYSymbolicDataset) dataset2;
    final String[] sDatasetSymbolicValues1 = sDataset1.getXSymbolicValues();
    final String[] sDatasetSymbolicValues2 = sDataset2.getXSymbolicValues();

    // Combine the two list of symbolic value of the two data set
    final int s1length = sDatasetSymbolicValues1.length;
    final int s2length = sDatasetSymbolicValues2.length;
    final List xSymbolicValuesCombined = new Vector();
    for (int i = 0; i < s1length; i++) {
        xSymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
    }
    for (int i = 0; i < s2length; i++) {
        if (!xSymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
            xSymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
        }
    }

    // Change the Integer reference of the second data set
    int newIndex;
    for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
        for (int j = 0; j < sDataset2.getItemCount(i); j++) {
            newIndex = xSymbolicValuesCombined.indexOf(sDataset2.getXSymbolicValue(i, j));
            sDataset2.setXValue(i, j, new Integer(newIndex));
        }
    }

    // Set the new list of symbolic value on the two data sets
    final String[] xSymbolicValuesCombinedA = new String[xSymbolicValuesCombined.size()];
    xSymbolicValuesCombined.toArray(xSymbolicValuesCombinedA);
    sDataset1.setXSymbolicValues(xSymbolicValuesCombinedA);
    sDataset2.setXSymbolicValues(xSymbolicValuesCombinedA);

    return xSymbolicValuesCombinedA;
}

From source file:org.jfree.chart.demo.SampleXYSymbolicDataset.java

/**
 * This function modify <CODE>dataset1</CODE> and <CODE>dataset1</CODE> in
 * order that they share the same Y symbolic value list.
 * <P>/*from  w w w .  j  a va2  s .c  o m*/
 * The sharing Y symbolic value list is obtained adding the Y symbolic data list of the fist data set to the Y symbolic data list of the second data set.
 * <P>
 * This function is use with the <I>combined plot</I> functions of JFreeChart.
 * 
 * @param dataset1
 *           the first data set to combine.
 * @param dataset2
 *           the second data set to combine.
 * @return the shared Y symbolic array.
 */
public static String[] combineYSymbolicDataset(final YisSymbolic dataset1, final YisSymbolic dataset2) {

    final SampleXYSymbolicDataset sDataset1 = (SampleXYSymbolicDataset) dataset1;
    final SampleXYSymbolicDataset sDataset2 = (SampleXYSymbolicDataset) dataset2;
    final String[] sDatasetSymbolicValues1 = sDataset1.getYSymbolicValues();
    final String[] sDatasetSymbolicValues2 = sDataset2.getYSymbolicValues();

    // Combine the two list of symbolic value of the two data set
    final int s1length = sDatasetSymbolicValues1.length;
    final int s2length = sDatasetSymbolicValues2.length;
    final List ySymbolicValuesCombined = new Vector();
    for (int i = 0; i < s1length; i++) {
        ySymbolicValuesCombined.add(sDatasetSymbolicValues1[i]);
    }
    for (int i = 0; i < s2length; i++) {
        if (!ySymbolicValuesCombined.contains(sDatasetSymbolicValues2[i])) {
            ySymbolicValuesCombined.add(sDatasetSymbolicValues2[i]);
        }
    }

    // Change the Integer reference of the second data set
    int newIndex;
    for (int i = 0; i < sDataset2.getSeriesCount(); i++) {
        for (int j = 0; j < sDataset2.getItemCount(i); j++) {
            newIndex = ySymbolicValuesCombined.indexOf(sDataset2.getYSymbolicValue(i, j));
            sDataset2.setYValue(i, j, new Integer(newIndex));
        }
    }

    // Set the new list of symbolic value on the two data sets
    final String[] ySymbolicValuesCombinedA = new String[ySymbolicValuesCombined.size()];
    ySymbolicValuesCombined.toArray(ySymbolicValuesCombinedA);
    sDataset1.setYSymbolicValues(ySymbolicValuesCombinedA);
    sDataset2.setYSymbolicValues(ySymbolicValuesCombinedA);

    return ySymbolicValuesCombinedA;
}

From source file:br.com.autonomiccs.cloudTraces.main.CloudTracesSimulator.java

/**
 * This method will try to deploy the virtual machine in the given cloud.
 * We use a heuristic to support the deployment process.
 * That means, the heuristic will decide in which cluster and hosts we try first to deploy the VM.
 * If the deployment is not possible, an exception will be thrown.
 *///from  w  ww.j a va2  s.  co  m
private static void deployVirtualMachine(VirtualMachine virtualMachine, Cloud cloud) {
    DeploymentHeuristic deploymentHeuristic = getDeploymentHeuristic();

    List<Cluster> rankedClustersToDeployVirtualMachine = deploymentHeuristic
            .getRankedClustersToDeployVirtualMachine(cloud.getClusters(), virtualMachine);
    for (Cluster c : rankedClustersToDeployVirtualMachine) {
        List<Host> clusterOriginalHostsList = c.getHosts();
        List<Host> rankedHostsToDeployVirtualMachie = deploymentHeuristic
                .getRankedHostsToDeployVirtualMachie(clusterOriginalHostsList, virtualMachine);
        for (Host host : rankedHostsToDeployVirtualMachie) {
            if (canHostSupportVirtualMachine(host, virtualMachine)) {
                cloud.addVirtualMachine(virtualMachine);

                int indexOfTargetHost = clusterOriginalHostsList.indexOf(host);
                Host targetHost = clusterOriginalHostsList.get(indexOfTargetHost);

                logger.debug("Host before deploy of VM: " + targetHost);
                logger.debug(
                        String.format("VM [%s] deployed at host [%s]", virtualMachine.getVmId(), host.getId()));

                targetHost.addVirtualMachine(virtualMachine);
                logger.debug("Host after deploy of VM: " + targetHost);
                return;
            }
        }
    }
    throw new GoogleTracesToCloudTracesException(
            "Could not find a suitable host to deploy VM: " + virtualMachine + "\nCloud state: " + cloud);
}