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.wallride.web.controller.admin.article.ArticleDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = articleService.getArticleById(id);
    if (article == null) {
        throw new HttpNotFoundException();
    }/*from   ww  w  .j a va  2 s  . c  om*/

    if (!article.getLanguage().equals(language)) {
        Article target = articleService.getArticleByCode(article.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/articles/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", article);
            redirectAttributes.addAttribute("code", article.getCode());
            return "redirect:/_admin/{language}/articles/create?code={code}";
        }
    }

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new ArticleSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    ArticleSearchForm form = (ArticleSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = articleService.getArticleIds(form.toArticleSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(article.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("article", article);
    model.addAttribute("query", query);
    return "article/describe";
}

From source file:org.wallride.web.controller.guest.article.ArticleDescribeController.java

@RequestMapping
public String describe(@PathVariable int year, @PathVariable int month, @PathVariable int day,
        @PathVariable String code, BlogLanguage blogLanguage, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = articleService.getArticleByCode(code, blogLanguage.getLanguage());
    if (article == null) {
        article = articleService.getArticleByCode(code, blogLanguage.getBlog().getDefaultLanguage());
    }/* ww w  .  j a  va 2  s  .  co m*/
    if (article == null) {
        throw new HttpNotFoundException();
    }
    if (article.getStatus() != Post.Status.PUBLISHED) {
        throw new HttpNotFoundException();
    }

    LocalDate date = LocalDate.of(year, month, day);
    if (!article.getDate().toLocalDate().equals(date)) {
        redirectAttributes.addAttribute("year", article.getDate().getYear());
        redirectAttributes.addAttribute("month", article.getDate().getMonth().getValue());
        redirectAttributes.addAttribute("day", article.getDate().getDayOfMonth());
        redirectAttributes.addAttribute("code", code);
        return "redirect:/{year}/{month}/{day}/{code}";
    }

    CommentSearchRequest request = new CommentSearchRequest();
    request.setPostId(article.getId());
    request.setApproved(Boolean.TRUE);
    Page<Comment> comments = commentService.getComments(request, new PageRequest(0, 1000));

    List<Long> ids = articleService.getArticleIds(new ArticleSearchRequest().withStatus(Post.Status.PUBLISHED));
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(article.getId());
        if (index < ids.size() - 1) {
            Article next = articleService.getArticleById(ids.get(index + 1));
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Article prev = articleService.getArticleById(ids.get(index - 1));
            model.addAttribute("prev", prev);
        }
    }
    model.addAttribute("article", article);
    model.addAttribute("comments", comments);
    return "article/describe";
}

From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandCallable.java

/**
 * Code to mask passwords in the logs/*  ww w .  ja v a2s .  c  om*/
 */
private String createPrintableCommand(final List<String> cmd) {
    final List<String> cmdToOutput = new ArrayList<>();
    cmdToOutput.addAll(cmd);

    int passwordIndex = cmdToOutput.indexOf("--password");
    if (passwordIndex > -1) {
        // The User's password will be at the next index
        passwordIndex++;
    }

    int proxyPasswordIndex = -1;
    for (int commandIndex = 0; commandIndex < cmdToOutput.size(); commandIndex++) {
        final String commandParameter = cmdToOutput.get(commandIndex);
        if (commandParameter.contains("-Dhttp.proxyPassword=")) {
            proxyPasswordIndex = commandIndex;
        }
    }

    maskIndex(cmdToOutput, passwordIndex);
    maskIndex(cmdToOutput, proxyPasswordIndex);

    return StringUtils.join(cmdToOutput, " ");
}

From source file:edu.uci.ics.asterix.optimizer.rules.FeedScanCollectionToUnnest.java

private ILogicalExpression findVarOriginExpression(LogicalVariable v, ILogicalOperator op)
        throws AlgebricksException {
    boolean searchInputs = false;
    if (!(op instanceof AbstractAssignOperator)) {
        searchInputs = true;//from  w  w  w.j  av a 2  s .com
    } else {
        AbstractAssignOperator aao = (AbstractAssignOperator) op;
        List<LogicalVariable> producedVars = new ArrayList<>();
        VariableUtilities.getProducedVariables(op, producedVars);
        int exprIndex = producedVars.indexOf(v);
        if (exprIndex == -1) {
            searchInputs = true;
        } else {
            ILogicalExpression originalCandidate = aao.getExpressions().get(exprIndex).getValue();
            if (originalCandidate.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                searchInputs = true;
            } else {
                return originalCandidate;
            }
        }
    }

    if (searchInputs) {
        for (Mutable<ILogicalOperator> childOp : op.getInputs()) {
            ILogicalExpression ret = findVarOriginExpression(v, childOp.getValue());
            if (ret != null) {
                return ret;
            }
        }
    }

    throw new IllegalStateException("Unable to find the original expression that produced variable " + v);
}

From source file:org.powertac.producer.ProducerService.java

@Override
public String initialize(Competition competition, List<String> completedInits) {
    int index = completedInits.indexOf("DefaultBroker");
    if (index == -1) {
        return null;
    }/*from   w ww . j av a2s  .com*/

    serverPropertiesService.configureMe(this);
    if (producerFileFolder == null)
        log.error("The supplied configuration path was invalid. Will load default " + "implementations.");
    else
        log.info("The configuration folder is located at: " + producerFileFolder);

    // Clear the list of producers and create new ones
    producerList.clear();

    tariffMarketService.registerNewTariffListener(this);

    try {
        producerList = loadProducers();
    } catch (Exception e) {
        throw new PowerTacException(e);
    }

    // Make sure producers subscribe to the default tariff
    for (Producer producer : producerList)
        producer.subscribeDefault();

    super.init();

    return "Producer";
}

From source file:com.tage.calcite.adapter.druid.DruidQuery.java

static Pair<List<RexNode>, List<RexNode>> splitProjects(final RexBuilder rexBuilder, final RelNode input,
        List<RexNode> nodes) {
    final RelOptUtil.InputReferencedVisitor visitor = new RelOptUtil.InputReferencedVisitor();
    for (RexNode node : nodes) {
        node.accept(visitor);// w w  w .j  ava 2  s  . c  om
    }
    if (visitor.inputPosReferenced.size() == input.getRowType().getFieldCount()) {
        // All inputs are referenced
        return null;
    }
    final List<RexNode> belowNodes = new ArrayList<>();
    final List<Integer> positions = Lists.newArrayList(visitor.inputPosReferenced);
    for (int i : positions) {
        belowNodes.add(rexBuilder.makeInputRef(input, i));
    }
    final List<RexNode> aboveNodes = new ArrayList<>();
    for (RexNode node : nodes) {
        aboveNodes.add(node.accept(new RexShuttle() {
            @Override
            public RexNode visitInputRef(RexInputRef ref) {
                return rexBuilder.makeInputRef(input, positions.indexOf(ref.getIndex()));
            }
        }));
    }
    return Pair.of(aboveNodes, belowNodes);
}

From source file:dataLoader.Loader.java

public List<support.GroupData> summary(List<support.JsonClass> data) {
    List<support.GroupData> community = new ArrayList<>();
    List<String> log = new ArrayList<>();
    support.GroupData temp;/*from w w  w  .  ja va 2s.  c  o m*/
    for (int i = 0; i < data.size(); i++) {
        if (log.contains(data.get(i).getCommunitiesVillages())) {
            temp = community.get(log.indexOf(data.get(i).getCommunitiesVillages()));
            temp.entityIncrease();
        } else {
            log.add(data.get(i).getCommunitiesVillages());
            temp = new support.GroupData(data.get(i).getCommunitiesVillages());
            community.add(temp);
        }

        if (!data.get(i).getWaterFunctioning().equalsIgnoreCase("yes"))
            temp.unusableIncrease();
        else
            temp.usableIncrease();
    }

    return community;
}

From source file:io.cloudslang.content.amazon.factory.helpers.VolumeUtils.java

@NotNull
private Map<String, String> getVolumedIdsQueryMap(@NotNull final InputsWrapper wrapper) {
    final String[] volumeIds = getArrayWithoutDuplicateEntries(wrapper.getVolumeInputs().getVolumeIdsString(),
            VOLUME_IDS_STRING, wrapper.getCommonInputs().getDelimiter());
    final Map<String, String> volumeIdsQueryMap = new HashMap<>();
    if (isNotEmpty(volumeIds)) {
        final List<String> volumeIdsList = Arrays.asList(volumeIds);
        for (final String id : volumeIdsList) {
            final String key = String.format(VOLUME_ID_FORMAT, volumeIdsList.indexOf(id) + 1);
            setOptionalMapEntry(volumeIdsQueryMap, key, id, StringUtils.isNotEmpty(id));
        }//from ww  w  . j  av  a  2  s. c o  m
    }
    return volumeIdsQueryMap;
}

From source file:net.rrm.ehour.timesheet.service.TimesheetPersistance.java

private TimesheetEntry getEntry(List<TimesheetEntry> entries, TimesheetEntry entry) {
    int index = entries.indexOf(entry);

    if (index >= 0) {
        return entries.get(index);
    } else {//from  www  . j  a v a  2  s.c om
        return null;
    }
}