Example usage for java.util List subList

List of usage examples for java.util List subList

Introduction

In this page you can find the example usage for java.util List subList.

Prototype

List<E> subList(int fromIndex, int toIndex);

Source Link

Document

Returns a view of the portion of this list between the specified fromIndex , inclusive, and toIndex , exclusive.

Usage

From source file:edu.mit.mobile.android.locast.data.TaggableItem.java

/**
 * TODO make this pick the set of tags for a set of content.
 *
 * @param cr a content resolver//  ww w .  java  2  s  .  com
 * @return the top MAX_POPULAR_TAGS most popular tags in the set, with the most popular first.
 */
public static List<String> getPopularTags(ContentResolver cr) {

    final Map<String, Integer> tagPop = new HashMap<String, Integer>();
    final List<String> popTags;

    final Cursor c = cr.query(Tag.CONTENT_URI, Tag.DEFAULT_PROJECTION, null, null, null);
    final int tagColumn = c.getColumnIndex(Tag._NAME);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        final String tag = c.getString(tagColumn);

        final Integer count = tagPop.get(tag);
        if (count == null) {
            tagPop.put(tag, 1);
        } else {
            tagPop.put(tag, count + 1);
        }
    }
    c.close();

    popTags = new ArrayList<String>(tagPop.keySet());

    Collections.sort(popTags, new Comparator<String>() {
        public int compare(String object1, String object2) {
            return tagPop.get(object2).compareTo(tagPop.get(object1));
        }

    });
    int limit;
    if (popTags.size() < MAX_POPULAR_TAGS) {
        limit = popTags.size();
    } else {
        limit = MAX_POPULAR_TAGS;
    }
    return popTags.subList(0, limit);
}

From source file:no.ntnu.okse.web.controller.LogController.java

/**
 * This method returns the log given the request parameters
 *
 * @param logID    The log file to return (represented as a integer)
 * @param logLevel The log level to show
 * @param length   How many lines to return
 * @return A Log model containing the correct log. Will be serialized as JSON
 *///from ww w  .ja  v a2 s .com
@RequestMapping(method = RequestMethod.GET)
public Log log(@RequestParam(value = "logID", defaultValue = "0") Integer logID,
        @RequestParam(value = "logLevel", defaultValue = "DEBUG") String logLevel,
        @RequestParam(value = "length", defaultValue = "250") int length) {

    try {
        Stream<String> l = Files.lines(Paths.get("logs/", fileNames.get(logID)));

        List<String> lines = l.filter(x -> isWithinLogLevel(logLevel, x)).collect(Collectors.toList());
        Collections.reverse(lines);

        Log log;

        if (lines.size() > length) {
            log = new Log(fileNames.get(logID), lines.subList(0, length));
        } else {
            log = new Log(fileNames.get(logID), lines);
        }

        return log;

    } catch (IOException e) {
        Log log = new Log("Does not exists", new ArrayList<String>() {
            {
                add("The logfile you requested do not exist.");
            }
        });
        return log;
    }
}

From source file:ph.fingra.statisticsweb.service.DistributionServiceImpl.java

@Override
public TopResolutionData getResolutionDailyData(FingraphSearchParam searchParam) {
    TopResolutionData data = new TopResolutionData();

    List<String> rTopNList = distributionDao.getResolutionDailyTopNList(searchParam);
    if (rTopNList.size() > 0) {

        if (rTopNList.size() > 5) {
            searchParam.setTopNList(rTopNList.subList(0, searchParam.getTopN()));
            searchParam.setOthers(true);
        } else {/*from ww  w  .  j  a  v a  2  s  . com*/
            searchParam.setTopNList(rTopNList);
            searchParam.setOthers(false);
        }

        List<ResolutionData> sumList = distributionDao.getResolutionDailySum(searchParam);
        data.setSumList(sumList);
        List<ResolutionTimeSeriesData> rtsList = distributionDao
                .getResolutionDailyTimeSeriesDataList(searchParam);
        data.setRtsList(rtsList);
    }

    return data;
}

From source file:ph.fingra.statisticsweb.service.DistributionServiceImpl.java

@Override
public TopResolutionData getResolutionWeeklyData(FingraphSearchParam searchParam) {
    TopResolutionData data = new TopResolutionData();

    List<String> rTopNList = distributionDao.getResolutionWeeklyTopNList(searchParam);
    if (rTopNList.size() > 0) {

        if (rTopNList.size() > 5) {
            searchParam.setTopNList(rTopNList.subList(0, searchParam.getTopN()));
            searchParam.setOthers(true);
        } else {/*from w w w .j a  v  a 2s.c  o  m*/
            searchParam.setTopNList(rTopNList);
            searchParam.setOthers(false);
        }

        List<ResolutionData> sumList = distributionDao.getResolutionWeeklySum(searchParam);
        data.setSumList(sumList);
        List<ResolutionTimeSeriesData> rtsList = distributionDao
                .getResolutionWeeklyTimeSeriesDataList(searchParam);
        data.setRtsList(rtsList);
    }

    return data;
}

From source file:ph.fingra.statisticsweb.service.DistributionServiceImpl.java

@Override
public TopResolutionData getResolutionMonthlyData(FingraphSearchParam searchParam) {
    TopResolutionData data = new TopResolutionData();

    List<String> rTopNList = distributionDao.getResolutionMonthlyTopNList(searchParam);
    if (rTopNList.size() > 0) {

        if (rTopNList.size() > 5) {
            searchParam.setTopNList(rTopNList.subList(0, searchParam.getTopN()));
            searchParam.setOthers(true);
        } else {/*from  w  w w . j ava 2s.com*/
            searchParam.setTopNList(rTopNList);
            searchParam.setOthers(false);
        }

        List<ResolutionData> sumList = distributionDao.getResolutionMonthlySum(searchParam);
        data.setSumList(sumList);
        List<ResolutionTimeSeriesData> rtsList = distributionDao
                .getResolutionMonthlyTimeSeriesDataList(searchParam);
        data.setRtsList(rtsList);
    }

    return data;
}

From source file:uk.ac.ebi.eva.pipeline.io.writers.VepAnnotationMongoWriter.java

@Override
protected void doWrite(List<? extends VariantAnnotation> variantAnnotations) {

    Map<String, List<VariantAnnotation>> variantAnnotationsByStorageId = groupVariantAnnotationById(
            variantAnnotations);/*  w  w  w.j  av a  2s. c  o m*/

    for (Map.Entry<String, List<VariantAnnotation>> annotationsIn : variantAnnotationsByStorageId.entrySet()) {
        String storageId = annotationsIn.getKey();
        List<VariantAnnotation> annotations = annotationsIn.getValue();

        VariantAnnotation variantAnnotation = annotations.get(0);

        if (annotations.size() > 1) {
            variantAnnotation = concatenateOtherAnnotations(variantAnnotation,
                    annotations.subList(1, annotations.size()));
        }

        writeVariantAnnotationInMongoDb(storageId, variantAnnotation);
    }

}

From source file:com.almende.eve.agent.TestScaleAgent.java

/**
 * Instantiates a new test scale agent.//from   w w  w. ja  va 2s  . co m
 *
 * @param id
 *            the id
 * @param config
 *            the config
 * @param parent
 *            the parent
 * @param nofChildren
 *            the nof children
 */
public TestScaleAgent(final String id, final Config config, final URI parent, final List<Integer> nofChildren) {
    super(id, config);
    this.parent = parent;
    getState().put("key", "value");
    if (nofChildren.size() > 0) {
        for (int i = 0; i < nofChildren.get(0); i++) {
            Agent newAgent = new TestScaleAgent(id + "_" + i, config, getUrls().get(0),
                    nofChildren.subList(1, nofChildren.size()));
            children.add(newAgent.getUrls().get(0));
        }
    }
}

From source file:com.abixen.platform.service.businessintelligence.multivisualization.service.impl.AbstractDatabaseService.java

public List<Map<String, DataValueWeb>> getChartDataPreview(Connection connection,
        DatabaseDataSource databaseDataSource, ChartConfigurationForm chartConfigurationForm,
        String seriesName) {/*from w w w .  j a v  a 2  s . c o  m*/
    Set<String> chartColumnsSet = getDomainColumn(chartConfigurationForm);

    chartConfigurationForm.getDataSetChart().getDataSetSeries().forEach(dataSetSeries -> {
        if (dataSetSeries.getName().equals(seriesName)) {
            chartColumnsSet.add(dataSetSeries.getValueSeriesColumn().getDataSourceColumn().getName());
        }
    });

    if (chartColumnsSet.isEmpty()) {
        return new ArrayList<>();
    }
    //FixMe
    List<Map<String, DataValueWeb>> data = getData(connection, databaseDataSource, chartColumnsSet,
            chartConfigurationForm);
    return data.subList(0, data.size() < chartLimit ? data.size() : chartLimit);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.datareports.service.DatareportsServiceImpl.java

public List<X> getPaginatedList(final List<X> list, final int start, final int limit) {
    int page = (start + limit);
    if (page > getTotalCount(list)) {
        page = getTotalCount(list);/*from   w w w . j av a2 s  . c  om*/
    }
    return (page != 0) ? list.subList(start, page) : list;
}

From source file:de.widone.web.page.home.HomePage.java

@Override
public void onEvent(IEvent<?> event) {
    super.onEvent(event);
    if (event.getPayload() instanceof ChangeTaskPositionEvent) {
        ChangeTaskPositionEvent changePosEvent = (ChangeTaskPositionEvent) event.getPayload();
        Task task = changePosEvent.getTask();
        List<Task> tasks = changePosEvent.getTaskList().getTasks();
        Integer newPos = changePosEvent.getNewPosition();
        Integer oldPos = tasks.indexOf(task);
        if (newPos < 0 || newPos >= tasks.size()) {
            return;
        }//from w  w w  .  j a  v  a  2  s  .  c  o m
        tasks.remove(task);
        List<Task> sublist = new ArrayList<Task>(tasks.subList(newPos, tasks.size()));
        tasks.removeAll(sublist);
        tasks.add(task);
        tasks.addAll(sublist);
        ((IModel<TaskList>) getDefaultModel()).setObject(taskListService.update(changePosEvent.getTaskList()));
    } else if (event.getPayload() instanceof DoneTaskEvent) {
        DoneTaskEvent deleteTaskEvent = (DoneTaskEvent) event.getPayload();
        TaskList taskList = deleteTaskEvent.getTaskList();
        taskList.getTasks().remove(deleteTaskEvent.getTask());
        ((IModel<TaskList>) getDefaultModel()).setObject(taskListService.update(taskList));
    } else if (event.getPayload() instanceof DeleteTaskEvent) {
        DeleteTaskEvent deleteTaskEvent = (DeleteTaskEvent) event.getPayload();
        TaskList taskList = deleteTaskEvent.getTaskList();
        taskList.getTasks().remove(deleteTaskEvent.getTask());
        ((IModel<TaskList>) getDefaultModel()).setObject(taskListService.update(taskList));
    } else if (event.getPayload() instanceof NewTaskEvent) {
        NewTaskEvent newTaskEvent = (NewTaskEvent) event.getPayload();
        ((IModel<TaskList>) getDefaultModel()).setObject(taskListService.addTaskToTaskList(
                newTaskEvent.getNewTask(), ((IModel<TaskList>) getDefaultModel()).getObject()));
    } else if (event.getPayload() instanceof NewTaskListEvent) {
        NewTaskListEvent newTaskListEvent = (NewTaskListEvent) event.getPayload();
        User user = userService.initTaskLists(new CurrentUserModel().getObject());
        user.getTaskLists().add(newTaskListEvent.getNewTaskList());
        userService.update(user);
    }
}