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.doculibre.constellio.plugins.PluginFactory.java

private static <P extends ConstellioPlugin> List<P> getPlugins(Class<P> pluginClass, boolean onlyDefault) {
    List<P> matches = new ArrayList<P>();
    P defaultPlugin = null;/*w w  w  .j a  v  a 2 s.co  m*/

    initPluginManager();
    PluginManagerUtil pmu = new PluginManagerUtil(pm);
    for (P impl : pmu.getPlugins(pluginClass)) {
        // ClassLoader classLoader = impl.getClass().getClassLoader();
        // classLoaders.add(classLoader);
        if (DefaultConstellioPlugin.NAME.equals(impl.getName())) {
            defaultPlugin = impl;
        } else if (!onlyDefault) {
            matches.add(impl);
        }
    }
    if (matches.isEmpty()) {
        if (defaultPlugin != null) {
            matches.add(defaultPlugin);
        }
    } else {
        // If many plugins are found, they are sorted in the order they are configured in constellio.xml
        // (the last has priority over the previous)
        Collections.sort(matches, new Comparator<ConstellioPlugin>() {
            @Override
            public int compare(ConstellioPlugin o1, ConstellioPlugin o2) {
                List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames();
                Integer indexOfPluginName1 = availablePluginNames.indexOf(o1.getName());
                Integer indexOfPluginName2 = availablePluginNames.indexOf(o2.getName());
                return indexOfPluginName1.compareTo(indexOfPluginName2);
            }
        });
    }
    return matches;
}

From source file:cpcc.vvrte.services.task.AcoTspSimple.java

/**
 * @param costMatrix the cost matrix./*from   w w  w.  j a  v a 2  s.  c om*/
 * @param pheromoneTrails the pheromone trails.
 * @param used the list of used values.
 * @param current the current value.
 * @return the weight sum.
 */
private static double doSumWeight(double[][] costMatrix, double[][] pheromoneTrails, List<Integer> used,
        int current) {
    double runningTotal = 0.0;

    for (int city = 0; city < costMatrix.length; city++) {
        if (used.indexOf(city) == -1) {
            runningTotal += (1.0 + pheromoneTrails[current][city]) / (1.0 + costMatrix[current][city]);
        }
    }

    return runningTotal;
}

From source file:com.ibuildapp.romanblack.CataloguePlugin.model.ShoppingCart.java

/**
 * Insert passed product to cart/*w  ww. ja  v  a 2s  .com*/
 *
 * @param product product
 */
public static void insertProduct(final Product product) {
    List<Product> products = getProducts();
    int index = products.indexOf(product);

    if (index == -1) {
        products.add(product);
    } else {
        products.set(index,
                new Product.Builder().setId(product.getId()).setQuantity(product.getQuantity()).build());
    }

    SqlAdapter.insertShoppingCartContent(products);
}

From source file:com.eucalyptus.entities.PersistenceContexts.java

private static boolean isDuplicate(Class entity) {
    PersistenceContext ctx = Ats.from(entity).get(PersistenceContext.class);
    if (Ats.from(entity).has(MappedSuperclass.class) || Ats.from(entity).has(Embeddable.class)) {
        return false;
    } else if (ctx == null || ctx.name() == null) {
        RuntimeException ex = new RuntimeException(
                "Failed to register broken entity class: " + entity.getCanonicalName()
                        + ".  Ensure that the class has a well-formed @PersistenceContext annotation.");
        LOG.error(ex, ex);//from   w  w  w . ja  va 2s .  c  o m
        return false;
    } else if (sharedEntities.contains(entity)) {
        Class old = sharedEntities.get(sharedEntities.indexOf(entity));
        LOG.error("Duplicate entity definition detected: " + entity.getCanonicalName());
        LOG.error("=> OLD: " + old.getProtectionDomain().getCodeSource().getLocation());
        LOG.error("=> NEW: " + entity.getProtectionDomain().getCodeSource().getLocation());
        throw BootstrapException.throwFatal("Duplicate entity definition in shared entities: "
                + entity.getCanonicalName() + ". See error logs for details.");
    } else if (entities.get(ctx.name()) != null && entities.get(ctx.name()).contains(entity)) {
        List<Class> context = entities.get(ctx.name());
        Class old = context.get(context.indexOf(entity));
        LOG.error("Duplicate entity definition detected: " + entity.getCanonicalName());
        LOG.error("=> OLD: " + old.getProtectionDomain().getCodeSource().getLocation());
        LOG.error("=> NEW: " + entity.getProtectionDomain().getCodeSource().getLocation());
        throw BootstrapException.throwFatal("Duplicate entity definition in '" + ctx.name() + "': "
                + entity.getCanonicalName() + ". See error logs for details.");
    } else {
        return false;
    }
}

From source file:net.maritimecloud.identityregistry.model.database.IdentityProviderAttribute.java

public static boolean listsEquals(List<IdentityProviderAttribute> first,
        List<IdentityProviderAttribute> second) {
    if (first == null && second != null || first != null && second == null) {
        return false;
    }//from w w  w .  j ava  2 s.co m
    if (first == null && second == null) {
        return true;
    }
    if (first.size() != second.size()) {
        return false;
    }
    List<IdentityProviderAttribute> secondCopy = new ArrayList<>(second);
    for (IdentityProviderAttribute attrInFirst : first) {
        boolean foundMatch = false;
        if (attrInFirst == null) {
            int nullIdx = secondCopy.indexOf(null);
            secondCopy.remove(nullIdx);
            continue;
        }
        for (IdentityProviderAttribute attrInSecond : secondCopy) {
            if (attrInFirst.compareNameAndValueTo(attrInSecond) == 0) {
                foundMatch = true;
                secondCopy.remove(attrInSecond);
                break;
            }
        }
        if (!foundMatch) {
            return false;
        }
    }
    if (secondCopy.size() == 0) {
        return true;
    }
    return false;
}

From source file:br.com.diegosilva.jsfcomponents.util.Utils.java

public static boolean isLastItemInList(List list, Object o) {
    return list.contains(o) && !(list.indexOf(o) < list.size() - 1);
}

From source file:com.example.android.tvleanback2.data.VideoProvider.java

/**
 * Set the current queue to the list of Movies in the given Movie's category.
 *
 * @param selectedMovie Movie whose category will be used to determine queue to be set.
 *//*from w  w w. j av a  2  s.  co m*/
public static void setQueue(Movie selectedMovie) {
    if (sMovieList == null) {
        sCurrentQueue = null;
        sCurrentMovieIndex = -1;
        return;
    }

    for (Map.Entry<String, List<Movie>> entry : sMovieList.entrySet()) {
        if (selectedMovie.getCategory().equals(entry.getKey())) {
            List<Movie> list = entry.getValue();
            if (list != null && !list.isEmpty()) {
                sCurrentQueue = list;
                sCurrentMovieIndex = list.indexOf(selectedMovie);
                return;
            }
        }
    }
}

From source file:com.tekstosense.segmenter.Rule.HeadingRule.java

/**
 * Checks if is current OR after reference.
 *
 * @param sections// w  w w.j  a  v  a2s.  c  o m
 *            the sections
 * @param section
 *            the section
 * @return true, if is current OR after reference
 */
public static boolean isCurrentORAfterReference(List<Section> sections, Section section) {
    if (section != null) {
        if (section.getHeading() != null
                && section.getHeading().getText().toLowerCase().contains("REFERENCES".toLowerCase())) {
            return true;
        }
        int index = sections.indexOf(section);
        if (index > 0) {
            return sections.get(index - 1).isReference();
        }
    }
    return false;
}

From source file:org.openrepose.filters.custom.extractdeviceid.ExtractDeviceIdFilter.java

static String extractPrefixedElement(String uri, String prefix) {
    String rtn = null;//w ww .  ja  v  a 2  s  .  co  m
    if (uri != null) {
        List<String> list = Splitter.on('/').omitEmptyStrings().splitToList(uri);
        final int idx = list.indexOf(prefix);
        if (idx >= 0 && idx + 1 < list.size()) {
            rtn = list.get(idx + 1);
        }
    }
    return rtn;
}

From source file:hydrograph.server.execution.tracking.client.main.HydrographMain.java

/**
 * /*w w w.  ja  v a2s  .  c  o m*/
 * @param argumentList
 * @return
 */
private static Optional<String> getLogLevel(List<String> argumentList) {

    if (argumentList.contains(Constants.JOB_LOG_LEVEL)) {
        return Optional.of(argumentList.get(argumentList.indexOf(Constants.JOB_LOG_LEVEL) + 1));
    }
    return Optional.empty();

}