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:eu.supersede.gr.utility.PointsLogic.java

private void computePoints() {
    List<HAHPGamePlayerPoint> gamesPlayersPoints = gamesPlayersPointsRepository.findAll();

    // cycle on every gamesPlayersPoints
    for (int i = 0; i < gamesPlayersPoints.size(); i++) {
        HAHPGame g = gamesRepository.findOne(gamesPlayersPoints.get(i).getGame().getGameId());

        // set currentPlayer that is used for other methods
        g.setCurrentPlayer(gamesPlayersPoints.get(i).getUser());

        List<HAHPCriteriasMatrixData> criteriasMatrixDataList = criteriaMatricesRepository.findByGame(g);

        // calculate the agreementIndex for every gamesPlayersPoints of a game and a specific user

        Map<String, Double> resultTotal = AHPRest.CalculateAHP(g.getCriterias(), g.getRequirements(),
                criteriasMatrixDataList, g.getRequirementsMatrixData());
        Map<String, Double> resultPersonal = AHPRest.CalculatePersonalAHP(
                gamesPlayersPoints.get(i).getUser().getUserId(), g.getCriterias(), g.getRequirements(),
                criteriasMatrixDataList, g.getRequirementsMatrixData());
        List<Requirement> gameRequirements = g.getRequirements();
        Double sum = 0.0;/*from w  w  w. j  a v  a  2 s .c  o  m*/

        for (int j = 0; j < resultTotal.size(); j++) {
            Double requirementValueTotal = resultTotal
                    .get(gameRequirements.get(j).getRequirementId().toString());
            Double requirementValuePersonal = resultPersonal
                    .get(gameRequirements.get(j).getRequirementId().toString());
            sum = sum + (Math.abs(requirementValueTotal - requirementValuePersonal)
                    * (1.0 - requirementValueTotal));
        }

        Double agreementIndex = M - (M * sum);
        gamesPlayersPoints.get(i).setAgreementIndex(agreementIndex.longValue());

        // calculate the positionInVoting for every gamesPlayersPoints of a game and a specific user

        List<User> players = g.getPlayers();
        List<HAHPRequirementsMatrixData> lrmd = requirementsMatricesRepository.findByGame(g);
        Map<User, Float> gamePlayerVotes = new HashMap<>();

        for (User player : players) {
            Integer total = 0;
            Integer voted = 0;

            if (lrmd != null) {
                for (HAHPRequirementsMatrixData data : lrmd) {
                    for (HAHPPlayerMove pm : data.getPlayerMoves()) {
                        if (pm.getPlayer().getUserId().equals(player.getUserId())) {
                            total++;

                            if (pm.getPlayed() == true && pm.getValue() != null && !pm.getValue().equals(-1l)) {
                                voted++;
                            }
                        }
                    }
                }
            }

            gamePlayerVotes.put(player, total.equals(0) ? 0f : ((new Float(voted) / new Float(total)) * 100));
        }

        LinkedHashMap<User, Float> orderedList = sortHashMapByValues(gamePlayerVotes);
        List<User> indexes = new ArrayList<>(orderedList.keySet());
        Integer index = indexes.indexOf(gamesPlayersPoints.get(i).getUser());
        Double positionInVoting = (orderedList.size() - (new Double(index) + 1.0)) + 1.0;
        gamesPlayersPoints.get(i).setPositionInVoting(positionInVoting.longValue());

        // calculate the virtualPosition of a user base on his/her points in a particular game

        HAHPGamePlayerPoint gpp = gamesPlayersPointsRepository
                .findByUserAndGame(gamesPlayersPoints.get(i).getUser(), g);
        List<HAHPGamePlayerPoint> specificGamePlayersPoints = gamesPlayersPointsRepository.findByGame(g);

        Collections.sort(specificGamePlayersPoints, new CustomComparator());

        Long virtualPosition = specificGamePlayersPoints.indexOf(gpp) + 1l;
        gamesPlayersPoints.get(i).setVirtualPosition(virtualPosition);

        Long movesPoints = 0l;
        Long gameProgressPoints = 0l;
        Long positionInVotingPoints = 0l;
        Long gameStatusPoints = 0l;
        Long agreementIndexPoints = 0l;
        Long totalPoints = 0l;

        // set the movesPoints
        movesPoints = g.getMovesDone().longValue();

        // setGameProgressPoints
        gameProgressPoints = (long) Math.floor(g.getPlayerProgress() / 10);

        // setPositionInVotingPoints
        if (positionInVoting == 1) {
            positionInVotingPoints = 5l;
        } else if (positionInVoting == 2) {
            positionInVotingPoints = 3l;
        } else if (positionInVoting == 3) {
            positionInVotingPoints = 2l;
        }

        // setGameStatusPoints
        if (g.getPlayerProgress() != 100) {
            gameStatusPoints = -20l;
        } else {
            gameStatusPoints = 0l;
        }

        // set AgreementIndexPoints
        agreementIndexPoints = agreementIndex.longValue();
        totalPoints = movesPoints.longValue() + gameProgressPoints + positionInVotingPoints + gameStatusPoints
                + agreementIndexPoints;

        // set totalPoints 0 if the totalPoints are negative
        if (totalPoints < 0) {
            totalPoints = 0l;
        }

        gamesPlayersPoints.get(i).setPoints(totalPoints);
        gamesPlayersPointsRepository.save(gamesPlayersPoints.get(i));
    }

    System.out.println("Finished computing votes");
}

From source file:com.microsoft.alm.plugin.idea.common.ui.common.ServerContextTableModel.java

private void select(final ServerContext context) {
    final List<ServerContext> localRows;
    if (filteredRows != null) {
        localRows = filteredRows;/* w w w  .  java  2s  .co m*/
    } else {
        localRows = rows;
    }

    final int index = localRows.indexOf(context);
    if (index >= 0) {
        selectionModel.setSelectionInterval(index, index);
    }
}

From source file:net.urlgrey.mythpodcaster.dao.SubscriptionsDAOImpl.java

@Override
public void removeSubscription(String seriesId, String transcodeProfileId) {
    LOGGER.debug("Removing subscription: seriesId [" + seriesId + "], transcodeProfileId[" + transcodeProfileId
            + "]");
    FeedSubscriptions subscriptionsDocument = loadSubscriptionDocument();

    FeedSubscriptionItem item = new FeedSubscriptionItem();
    item.setSeriesId(seriesId);//from   w  w  w. j  a  v a2s.  com
    item.setTranscodeProfile(transcodeProfileId);

    final List<FeedSubscriptionItem> subscriptions = subscriptionsDocument.getSubscriptions();
    if (!subscriptions.contains(item)) {
        LOGGER.info("Item not found in subscriptions, returning");
        return;
    }

    final int index = subscriptions.indexOf(item);
    final FeedSubscriptionItem actualItem = subscriptions.get(index);
    actualItem.setActive(false);
    LOGGER.debug("Subscriptions size: " + subscriptions.size());
    storeSubscriptionDocument(subscriptionsDocument);
}

From source file:com.trial.phonegap.plugin.calendar.CalendarAccessorMock.java

/**
 * Add an event to calendar with the given paramaters
 * @param calendar//from   ww w .j  av a2 s. c o  m
 * @param description
 * @param location
 * @param summary
 * @param start
 * @param end
 * @param status
 * @param transparency
 * @param reminder
 * @param frequency
 * @param daysInMonth
 * @param monthsInYear
 * @param expires
 */
private static void addCalendar(List<JSONObject> calendar, String description, String location, String summary,
        String start, String end, String status, String transparency, String reminder, String frequency,
        JSONArray daysInMonth, JSONArray monthsInYear, String expires) {

    JSONObject event = new JSONObject();
    JSONObject recurrence = new JSONObject();
    try {
        recurrence.put("frequency", frequency);
        recurrence.put("daysInMonth", daysInMonth);
        recurrence.put("monthsInYear", monthsInYear);
        recurrence.put("expires", expires);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        event.put("description", description);
        event.put("location", location);
        event.put("summary", summary);
        event.put("start", start);
        event.put("end", end);
        event.put("status", status);
        event.put("transparency", transparency);
        event.put("reminder", reminder);
        event.put("recurrence", recurrence);

        calendar.add(event);
        event.put("id", String.valueOf(calendar.indexOf(event)));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.hs.mannheim.modUro.controller.diagram.ModeltypeDiagramController.java

/**
 * Initializes Choicebox Content./*from w w w.ja  v a 2 s  . com*/
 */
private void initializeChoiceboxContent() {
    List<String> name = modeltypeDiagram.getMetricTypeNames();

    int left = 0;
    int right = 0;

    for (String val : name) {
        if (val.equals(FitnessName.ARRANGEMENT_FITNESS.getName())) {
            left = name.indexOf(FitnessName.ARRANGEMENT_FITNESS.getName());
        }

        if (val.equals(FitnessName.VOLUME_FITNESS.getName())) {
            right = name.indexOf(FitnessName.VOLUME_FITNESS.getName());
        }
    }

    leftMetricType.setItems(FXCollections.observableArrayList(name));
    rightMetricType.setItems(FXCollections.observableArrayList(name));

    leftMetricType.getSelectionModel().select(left);
    rightMetricType.getSelectionModel().select(right);

    leftLastSelectedIndex = left;
    rightLastSelectedIndex = right;

    leftLastSelectedMetrictypename = name.get(leftLastSelectedIndex);
    rightLastSelectedMetrictypename = name.get(rightLastSelectedIndex);

    setLeftChartContent(name.get(left));
    setRightChartContent(name.get(right));
}

From source file:com.cronutils.model.time.TimeNode.java

/**
 * We return same reference value if matches or next one if does not match.
 * Then we start applying shifts.// ww  w .jav  a  2 s. c  o  m
 * This way we ensure same value is returned if no shift is requested.
 * @param reference - reference value
 * @param shiftsToApply - shifts to apply
 * @return NearestValue instance, never null. Holds information on nearest (forward) value and shifts performed.
 */
@VisibleForTesting
NearestValue getNearestForwardValue(int reference, int shiftsToApply) {
    List<Integer> values = new ArrayList<Integer>(this.values);
    int index = 0;
    boolean foundGreater = false;
    AtomicInteger shift = new AtomicInteger(0);
    if (!values.contains(reference)) {
        for (Integer value : values) {
            if (value > reference) {
                index = values.indexOf(value);
                shiftsToApply--;//we just moved a position!
                foundGreater = true;
                break;
            }
        }
        if (!foundGreater) {
            shift.incrementAndGet();
        }
    } else {
        index = values.indexOf(reference);
    }
    int value = values.get(index);
    for (int j = 0; j < shiftsToApply; j++) {
        value = getValueFromList(values, index + 1, shift);
        index = values.indexOf(value);
    }
    return new NearestValue(value, shift.get());
}

From source file:edu.uci.ics.jung.io.PajekNetIOTest.java

private void checkSets(Collection<Number> s1, Collection<Number> s2, List<Number> id1, List<Number> id2) {
    for (Number u : s1) {
        int j = id1.indexOf(u);
        assertTrue(s2.contains(id2.get(j)));
    }/*from   w  w w  . j  ava 2  s .  c  om*/
}

From source file:edu.uci.ics.jung.io.PajekNetWriter.java

/**
 * Writes <code>graph</code> to <code>w</code>.  Labels for vertices may
 * be supplied by <code>vs</code> (defaults to no labels if null), 
 * edge weights may be specified by <code>nev</code>
 * (defaults to weights of 1.0 if null), 
 * and vertex locations may be specified by <code>vld</code> (defaults
 * to no locations if null). /*  w w w  .j a  va  2s . com*/
 */
public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev,
        Transformer<V, Point2D> vld) throws IOException {
    /*
     * TODO: Changes we might want to make:
     * - optionally writing out in list form
     */

    BufferedWriter writer = new BufferedWriter(w);
    if (nev == null)
        nev = new Transformer<E, Number>() {
            public Number transform(E e) {
                return 1;
            }
        };
    writer.write("*Vertices " + graph.getVertexCount());
    writer.newLine();

    List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph);
    for (V currentVertex : graph.getVertices()) {
        // convert from 0-based to 1-based index
        int v_id = id.indexOf(currentVertex) + 1;
        writer.write("" + v_id);
        if (vs != null) {
            String label = vs.transform(currentVertex);
            if (label != null)
                writer.write(" \"" + label + "\"");
        }
        if (vld != null) {
            Point2D location = vld.transform(currentVertex);
            if (location != null)
                writer.write(" " + location.getX() + " " + location.getY() + " 0.0");
        }
        writer.newLine();
    }

    Collection<E> d_set = new HashSet<E>();
    Collection<E> u_set = new HashSet<E>();

    boolean directed = graph instanceof DirectedGraph;

    boolean undirected = graph instanceof UndirectedGraph;

    // if it's strictly one or the other, no need to create extra sets
    if (directed)
        d_set.addAll(graph.getEdges());
    if (undirected)
        u_set.addAll(graph.getEdges());
    if (!directed && !undirected) // mixed-mode graph
    {
        u_set.addAll(graph.getEdges());
        d_set.addAll(graph.getEdges());
        for (E e : graph.getEdges()) {
            if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) {
                d_set.remove(e);
            } else {
                u_set.remove(e);
            }
        }
    }

    // write out directed edges
    if (!d_set.isEmpty()) {
        writer.write("*Arcs");
        writer.newLine();
    }
    for (E e : d_set) {
        int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1;
        int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(source_id + " " + target_id + " " + weight);
        writer.newLine();
    }

    // write out undirected edges
    if (!u_set.isEmpty()) {
        writer.write("*Edges");
        writer.newLine();
    }
    for (E e : u_set) {
        Pair<V> endpoints = graph.getEndpoints(e);
        int v1_id = id.indexOf(endpoints.getFirst()) + 1;
        int v2_id = id.indexOf(endpoints.getSecond()) + 1;
        float weight = nev.transform(e).floatValue();
        writer.write(v1_id + " " + v2_id + " " + weight);
        writer.newLine();
    }
    writer.close();
}

From source file:grakn.core.console.test.GraknConsoleIT.java

private String[] addKeyspaceAndUriParams(String[] args) {
    List<String> argList = Lists.newArrayList(args);

    int keyspaceIndex = argList.indexOf("-k") + 1;
    if (keyspaceIndex == 0) {
        argList.add("-k");
        argList.add(GraknConsole.DEFAULT_KEYSPACE);
        keyspaceIndex = argList.size() - 1;
    }/*  ww w  . j  a va 2s .  co m*/

    argList.set(keyspaceIndex, argList.get(keyspaceIndex) + keyspaceSuffix);

    boolean uriSpecified = argList.contains("-r");
    if (!uriSpecified) {
        argList.add("-r");
        argList.add(server.grpcUri());
    }

    return argList.toArray(new String[argList.size()]);
}

From source file:br.com.d4n.ui4entity.mvc.SpringContextConfigurer.java

private void decorateHandlers(List<HandlerMethodReturnValueHandler> handlers) {
    for (HandlerMethodReturnValueHandler handler : handlers) {

        if (handlerReturnValueType.equals(handler.getClass())) {
            HandlerMethodReturnValueHandler decorator = new ValueOptionReturnValueHandler(
                    new ControllerReturnValueHandler(handler, parserEngine));
            int index = handlers.indexOf(handler);
            handlers.set(index, decorator);

            logger.info("@TODO: Metadata Injecting decorator wired up");
        }//  w  w w  .jav  a  2  s  .  c  om
    }
}