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:org.easit.core.controllers.twitter.TwitterTimelineController.java

@RequestMapping(value = "/twitter/timeline/{timelineType}", method = RequestMethod.GET)
public String showTimeline(@PathVariable("timelineType") String timelineType, Model model, String offset) {
    int int_page = 1;
    if (offset != null) {
        int_page = Integer.valueOf(offset);
    }//from   w w w  .  j  a v  a 2 s. c o  m
    if (timelineType.equals("Home")) {
        int fromIndex = (int_page - 1) * PSMetadata.TWITTER_LIMIT_RESULT;
        int toIndex = fromIndex + PSMetadata.TWITTER_LIMIT_RESULT;

        List<Tweet> tweets = twitter.timelineOperations().getHomeTimeline(200);
        toIndex = Math.min(toIndex, tweets.size());

        model.addAttribute("timeline", tweets.subList(fromIndex, toIndex));
        model.addAttribute("pageSize", twitter.timelineOperations().getHomeTimeline().size());

    } else if (timelineType.equals("User")) {
        int fromIndex = (int_page - 1) * PSMetadata.TWITTER_LIMIT_RESULT;
        int toIndex = fromIndex + PSMetadata.TWITTER_LIMIT_RESULT;

        List<Tweet> tweets = twitter.timelineOperations().getUserTimeline(200);
        toIndex = Math.min(toIndex, tweets.size());

        model.addAttribute("timeline", tweets.subList(fromIndex, toIndex));
        model.addAttribute("pageSize", twitter.timelineOperations().getHomeTimeline().size());

    } else if (timelineType.equals("Mentions")) {
        int fromIndex = (int_page - 1) * PSMetadata.TWITTER_LIMIT_RESULT;
        int toIndex = fromIndex + PSMetadata.TWITTER_LIMIT_RESULT;

        List<Tweet> mentions = twitter.timelineOperations().getMentions(200);
        toIndex = Math.min(toIndex, mentions.size());

        model.addAttribute("timeline", mentions.subList(fromIndex, toIndex));
        model.addAttribute("pageSize", twitter.timelineOperations().getHomeTimeline().size());

    } else if (timelineType.equals("Favorites")) {
        int fromIndex = (int_page - 1) * PSMetadata.TWITTER_LIMIT_RESULT;
        int toIndex = fromIndex + PSMetadata.TWITTER_LIMIT_RESULT;

        List<Tweet> favorits = twitter.timelineOperations().getFavorites(200);
        toIndex = Math.min(toIndex, favorits.size());

        model.addAttribute("timeline", favorits.subList(fromIndex, toIndex));
        model.addAttribute("pageSize", twitter.timelineOperations().getHomeTimeline().size());
    }
    model.addAttribute("timelineName", timelineType);
    model.addAttribute(new UploadItem());
    model.addAttribute("offset", int_page);
    return "twitter/timeline";
}

From source file:com.vrem.wifianalyzer.wifi.graphutils.SeriesCacheTest.java

@Test
public void tesDifferenceExpectOneLess() {
    // setup/*w w w  . ja  va 2s . com*/
    List<WiFiDetail> expected = withData();
    // execute
    List<WiFiDetail> actual = fixture.difference(new TreeSet<>(expected.subList(0, 1)));
    // validate
    assertEquals(expected.size() - 1, actual.size());
    for (int i = 1; i < expected.size(); i++) {
        assertEquals(expected.get(i), actual.get(i - 1));
    }
}

From source file:com.ewcms.component.online.service.OnlineService.java

public String mainJSON() {
    List<Working> workings = workingDAO.getRootChildren();
    if (workings.isEmpty()) {
        return "[]";
    }/*from   w  ww.ja  va2 s . c om*/
    workings = workings.size() > 3 ? workings.subList(0, 3) : workings;
    for (Working working : workings) {
        Integer id = working.getId();
        List<Working> children = workingDAO.getChildren(id);
        working.setChildren(children);
    }

    StringBuilder builder = new StringBuilder();
    builder.append("[");
    for (Working working : workings) {
        builder.append("{");
        builder.append("\"id\":").append(working.getId()).append(",");
        builder.append("\"name\":\"").append(working.getName()).append("\",");
        builder.append("\"children\":").append(childrenJSON(working.getChildren()));
        builder.append("},");
    }
    builder.deleteCharAt(builder.length() - 1);
    builder.append("]");

    return builder.toString();
}

From source file:org.openmrs.module.uiframeworkpatientsummarysupport.fragment.controller.PatientObsFlowsheetFragmentController.java

public void controller(FragmentModel model, @FragmentParam(value = "patientId") Patient patient,
        @FragmentParam(value = "conceptIds") ArrayList<Concept> questionConcepts,
        @FragmentParam(value = "withinDays", required = false) Integer withinDays,
        @FragmentParam(value = "maximumNumber", required = false) Integer maximumNumber) {

    List<Person> persons = new ArrayList<Person>();
    persons.add(patient);//from  w w w.j  a v  a 2 s .  c om

    List<PERSON_TYPE> personTypes = new ArrayList<PERSON_TYPE>();
    personTypes.add(PERSON_TYPE.PATIENT);

    //we want the latest obs to be displayed at the top
    List<String> sortList = new ArrayList<String>();
    sortList.add("obsDatetime");

    Date fromDate = null;
    if (withinDays != null) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, -withinDays);
        fromDate = startOfDay(cal.getTime());
    }

    List<Obs> observations = Context.getObsService().getObservations(persons, null, questionConcepts, null,
            personTypes, null, sortList, null, null, fromDate, null, false);
    if (maximumNumber != null)
        observations = observations.subList(0, maximumNumber);

    Map<Concept, List<Obs>> conceptObsMap = new HashMap<Concept, List<Obs>>();
    for (Obs o : observations) {
        if (!conceptObsMap.containsKey(o.getConcept()))
            conceptObsMap.put(o.getConcept(), new ArrayList<Obs>());

        conceptObsMap.get(o.getConcept()).add(o);
    }

    model.addAttribute("conceptObsMap", conceptObsMap);
}

From source file:de.taimos.dao.hibernate.EntityDAOMock.java

@Override
public List<E> findList(final int first, final int max) {
    List<E> values = new ArrayList<>(this.entities.values());
    this.sortById(values);

    if (first >= 0) {
        if (max >= 0) {
            return Collections.unmodifiableList(values.subList(first, Math.max(first + max, values.size())));
        }/*  ww w  . j  av a  2s.  c o m*/
        return Collections.unmodifiableList(values.subList(first, values.size()));
    }
    if (max >= 0) {
        return Collections.unmodifiableList(values.subList(0, Math.max(first + max, values.size())));
    }
    return Collections.unmodifiableList(values);
}

From source file:net.naijatek.myalumni.util.taglib.DisplayRSSTag.java

/**
 * Process the end of this tag.//from www. java2 s. com
 *
 * @throws JspException if a JSP exception has occurred
 * @return int
 */
@Override
public final int doEndTag() throws JspException {

    request = (HttpServletRequest) pageContext.getRequest();
    StringBuffer sb = new StringBuffer();
    AppProp ap = AppProp.getInstance();

    SystemConfigVO feed = sysConfigService.getRssFeedSource();
    int limit;
    try {
        limit = Integer.parseInt(getMaxNumberToDisplay());
    } catch (NumberFormatException nfe) {
        limit = 5;
    }

    try {
        // Next, we read the fed input.
        URL feedUrl = new URL(feed.getRssUrl());
        //System.out.println(feedUrl);
        SyndFeedInput input = new SyndFeedInput();

        XmlReader reader = new XmlReader(feedUrl);
        SyndFeed feeder = input.build(reader);

        List feederEntries = feeder.getEntries();
        int end = feederEntries.size();
        end = (end < limit) ? end : limit;

        List selectedNewsEntries = feederEntries.subList(0, end);

        // We then set this selected news in our feed source.
        request.setAttribute("readNews", feederEntries);
        request.setAttribute("rssHeader", feed.getRssHeader());
    } catch (Exception e) {
        sb.append(ap.getValue("core.errorcode.00707"));//Problem encountered while retrieving rss feeds
        System.out.println(e.getMessage());
    }

    return EVAL_PAGE;
}

From source file:com.hpe.application.automation.tools.octane.executor.UftTestDiscoveryDispatcher.java

private static boolean postScmResources(MqmRestClient client, List<ScmResourceFile> resources,
        String workspaceId, String scmResourceId) {

    if (!resources.isEmpty()) {
        try {//  w ww . jav  a2s .  c  om
            completeScmResourceProperties(resources, scmResourceId);
        } catch (RequestErrorException e) {
            logger.error("Failed to completeScmResourceProperties : " + e.getMessage());
            return false;
        }

        for (int i = 0; i < resources.size(); i += POST_BULK_SIZE)
            try {
                ScmResources data = ScmResources
                        .createWithItems(resources.subList(i, Math.min(i + POST_BULK_SIZE, resources.size())));
                String uftTestJson = convertToJsonString(data);
                client.postEntities(Long.parseLong(workspaceId), OctaneConstants.DataTables.COLLECTION_NAME,
                        uftTestJson);
            } catch (RequestErrorException e) {
                return checkIfExceptionCanBeIgnoredInPOST(e, "Failed to post scm resource files");
            }
    }
    return true;
}

From source file:org.apache.drill.optiq.DrillJoinRel.java

@Override
public int implement(DrillImplementor implementor) {
    final List<String> fields = getRowType().getFieldNames();
    assert isUnique(fields);
    final int leftCount = left.getRowType().getFieldCount();
    final List<String> leftFields = fields.subList(0, leftCount);
    final List<String> rightFields = fields.subList(leftCount, fields.size());

    final int leftId = implementInput(implementor, 0, 0, left);
    final int rightId = implementInput(implementor, 1, leftCount, right);

    /*/*from  ww  w  .j a v  a  2  s  . c  o m*/
     * E.g. { op: "join", left: 2, right: 4, conditions: [ {relationship: "==", left: "deptId", right: "deptId"} ] }
     */
    final ObjectNode join = implementor.mapper.createObjectNode();
    join.put("op", "join");
    join.put("left", leftId);
    join.put("right", rightId);
    join.put("type", toDrill(joinType));
    final ArrayNode conditions = implementor.mapper.createArrayNode();
    join.put("conditions", conditions);
    for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
        final ObjectNode condition = implementor.mapper.createObjectNode();
        condition.put("relationship", "==");
        condition.put("left", leftFields.get(pair.left));
        condition.put("right", rightFields.get(pair.right));
        conditions.add(condition);
    }
    return implementor.add(join);
}

From source file:net.sourceforge.atunes.kernel.modules.playlist.M3UPlayListReader.java

private List<String> readUntilFirstUncommentedLine(final List<String> lines) {
    int i = 0;/*  w w  w. j  a va2s  .c o  m*/
    for (String line : lines) {
        i++;
        if (line.startsWith(M3U_START_COMMENT)) {
            break;
        }
    }
    return lines.subList(i, lines.size());
}

From source file:com.esri.geoportal.harvester.waf.WafFolder.java

/**
 * Matches URL/*from ww  w  .j  ava 2s.co m*/
 * @param u url
 * @param pattern match patter (glob)
 * @return <code>true</code> if URL matches the pattern
 */
private boolean matchUrl(URL u, String pattern) {
    String[] split = u.getPath().split("(/|\\\\)+");
    List<String> items = Arrays.asList(split).stream().filter(s -> s != null && !s.isEmpty())
            .collect(Collectors.toList());
    if (!items.isEmpty()) {
        String first = items.get(0);
        List<String> subList = items.subList(1, items.size());
        Path path = fileSystem.getPath(first, subList.toArray(new String[] {}));
        PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + pattern);
        return pathMatcher.matches(path);
    } else {
        return false;
    }
}