Java List IndexOf indexOfFactory(List factories, Class classInstance)

Here you can find the source of indexOfFactory(List factories, Class classInstance)

Description

Returns the index of the factory with the given class in the List .

License

Open Source License

Parameter

Parameter Description
factories All factories.
classInstance All class instances.

Return

The index or -1 if it was not found.

Declaration

protected static int indexOfFactory(List<?> factories, Class<?> classInstance) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany
 *                    Technical University Darmstadt, Germany
 *                    Chalmers University of Technology, Sweden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   ww w.j a v a 2s  . c om
 *    Technical University Darmstadt - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Returns the index of the factory with the given class in the {@link List}.
     * @param factories All factories.
     * @param classInstance All class instances.
     * @return The index or {@code -1} if it was not found.
     */
    protected static int indexOfFactory(List<?> factories, Class<?> classInstance) {
        int result = -1;
        Iterator<?> iter = factories.iterator();
        int i = 0;
        while (result < 0 && iter.hasNext()) {
            if (classInstance.equals(iter.next().getClass())) {
                result = i;
            }
            i++;
        }
        return result;
    }
}

Related

  1. indexOf(List data, List token)
  2. indexOf(List source, List target)
  3. indexOf(List lines, String... conditions)
  4. indexOf(List list, T string, int beginIndex)
  5. indexOf(Object o, Collection list)
  6. indexOfId(List aList, Object anObj)
  7. indexOfIdentical(List list, Object value)
  8. indexOfIdentity(List l, T t)
  9. indexOfIgnoreCase(List values, String target)