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.shredzone.cilla.view.GalleryView.java

/**
 * Shows a single picture of a gallery./*  w ww.  j  a v a  2 s  . c om*/
 */
@Framed
@View(pattern = "/show/gallery/${section.id}/picture/${picture.id}.html", signature = { "section", "picture" })
@View(pattern = "/ajax/gallery/${section.id}/picture/${picture.id}.html", signature = { "section",
        "picture" }, qualifier = "ajax")
public String galleryPictureView(@PathPart("section.id") GallerySection section,
        @PathPart("picture.id") Picture picture, @Qualifier String qualifier, HttpServletRequest req,
        HttpServletResponse resp) throws ViewException {
    if (!pageService.isVisible(section.getPage())) {
        throw new ErrorResponseException(HttpServletResponse.SC_FORBIDDEN);
    }

    commentFormHandler.handleComment(picture, req, section.isCommentable());

    List<Picture> pictureList = section.getPictures();
    int size = pictureList.size();
    int current = pictureList.indexOf(picture);

    if (current < 0 || size == 0) {
        // There is such a picture, but not in this gallery!
        throw new PageNotFoundException("No such picture in this gallery.");
    }

    if (redirectRestricted(section.getPage(), req, resp)) {
        return null;
    }

    req.setAttribute("page", section.getPage());
    req.setAttribute("section", section);
    req.setAttribute("picture", picture);
    req.setAttribute("info", new PictureInfoModel(pictureList, current));

    if ("ajax".equals(qualifier)) {
        return "section/gallery/picture-ajax.jsp";
    } else {
        return "section/gallery/picture.jsp";
    }
}

From source file:org.wallride.web.controller.admin.page.PageDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Page page = pageService.getPageById(id);
    if (page == null) {
        throw new HttpNotFoundException();
    }/*  w  w  w.  ja  v a 2 s.c  o  m*/

    if (!page.getLanguage().equals(language)) {
        Page target = pageService.getPageByCode(page.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/pages/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", page);
            redirectAttributes.addAttribute("code", page.getCode());
            return "redirect:/_admin/{language}/pages/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 PageSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    PageSearchForm form = (PageSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = pageService.getPageIds(form.toPageSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(page.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("page", page);
    model.addAttribute("query", query);
    return "page/describe";
}

From source file:com.netflix.ice.basic.AppnetaMapDbResourceService.java

protected String getEc2Resource(Account account, Region region, Product product, String resourceId,
        String[] lineItem, long millisStart) {
    // Creator, Name, Role are predefined tags in AWS, we use creator, Name, role
    // guard against old files that don't have our tags, or tags defined (basically, pre July 2013)
    if (lineItem.length <= config.lineItemProcessor.getUserTagStartIndex()) {
        return UNKNOWN;
    }/* www  .  j  av a  2s  .c  o m*/
    // use customTags to make tag collection easier
    // TODO: this could be smarter, if we have more than one tag defined on a line item, it'll end up
    //       producint value1_value2

    // copied from BasicResourceService.getResource()
    List<String> header = config.lineItemProcessor.getHeader();

    String result = "";
    for (String tag : config.customTags) {
        int index = header.indexOf(tag);
        if (index > 0 && lineItem.length > index && !StringUtils.isEmpty(lineItem[index]))
            result = StringUtils.isEmpty(result) ? lineItem[index] : result + "_" + lineItem[index];
    }

    if (StringUtils.isEmpty(result)) {
        return UNKNOWN;
    } else {
        instanceDb.SetResource(account, region, resourceId, result, millisStart);
        logger.debug("resource set, result added, probably role name. resourceId: {}, result: {}", resourceId,
                result);
        return result;
    }
}

From source file:org.cds06.speleograph.data.fileio.SpeleoFileWriter.java

private void writeSeries(List<Series> series, Integer[][] columns) {
    for (Series s : series) {
        int seriesId = series.indexOf(s);
        switch (columns[seriesId].length) {
        case 1://from  w ww  . j  a v  a  2  s .c  o m
            writeColumn(columns[seriesId][0], s);
            break;
        case 2:
            writeMinMaxColumn(columns[seriesId], s);
            break;
        default:

        }
    }
}

From source file:cs.register.geraGrafico.java

private XYSeriesCollection datakda(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, (p.getKill() / p.getDeath()));
    }/*w  ww . j a  v  a  2s .com*/
    data.addSeries(ser);

    return data;
}

From source file:cs.register.geraGrafico.java

private XYSeriesCollection datawld(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, (p.getWld()));
    }/*from  ww  w . ja  v a 2 s .c  o  m*/
    data.addSeries(ser);

    return data;
}

From source file:cs.register.geraGrafico.java

private XYSeriesCollection datasocore(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, p.getScore());
    }/*from w  w  w .j av a  2  s .  c o m*/
    data.addSeries(ser);

    return data;
}

From source file:cs.register.geraGrafico.java

private XYSeriesCollection datakill(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, p.getKill());
    }//  ww w . j ava  2  s  .co  m
    data.addSeries(ser);

    return data;
}

From source file:cs.register.geraGrafico.java

private XYDataset datarank(List<partida> list1) {
    XYSeriesCollection data = new XYSeriesCollection();
    XYSeries ser = new XYSeries("kda");
    for (partida p : list1) {
        ser.add(list1.indexOf(p) + 1, p.getRank());
    }/*from   w w  w.  j av  a 2  s.c o  m*/
    data.addSeries(ser);

    return data;
}

From source file:de.ingrid.iplug.opensearch.converter.RankingModifierLinear.java

@Override
public float getNormalizedRanking(IngridHit hit) {
    float scoreInRange = normalizeScoreToConfigRange(hit.getScore());

    // Get position of passed hit in list of hits with same score.
    List<IngridHit> hitsWithSameScoreList = hitsWithSameScoreLists.get(scoreInRange);
    int hitPositionInList = hitsWithSameScoreList.indexOf(hit);
    int numHitsInList = hitsWithSameScoreList.size();

    // max and min value of score from configuration
    Float configMaxOfScore = 1.0f;
    Float configMinOfScore = 0.0f;
    List<Float> configMaxMinOfScore = configMap.get(scoreInRange);
    if (configMaxMinOfScore != null && configMaxMinOfScore.size() > 1) {
        configMaxOfScore = configMaxMinOfScore.get(0);
        configMinOfScore = configMaxMinOfScore.get(1);
    } else {/*from www  .  j a  v  a 2 s.  c  o m*/
        log.warn("NO config MAX/MIN set for score: " + scoreInRange + ", WE USE 1.0/0.0");
    }

    // compute new score
    float newScore = configMinOfScore
            + (((configMaxOfScore - configMinOfScore) / numHitsInList) * (numHitsInList - hitPositionInList));

    if (log.isDebugEnabled()) {
        log.debug("score of Hit: " + hit.getScore());
        log.debug("score of Hit mapped to config score range: " + scoreInRange);
        log.debug("score MEDIAN from config: " + configMaxOfScore);
        log.debug("score MIN from config: " + configMinOfScore);
        log.debug("list of hits same score, numHitsInList: " + numHitsInList);
        log.debug("list of hits same score, hitPositionInList: " + hitPositionInList);
        log.debug("MIN + ( ((MEDIAN - MIN) / numHitsInList) * (numHitsInList - hitPositionInList) ): "
                + newScore);
    }

    return newScore;
}