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:forge.quest.QuestUtil.java

public static void travelWorld() {
    if (!checkActiveQuest("Travel between worlds.")) {
        return;//from   w w w .  j a v a2  s . co m
    }
    final List<QuestWorld> worlds = new ArrayList<>();
    final QuestController qCtrl = FModel.getQuest();

    for (final QuestWorld qw : FModel.getWorlds()) {
        if (qCtrl.getWorld() != qw) {
            worlds.add(qw);
        }
    }

    if (worlds.size() < 1) {
        SOptionPane.showErrorDialog(
                "There are currently no worlds you can travel to\nin this version of Forge.", "No Worlds");
        return;
    }

    final String setPrompt = "Where do you wish to travel?";
    final QuestWorld newWorld = SGuiChoose.oneOrNone(setPrompt, worlds);

    if (worlds.indexOf(newWorld) < 0) {
        return;
    }

    if (qCtrl.getWorld() != newWorld) {
        boolean needRemove = false;
        if (nextChallengeInWins() < 1 && !qCtrl.getAchievements().getCurrentChallenges().isEmpty()) {
            needRemove = true;

            if (!SOptionPane.showConfirmDialog(
                    "You have uncompleted challenges in your current world. If you travel now, they will be LOST!"
                            + "\nAre you sure you wish to travel anyway?\n"
                            + "(Click \"No\" to go back  and complete your current challenges first.)",
                    "WARNING: Uncompleted challenges")) {
                return;
            }
        }

        if (needRemove) {
            // Remove current challenges.
            while (nextChallengeInWins() == 0) {
                qCtrl.getAchievements().addChallengesPlayed();
            }

            qCtrl.getAchievements().getCurrentChallenges().clear();
        }

        qCtrl.setWorld(newWorld);
        qCtrl.resetDuelsManager();
        qCtrl.resetChallengesManager();
        // Note that the following can be (ab)used to re-randomize your opponents by travelling to a different
        // world and back. To prevent this, simply delete the following line that randomizes DuelsManager.
        // (OTOH, you can 'swap' opponents even more easily  by simply selecting a different quest data file and
        // then re-selecting your current quest data file.)
        qCtrl.getDuelsManager().randomizeOpponents();
        qCtrl.getCards().clearShopList();
        qCtrl.save();
    }
}

From source file:net.sf.jasperreports.components.sort.SortParameterContributor.java

private void overwriteExistingSortField(List<JRSortField> sortFields, JRSortField newSortField) {
    int indexOfExistingSortField = sortFields.indexOf(newSortField);
    if (indexOfExistingSortField != -1) {
        // remove sortfield if previos order was 'Descending'
        boolean mustRemove = (sortFields.get(indexOfExistingSortField)).getOrderValue()
                .equals(SortOrderEnum.DESCENDING);
        if (mustRemove) {
            sortFields.remove(indexOfExistingSortField);
        } else {/*from   w w w  . java 2s .  c  o m*/
            ((JRDesignSortField) sortFields.get(indexOfExistingSortField))
                    .setOrder(newSortField.getOrderValue());
        }

    } else if (newSortField.getOrderValue() != null) { // this is necessary because a dummy order - None - is introduced
        sortFields.add(newSortField);
    }
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.GWikiMacroFragment.java

@Override
public boolean replaceChilds(GWikiFragment search, List<GWikiFragment> replace) {
    List<GWikiFragment> lchilds = getChilds();
    int idx = lchilds.indexOf(search);
    if (idx == -1) {
        return false;
    }/*from   w  ww . j av  a 2 s.c  o  m*/
    lchilds.remove(idx);
    for (GWikiFragment ins : replace) {
        lchilds.add(idx++, ins);
    }
    return true;
}

From source file:com.benfante.minimark.ajax.FixedAnswerABo.java

@RemoteMethod
public void saveAnswer(Long id, String content, BigDecimal weight, Boolean correct, String filter)
        throws IOException, ServletException {
    WebContext wctx = WebContextFactory.get();
    ScriptSession session = wctx.getScriptSession();
    QuestionBean questionBean = (QuestionBean) wctx.getSession()
            .getAttribute(QuestionController.QUESTION_ATTR_NAME);
    if (questionBean != null) {
        List<FixedAnswer> fixedAnswers = questionBean.getFixedAnswers();
        FixedAnswer answer = null;//ww w  . j  av a2s. co  m
        if (id != null) {
            answer = fixedAnswerDao.get(id);
            int faIndex = fixedAnswers.indexOf(answer);
            answer = fixedAnswers.get(faIndex);
        } else { // new answer
            answer = new FixedAnswer();
            Long questionId = questionBean.getId();
            if (questionId != null) {
                answer.setQuestion((ClosedQuestion) questionDao.get(questionId));
            }
            fixedAnswers.add(answer);
        }
        answer.setContent(content);
        answer.setWeight(weight);
        answer.setCorrect(correct);
        answer.setContentFilter(filter);
        if (questionBean.getId() != null) {
            fixedAnswerDao.store(answer);
        }
        wctx.getHttpServletRequest().setAttribute("question", questionBean);
        String faDiv = wctx.forwardToString("/WEB-INF/jsp/question/fixedAnswers.jsp");
        Util util = new Util(session);
        util.setValue("fixedAnswers", faDiv, false);
    }

}

From source file:edu.uci.ics.hyracks.algebricks.core.jobgen.impl.PlanCompiler.java

private void reviseEdges(IHyracksJobBuilder builder) {
    /**//from ww  w. ja  va2 s  .  co  m
     * revise the edges for the case of replicate operator
     */
    for (Entry<Mutable<ILogicalOperator>, List<Mutable<ILogicalOperator>>> entry : operatorVisitedToParents
            .entrySet()) {
        Mutable<ILogicalOperator> child = entry.getKey();
        List<Mutable<ILogicalOperator>> parents = entry.getValue();
        if (parents.size() > 1) {
            if (child.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) {
                ReplicateOperator rop = (ReplicateOperator) child.getValue();
                if (rop.isBlocker()) {
                    // make the order of the graph edges consistent with the order of rop's outputs
                    List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
                    for (Mutable<ILogicalOperator> parent : parents) {
                        builder.contributeGraphEdge(child.getValue(), outputs.indexOf(parent),
                                parent.getValue(), 0);
                    }
                } else {
                    int i = 0;
                    for (Mutable<ILogicalOperator> parent : parents) {
                        builder.contributeGraphEdge(child.getValue(), i, parent.getValue(), 0);
                        i++;
                    }
                }
            }
        }
    }
}

From source file:net.sf.eclipsecs.ui.quickfixes.coding.StringLiteralEqualityQuickfix.java

/**
 * {@inheritDoc}// www  .j  a v  a 2 s  . com
 */
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartPosition) {

    return new ASTVisitor() {

        public boolean visit(InfixExpression node) {

            if (containsPosition(lineInfo, node.getStartPosition())) {

                StringLiteral literal = null;
                Expression otherOperand = null;

                if (node.getLeftOperand() instanceof StringLiteral) {
                    literal = (StringLiteral) node.getLeftOperand();
                    otherOperand = node.getRightOperand();
                } else if (node.getRightOperand() instanceof StringLiteral) {
                    literal = (StringLiteral) node.getRightOperand();
                    otherOperand = node.getLeftOperand();
                } else {
                    return true;
                }

                Expression replacementNode = null;

                MethodInvocation equalsInvocation = node.getAST().newMethodInvocation();
                equalsInvocation.setName(node.getAST().newSimpleName("equals")); //$NON-NLS-1$
                equalsInvocation.setExpression((Expression) ASTNode.copySubtree(node.getAST(), literal));
                equalsInvocation.arguments().add(ASTNode.copySubtree(node.getAST(), otherOperand));

                // if the string was compared with != create a not
                // expression
                if (node.getOperator().equals(InfixExpression.Operator.NOT_EQUALS)) {
                    PrefixExpression prefixExpression = node.getAST().newPrefixExpression();
                    prefixExpression.setOperator(PrefixExpression.Operator.NOT);
                    prefixExpression.setOperand(equalsInvocation);
                    replacementNode = prefixExpression;
                } else {
                    replacementNode = equalsInvocation;
                }

                replaceNode(node, replacementNode);
            }
            return true;
        }

        /**
         * Replaces the given node with the replacement node (using
         * reflection since I am not aware of a proper API to do this).
         * 
         * @param node
         *            the node to replace
         * @param replacementNode
         *            the replacement
         */
        private void replaceNode(ASTNode node, ASTNode replacementNode) {

            try {
                if (node.getLocationInParent().isChildProperty()) {

                    String property = node.getLocationInParent().getId();

                    String setterMethodName = "set" + StringUtils.capitalize(property);

                    Class testClass = node.getClass();

                    while (testClass != null) {

                        try {
                            Method setterMethod = node.getParent().getClass().getMethod(setterMethodName,
                                    testClass);
                            setterMethod.invoke(node.getParent(), replacementNode);
                            break;
                        } catch (NoSuchMethodException e) {
                            testClass = testClass.getSuperclass();
                        }
                    }

                } else if (node.getLocationInParent().isChildListProperty()) {
                    Method listMethod = node.getParent().getClass()
                            .getMethod(node.getLocationInParent().getId(), (Class<?>[]) null);
                    List list = (List) listMethod.invoke(node.getParent(), (Object[]) null);
                    list.set(list.indexOf(node), replacementNode);
                }
            } catch (InvocationTargetException e) {
                CheckstyleLog.log(e);
            } catch (IllegalAccessException e) {
                CheckstyleLog.log(e);
            } catch (NoSuchMethodException e) {
                CheckstyleLog.log(e);
            }
        }
    };
}

From source file:com.eyeq.pivot4j.util.MemberSelection.java

/**
 * @param member/*from  w  w w .  ja v a  2  s  . c  o m*/
 */
public void moveUp(Member member) {
    SelectionNode node = (SelectionNode) findChild(member);

    if (node == null) {
        throw new IllegalArgumentException("The specified member does not belong to the selection tree.");
    }

    TreeNode<Member> parentNode = node.getParent();
    List<TreeNode<Member>> siblings = parentNode.getChildren();

    int index = siblings.indexOf(node);

    TreeNode<Member> targetNode = siblings.get(index - 1);

    parentNode.removeChild(node);
    parentNode.removeChild(targetNode);

    parentNode.addChild(index - 1, node);
    parentNode.addChild(index, targetNode);
}

From source file:com.eyeq.pivot4j.util.MemberSelection.java

/**
 * @param member/*from   w ww.  j av a 2  s.  c o m*/
 */
public void moveDown(Member member) {
    SelectionNode node = (SelectionNode) findChild(member);

    if (node == null) {
        throw new IllegalArgumentException("The specified member does not belong to the selection tree.");
    }

    TreeNode<Member> parentNode = node.getParent();
    List<TreeNode<Member>> siblings = parentNode.getChildren();

    int index = siblings.indexOf(node);

    TreeNode<Member> targetNode = siblings.get(index + 1);

    parentNode.removeChild(node);
    parentNode.removeChild(targetNode);

    parentNode.addChild(index, targetNode);
    parentNode.addChild(index + 1, node);
}

From source file:com.evolveum.midpoint.repo.sql.query.definition.EntityDefinition.java

@Override
public String debugDump(int indent) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < indent; i++) {
        sb.append(DebugDumpable.INDENT_STRING);
    }/*  www  . j  a  va  2 s.  co m*/
    sb.append(toString());

    List<Definition> definitions = getDefinitions();
    for (Definition definition : definitions) {
        sb.append(definition.debugDump(indent + 1));
        if (definitions.indexOf(definition) != definitions.size() - 1) {
            sb.append('\n');
        }
    }

    return sb.toString();
}