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.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartLineGraphicCreator.java

/**
 * @param entries/*  ww  w.  j av a  2s. co m*/
 * @return index of the last element to add to the diagram
 */
private int getIndexLastElementToDraw(List<TimeseriesEntry> entries) {
    int idx = -1;
    for (TimeseriesEntry entry : entries) {
        if (entry.getDate().before(toDate)) {
            idx = entries.indexOf(entry);
        }
    }
    return idx;
}

From source file:edu.cmu.tetrad.graph.LayeredDrawing.java

private int numCrossings(List<Node> tier1, List<Node> tier2, Graph graph) {
    if (tier2.size() < 2) {
        return 0;
    }//from w w w .ja  v a 2s  . c o  m

    ChoiceGenerator cg = new ChoiceGenerator(tier2.size(), 2);
    int[] choice;
    int numCrossings = 0;

    while ((choice = cg.next()) != null) {
        List<Node> list1 = graph.getAdjacentNodes(tier2.get(choice[0]));
        List<Node> list2 = graph.getAdjacentNodes(tier2.get(choice[1]));

        list1.retainAll(tier1);
        list2.retainAll(tier1);

        for (Node node0 : list1) {
            for (Node node1 : list2) {
                if (list1.indexOf(node0) > list1.indexOf(node1)) {
                    numCrossings++;
                }
            }
        }
    }

    return numCrossings;
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.functions.AbstractLogFunction.java

protected Collection<Logger> getParentLoggers(final Object scope, final ReferenceScript script) {
    // determine parent script from call chain
    final List<? extends ReferenceScript> scriptCallChain = this.scriptProcessor.getScriptCallChain();
    final int scriptIndex = scriptCallChain.indexOf(script);
    final ReferenceScript parentScript = scriptIndex > 0 ? scriptCallChain.get(scriptIndex - 1) : null;

    // determine parent scope from explicit registration
    final Pair<WeakReference<Object>, ReferenceScript> scopeParentPair;

    this.scopeParentLock.readLock().lock();
    try {/*ww w. j  a  va2 s  . co m*/
        scopeParentPair = this.scopeParents.get(scope);
    } finally {
        this.scopeParentLock.readLock().unlock();
    }
    // use parent scope only if one has been registered and the script it was registered for is the identical script retrieved from the
    // call chain
    final Object parentScope = scopeParentPair == null || (scopeParentPair.getSecond() != parentScript) ? scope
            : scopeParentPair.getFirst().get();

    final LoggerData parentLoggerData = parentScope != null && parentScript != null
            ? this.getLoggerData(parentScope, parentScript, false)
            : null;
    final Collection<Logger> loggers;
    if (parentLoggerData == null || parentLoggerData.isInheritLoggerContext()) {
        loggers = this.getLoggers(parentScope, parentScript, parentLoggerData);
    } else {
        loggers = Collections.emptySet();
    }

    return loggers;
}

From source file:org.synyx.hades.dao.query.Parameters.java

/**
 * Creates a new instance of {@link Parameters}.
 * //w w  w.  jav a  2  s .  co  m
 * @param method
 */
public Parameters(Method method) {

    Assert.notNull(method);

    this.parameters = new ArrayList<Parameter>();

    List<Class<?>> types = Arrays.asList(method.getParameterTypes());
    Annotation[][] annotations = method.getParameterAnnotations();

    for (int i = 0; i < types.size(); i++) {
        parameters.add(new Parameter(types.get(i), annotations[i], this, i));
    }

    this.pageableIndex = types.indexOf(Pageable.class);
    this.sortIndex = types.indexOf(Sort.class);

    assertEitherAllParamAnnotatedOrNone();
}

From source file:com.draagon.meta.manager.xml.ObjectManagerXML.java

/**
 * Update the specified object in the datastore
 *//* w w w .  ja  v  a 2s.  co m*/
public void updateObject(ObjectConnection c, Object obj) throws MetaException {
    MetaObject mc = MetaDataLoader.findMetaObject(obj);
    List<Object> list = getObjectsFromTable(c, mc);

    int i = list.indexOf(obj);
    if (i < 0)
        throw new MetaException("Object [" + obj + "] did not exist in table for class [" + mc + "]");

    if (!isUpdateableClass(mc))
        throw new MetaException("Object of class [" + mc + "] is not persistable");

    prePersistence(c, mc, obj, UPDATE);

    list.set(i, obj);

    postPersistence(c, mc, obj, UPDATE);
}

From source file:com.draagon.meta.manager.xml.ObjectManagerXML.java

/**
 * Delete the specified object from the datastore
 *//*from  w  w w . j a v a  2 s .  c  o  m*/
public void deleteObject(ObjectConnection c, Object obj) throws MetaException {
    MetaObject mc = MetaDataLoader.findMetaObject(obj);
    List<Object> list = getObjectsFromTable(c, mc);

    int i = list.indexOf(obj);
    if (i < 0)
        throw new MetaException("Object [" + obj + "] did not exist in table for class [" + mc + "]");

    if (!isDeleteableClass(mc))
        throw new MetaException("Object of class [" + mc + "] is not persistable");

    prePersistence(c, mc, obj, DELETE);

    list.remove(i);

    postPersistence(c, mc, obj, DELETE);
}

From source file:com.vmware.vfabric.ide.eclipse.tcserver.internal.ui.ExtendedTcStaticResourcesEditorSection.java

private void updateButtons(Object obj) {
    if (obj instanceof String) {
        List<Object> modules = Arrays.asList(contentProvider.getElements(server));
        int index = modules.indexOf(obj);
        upButton.setEnabled(index > 0);
        downButton.setEnabled(index < modules.size() - 1);
        deleteButton.setEnabled(true);//  w w  w  . j a  v  a  2s.c o m
    } else {
        upButton.setEnabled(false);
        downButton.setEnabled(false);
        deleteButton.setEnabled(false);
    }
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.functions.AbstractLogFunction.java

protected boolean isParentLoggerExplicit(final Object scope, final ReferenceScript script) {
    // determine parent script from call chain
    final List<? extends ReferenceScript> scriptCallChain = this.scriptProcessor.getScriptCallChain();
    final int scriptIndex = scriptCallChain.indexOf(script);
    final ReferenceScript parentScript = scriptIndex > 0 ? scriptCallChain.get(scriptIndex - 1) : null;

    final boolean result;
    if (parentScript != null) {
        // determine parent scope from explicit registration
        final Pair<WeakReference<Object>, ReferenceScript> scopeParentPair;

        this.scopeParentLock.readLock().lock();
        try {//w  w  w.j a va2s. com
            scopeParentPair = this.scopeParents.get(scope);
        } finally {
            this.scopeParentLock.readLock().unlock();
        }

        // use parent scope only if one has been registered and the script it was registered for is the identical script retrieved from
        // the call chain
        final Object parentScope = scopeParentPair == null || (scopeParentPair.getSecond() != parentScript)
                ? scope
                : scopeParentPair.getFirst().get();

        final LoggerData parentLoggerData = parentScope != null
                ? this.getLoggerData(parentScope, parentScript, false)
                : null;

        // check immediate parent
        final boolean nextParentLoggerIsExplicit = parentLoggerData != null
                && parentLoggerData.getExplicitLogger() != null && parentLoggerData.isInheritLoggerContext();
        // recursive check unless inheritance is off
        final boolean ancestorLoggerIsExplicit = (parentLoggerData == null
                || parentLoggerData.isInheritLoggerContext())
                && this.isParentLoggerExplicit(parentScope, parentScript);
        result = nextParentLoggerIsExplicit || ancestorLoggerIsExplicit;
    } else {
        result = false;
    }
    return result;
}

From source file:com.google.dart.engine.services.internal.refactoring.ExtractLocalRefactoringImpl.java

/**
 * @return the {@link Statement} such that variable declaration added before it will be visible in
 *         all given occurrences./*from  w  w  w.  jav a  2 s . com*/
 */
private Statement findTargetStatement(List<SourceRange> occurrences) {
    List<ASTNode> nodes = findNodes(occurrences);
    List<ASTNode> firstParents = CorrectionUtils.getParents(nodes.get(0));
    ASTNode commonParent = CorrectionUtils.getNearestCommonAncestor(nodes);
    if (commonParent instanceof Block) {
        int commonIndex = firstParents.indexOf(commonParent);
        return (Statement) firstParents.get(commonIndex + 1);
    } else {
        return commonParent.getAncestor(Statement.class);
    }
}