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:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java

/**
 * Find the first compatible address element of the root.
 * <p>//from  w  w  w.  ja va 2  s .com
 * Compatible address should be SOAP protocol version 1.1 and 1.2.
 * </p>
 * 
 * @param root Root element of wsdl.
 * @return First compatible address element or null if no element.
 */
public static Element findFirstCompatibleAddress(Element root) {

    Validate.notNull(root, ROOT_ELEMENT_REQUIRED);

    // Find all address elements
    List<Element> addresses = XmlUtils.findElements(ADDRESSES_XPATH, root);

    // Separate on a list the addresses prefix
    List<String> prefixes = new ArrayList<String>();
    for (int i = 0; i < addresses.size(); i++) {

        String nodeName = addresses.get(i).getNodeName();
        prefixes.add(i, getNamespace(nodeName));
    }

    // Separate on a list the addresses namespace
    List<String> namespaces = new ArrayList<String>();
    for (int i = 0; i < prefixes.size(); i++) {

        namespaces.add(i, getNamespaceURI(root, prefixes.get(i)));
    }

    // Any namepace is a SOAP namespace with or whitout final slash ?
    int index;
    boolean soap1_2 = false;
    boolean soap1_1 = false;
    if ((index = namespaces.indexOf(SOAP_12_NAMESPACE)) != -1
            || (index = namespaces.indexOf(NAMESPACE_WITHOUT_SLASH_12)) != -1) {

        // First preference: SOAP 1.2 protocol
        soap1_2 = true;

    } else if ((index = namespaces.indexOf(SOAP_11_NAMESPACE)) != -1
            || (index = namespaces.indexOf(NAMESPACE_WITHOUT_SLASH_11)) != -1) {

        // Second preference: SOAP 1.1 protocol
        soap1_1 = true;
    }
    if (!(soap1_2 || soap1_1)) {
        // Other protocols not supported
        return null;
    }

    return addresses.get(index);
}

From source file:de.bund.bfr.math.Evaluator.java

public static double[] getDiffPoints(Map<String, Double> parserConstants, Map<String, String> functions,
        Map<String, Double> initValues, Map<String, String> initParameters,
        Map<String, List<Double>> conditionLists, String dependentVariable,
        Map<String, Double> independentVariables, String varX, double[] valuesX, IntegratorFactory integrator,
        InterpolationFactory interpolator) throws ParseException {
    DiffFunctionConf function = new DiffFunctionConf(parserConstants, functions, initValues, initParameters,
            conditionLists, dependentVariable, independentVariables, varX, valuesX, integrator, interpolator);
    double[] result = diffResults.getIfPresent(function);

    if (result != null) {
        return result;
    }// w ww . j a  v a 2s  . c  om

    List<ASTNode> fs = new ArrayList<>();
    List<String> valueVariables = new ArrayList<>();
    double[] values = new double[functions.size()];
    Parser parser = new Parser();

    parserConstants.forEach((constant, value) -> parser.setVarValue(constant, value));

    int index = 0;

    for (Map.Entry<String, String> entry : functions.entrySet()) {
        String var = entry.getKey();

        fs.add(parser.parse(entry.getValue()));
        valueVariables.add(var);
        values[index++] = initValues.containsKey(var) ? initValues.get(var)
                : parserConstants.get(initParameters.get(var));
    }

    Map<String, UnivariateFunction> variableFunctions = MathUtils.createInterpolationFunctions(conditionLists,
            varX, interpolator);
    FirstOrderDifferentialEquations f = MathUtils.createDiffEquations(parser, fs, valueVariables, varX,
            variableFunctions);
    FirstOrderIntegrator instance = integrator.createIntegrator();
    double diffValue = conditionLists.get(varX).get(0);
    int depIndex = valueVariables.indexOf(dependentVariable);
    double[] valuesY = new double[valuesX.length];

    for (int i = 0; i < valuesX.length; i++) {
        if (valuesX[i] == diffValue) {
            valuesY[i] = values[depIndex];
        } else if (valuesX[i] > diffValue) {
            instance.integrate(f, diffValue, values, valuesX[i], values);
            diffValue = valuesX[i];
            valuesY[i] = values[depIndex];
        } else {
            valuesY[i] = Double.NaN;
        }
    }

    diffResults.put(function, valuesY);

    return valuesY;
}

From source file:gov.nyc.doitt.gis.geoclient.service.search.SingleFieldSearchHandlerTest.java

@Test
public void testFindLocationDefaultPolicy_addressWithTwoValidSimilarNames() {
    SearchResult searchResult = this.singleFieldSearchHandler.findLocation("314 100 St Manhattan");
    assertThat(searchResult.isExactMatch(), is(false));
    assertThat(searchResult.getExactMatch(), is(nullValue()));
    assertThat(searchResult.getSearches().size() >= 3, is(true));
    // First result
    Search initialSearch = searchResult.getSearches().get(0);
    assertThat(initialSearch.getLevel(), equalTo(SearchPolicy.INITIAL_SEARCH_LEVEL));
    assertThat(initialSearch.getResponse().isRejected(), is(true));
    assertThat(initialSearch.getResponse().getResponseStatus().similarNamesCount() >= 2, is(true));
    List<String> similarNames = initialSearch.getSimilarNames();
    String east100Street = "EAST  100 STREET";
    assertThat(similarNames.contains(east100Street), is(true));
    String west100Street = "WEST  100 STREET";
    assertThat(similarNames.contains(west100Street), is(true));
    boolean east100IsFirst = similarNames.indexOf(east100Street) < similarNames.indexOf(west100Street);
    String firstSimilarName = east100IsFirst ? east100Street : west100Street;
    String secondSimilarName = east100IsFirst ? west100Street : east100Street;
    // Second result
    Search secondSearch = searchResult.getSearches().get(1);
    assertThat(secondSearch.getLevel(), equalTo(SearchPolicy.INITIAL_SEARCH_LEVEL + 1));
    AddressRequest secondRequest = (AddressRequest) secondSearch.getRequest();
    assertThat(secondRequest.getHouseNumber(), equalTo("314"));
    assertThat(secondRequest.getStreet(), equalTo(firstSimilarName));
    assertThat(secondRequest.getBorough(), equalTo("MANHATTAN"));
    assertThat(secondSearch.getResponseStatus().isRejected(), is(false));
    // Third result
    Search thirdSearch = searchResult.getSearches().get(2);
    assertThat(thirdSearch.getLevel(), equalTo(SearchPolicy.INITIAL_SEARCH_LEVEL + 1));
    AddressRequest thirdRequest = (AddressRequest) thirdSearch.getRequest();
    assertThat(thirdRequest.getHouseNumber(), equalTo("314"));
    assertThat(thirdRequest.getStreet(), equalTo(secondSimilarName));
    assertThat(thirdRequest.getBorough(), equalTo("MANHATTAN"));
    assertThat(thirdSearch.getResponseStatus().isRejected(), is(false));
}

From source file:com.intellectualcrafters.plot.commands.Comment.java

@Override
public boolean execute(final Player plr, final String... args) {
    if (!PlayerFunctions.isInPlot(plr)) {
        return sendMessage(plr, C.NOT_IN_PLOT);
    }//w w w.  j a v  a  2s.  com
    final Plot plot = PlayerFunctions.getCurrentPlot(plr);
    if (!plot.hasOwner()) {
        return sendMessage(plr, C.NOT_IN_PLOT);
    }

    final List<String> recipients = Arrays.asList("admin", "owner", "helper", "trusted", "everyone");

    if ((args.length == 2) && recipients.contains(args[0].toLowerCase())) {

        if (PlotMain.hasPermission(plr, "plots.comment." + args[0].toLowerCase())) {
            final String text = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
            final PlotComment comment = new PlotComment(text, plr.getName(),
                    recipients.indexOf(args[0].toLowerCase()));
            plot.settings.addComment(comment);

            DBFunc.setComment(plr.getWorld().getName(), plot, comment);

            return true;
        } else {
            return sendMessage(plr, C.NO_PERMISSION, "plots.comment." + args[0].toLowerCase());
        }
    }
    return sendMessage(plr, C.COMMENT_SYNTAX);
}

From source file:com.intuit.wasabi.tests.service.assignment.DailyAssignmentCountsTest.java

/**
 * Asserts that all priorities are present in the result, then asserts that their order matches the order of the
 * experiment labels.//from  ww w .  jav a  2  s.  c  o m
 *
 * @param experiments the expected experiments
 * @param result      the result
 */
private void assertPriorities(List<Experiment> experiments, Map<String, List<?>> result) {
    Assert.assertTrue(result.containsKey("priorities"), "Expected 'priorities' key.");

    @SuppressWarnings("unchecked")
    List<Integer> priorities = (List<Integer>) result.get("priorities");
    List<Integer> expectedPriorities = experiments.stream()
            .map(experiment -> this.experiments.indexOf(experiment) + 1).collect(Collectors.toList());
    Assert.assertEqualsNoOrder(priorities.toArray(), expectedPriorities.toArray(),
            "Not all experiment priorities are given.");

    @SuppressWarnings("unchecked")
    List<String> experimentLabels = (List<String>) result.get("experiments");
    List<Integer> expectedPrioritiesSorted = experiments.stream()
            .sorted((experiment1, experiment2) -> experimentLabels.indexOf(experiment1.label)
                    - experimentLabels.indexOf(experiment2.label))
            .map(experiment -> this.experiments.indexOf(experiment) + 1).collect(Collectors.toList());
    Assert.assertEquals(priorities, expectedPrioritiesSorted,
            "Priorities and Labels are not in the same order.");
}

From source file:com.haulmont.cuba.gui.config.MenuConfig.java

protected void addItem(List<MenuItem> items, MenuItem menuItem, MenuItem beforeItem, boolean before) {
    if (beforeItem == null) {
        items.add(menuItem);//from   w  ww .  j  a  va 2 s. com
    } else {
        int i = items.indexOf(beforeItem);
        if (before)
            items.add(i, menuItem);
        else
            items.add(i + 1, menuItem);
    }
}

From source file:com.nextep.designer.dbgm.mergers.TableMerger.java

/**
 * @see com.nextep.datadesigner.vcs.impl.Merger#fillObject(com.nextep.datadesigner.model.IReferenceable,
 *      com.nextep.designer.vcs.model.IComparisonItem,
 *      com.nextep.designer.vcs.model.IActivity)
 *//*from ww  w  .  jav a  2 s.  co  m*/
@Override
protected Object fillObject(Object target, IComparisonItem result, IActivity activity) {
    IBasicTable t = (IBasicTable) target;
    log.debug("Starting table <" + t.getName() + "> fill");
    fillName(result, t);

    // Filling temporary flag
    final boolean isTemporary = Boolean.valueOf(getStringProposal(ATTR_TEMPORARY, result));
    t.setTemporary(isTemporary);

    // Monitoring removed tables
    if (t.getName() == null || "".equals(t.getName())) {
        return null;
    }
    t.setShortName(getStringProposal(ATTR_SHORTNAME, result));
    save(t);
    log.debug("Merging columns...");
    List<?> cols = getMergedList(CATEGORY_COLUMNS, result, activity);

    // Adding merged columns
    log.debug("Adding merged columns to table...");
    for (Object r : cols) {
        IBasicColumn c = (IBasicColumn) r;
        c.setParent(t);
        // Bugfix: re-setting column index
        c.setRank(cols.indexOf(c));
        save(c);
        t.addColumn(c);
    }
    log.debug("Merging constraints...");
    List<?> keys = getMergedList(CATEGORY_KEYS, result, activity);

    // Adding merged constraints
    log.debug("Adding merged constraints to table...");
    for (Object r : keys) {
        IKeyConstraint c = (IKeyConstraint) r;
        c.setConstrainedTable(t);
        save(c);
        t.addConstraint(c);
    }
    log.debug("Saving merged table " + t.getName() + ":" + t.getUID());
    save(t);
    return t;
}

From source file:technology.tikal.ventas.controller.almacen.imp.EntradaControllerImp.java

private Entrada[] sortByGroup(List<EntradaOfy> source) {
    List<Entrada> result = new LinkedList<>();
    List<GrupoRegistroAlmacen> grupos = new ArrayList<>();
    for (EntradaOfy x : source) {
        if (x.getProducto() instanceof ProductoDeLinea) {
            ProductoDeLinea p = (ProductoDeLinea) x.getProducto();
            GrupoRegistroAlmacen grupo = new GrupoRegistroAlmacen(x.getPedidoId(), x.getIdProveedor(),
                    p.getLineaDeProductos());
            int index = grupos.indexOf(grupo);
            if (index < 0) {
                result.add(grupo);/*from   ww  w .  j a  v  a 2s.com*/
                grupos.add(grupo);
            } else {
                grupo = grupos.get(index);
            }
            grupo.updateFechaCreacion(x.getFechaDeCreacion());
            grupo.addRegistro(x);
        } else {
            result.add(x);
        }
    }
    Entrada[] response = new Entrada[result.size()];
    result.toArray(response);
    return response;
}

From source file:technology.tikal.ventas.controller.pedido.impl.PartidaControllerImp.java

private Partida[] splitByGroup(List<PartidaOfy> consulta) {
    List<GrupoPartida> grupos = new ArrayList<>();
    List<Partida> result = new LinkedList<>();
    for (PartidaOfy x : consulta) {
        if (x.getProducto() instanceof ProductoDeLinea) {
            ProductoDeLinea p = (ProductoDeLinea) x.getProducto();
            GrupoPartida grupo = new GrupoPartida(x.getPedidoId(), p.getLineaDeProductos());
            int index = grupos.indexOf(grupo);
            if (index < 0) {
                result.add(grupo);/* w  w  w .j  a  v a2 s  .com*/
                grupos.add(grupo);
            } else {
                grupo = grupos.get(index);
            }
            grupo.updateFechaCreacion(x.getFechaDeCreacion());
            grupo.addPartida(x);
        } else {
            result.add(x);
        }
    }
    Partida[] response = new Partida[result.size()];
    result.toArray(response);
    return response;
}

From source file:no.uka.findmyapp.android.rest.client.RestProcessor.java

/**
 * Send to content provider.//  w ww .j  av  a2s  .  co  m
 *
 * @param uri the uri
 * @param object the object
 * @param returnType the return type
 */
private void sendToContentProvider(Uri uri, Serializable object, String returnType) {
    Log.v(debug, "sendToContentProvider: serializable object " + object.getClass().getName());

    ContentResolver cr = mContext.getContentResolver();

    if (object instanceof List) {

        Class theClass = null;
        try {
            theClass = Class.forName(returnType);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        List<ContentValues> list = ContentHelper.getContentValuesList(object, theClass);
        Log.v(debug, "parsing contentvalue array");
        ContentValues[] cva = new ContentValues[list.size()];
        for (ContentValues cv : list) {
            cva[list.indexOf(cv)] = cv;
        }
        Log.v(debug, cva.toString());
        cr.bulkInsert(UkaEventContract.EVENT_CONTENT_URI, cva);
    } else {
        ContentValues cv = new ContentValues(ContentHelper.getContentValues(object));
        cr.insert(uri, cv);
    }
}