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:ca.nines.ise.cmd.Command.java

/**
 * Get a list of arguments for the command.
 *
 * @param cmd// ww  w. j  a  v a 2 s.  c  o  m
 * @return String[]
 */
public String[] getArgList(CommandLine cmd) {
    List<?> argList = cmd.getArgList();
    argList = argList.subList(1, argList.size());
    String[] args = argList.toArray(new String[argList.size()]);
    return args;
}

From source file:c5db.tablet.tabletCreationBehaviors.RootTabletLeaderBehavior.java

private List<Long> shuffleListAndReturnMetaRegionPeers(final List<Long> peers) {
    Collections.shuffle(new ArrayList<>(peers));
    return peers.subList(0, (int) numberOfMetaPeers);
}

From source file:com.bigdata.dastor.service.StorageProxy.java

public static List<Row> getRangeSlice(RangeSliceCommand command, ConsistencyLevel consistency_level)
        throws IOException, UnavailableException, TimeoutException {
    if (logger.isDebugEnabled())
        logger.debug(command);/*from  ww w.  j  av  a2 s .c  o m*/
    long startTime = System.nanoTime();

    final String table = command.keyspace;
    int responseCount = determineBlockFor(DatabaseDescriptor.getReplicationFactor(table), consistency_level);

    List<AbstractBounds> ranges = getRestrictedRanges(command.range);

    // now scan until we have enough results
    List<Row> rows = new ArrayList<Row>(command.max_keys);
    for (AbstractBounds range : ranges) {
        List<InetAddress> liveEndpoints = StorageService.instance.getLiveNaturalEndpoints(command.keyspace,
                range.right);
        if (liveEndpoints.size() < responseCount)
            throw new UnavailableException();
        DatabaseDescriptor.getEndPointSnitch(command.keyspace).sortByProximity(FBUtilities.getLocalAddress(),
                liveEndpoints);
        List<InetAddress> endpoints = liveEndpoints.subList(0, responseCount);

        RangeSliceCommand c2 = new RangeSliceCommand(command.keyspace, command.column_family,
                command.super_column, command.predicate, range, command.max_keys);
        Message message = c2.getMessage();

        // collect replies and resolve according to consistency level
        RangeSliceResponseResolver resolver = new RangeSliceResponseResolver(command.keyspace, endpoints,
                StorageService.getPartitioner());
        QuorumResponseHandler<List<Row>> handler = new QuorumResponseHandler<List<Row>>(responseCount,
                resolver);

        for (InetAddress endpoint : endpoints) {
            MessagingService.instance.sendRR(message, endpoint, handler);
            if (logger.isDebugEnabled())
                logger.debug("reading " + c2 + " from " + message.getMessageId() + "@" + endpoint);
        }
        // TODO read repair on remaining replicas?

        // if we're done, great, otherwise, move to the next range
        try {
            if (logger.isDebugEnabled()) {
                for (Row row : handler.get()) {
                    logger.debug("range slices read " + row.key);
                }
            }
            rows.addAll(handler.get());
        } catch (DigestMismatchException e) {
            throw new AssertionError(e); // no digests in range slices yet
        }
        if (rows.size() >= command.max_keys)
            break;
    }

    rangeStats.addNano(System.nanoTime() - startTime);
    return rows.size() > command.max_keys ? rows.subList(0, command.max_keys) : rows;
}

From source file:mondrian.rolap.RolapMemberBase.java

/**
 * Sets member ordinal values using a Bottom-up/Top-down algorithm.
 *
 * <p>Gets an array of members for each level and traverses
 * array for the lowest level, setting each member's
 * parent's parent's etc. member's ordinal if not set working back
 * down to the leaf member and then going to the next leaf member
 * and traversing up again.//ww w  .j a v a  2s  . co  m
 *
 * <p>The above algorithm only works for a hierarchy that has all of its
 * leaf members in the same level (that is, a non-ragged hierarchy), which
 * is the norm. After all member ordinal values have been set, traverses
 * the array of members, making sure that all members' ordinals have been
 * set. If one is found that is not set, then one must to a full Top-down
 * setting of the ordinals.
 *
 * <p>The Bottom-up/Top-down algorithm is MUCH faster than the Top-down
 * algorithm.
 *
 * @param schemaReader Schema reader
 * @param seedMember Member
 */
public static void setOrdinals(SchemaReader schemaReader, Member seedMember) {
    seedMember = RolapUtil.strip((RolapMember) seedMember);

    // The following are times for executing different set ordinals
    // algorithms for both the FoodMart Sales cube/Store dimension
    // and a Large Data set with a dimension with about 250,000 members.
    //
    // Times:
    //    Original setOrdinals Top-down
    //       Foodmart: 63ms
    //       Large Data set: 651865ms
    //    Calling getAllMembers before calling original setOrdinals
    //    Top-down
    //       Foodmart: 32ms
    //       Large Data set: 73880ms
    //    Bottom-up/Top-down
    //       Foodmart: 17ms
    //       Large Data set: 4241ms
    long start = System.currentTimeMillis();

    try {
        Hierarchy hierarchy = seedMember.getHierarchy();
        int ordinal = hierarchy.hasAll() ? 1 : 0;
        List<List<Member>> levelMembers = getAllMembers(schemaReader, hierarchy);
        List<Member> leafMembers = levelMembers.get(levelMembers.size() - 1);
        levelMembers = levelMembers.subList(0, levelMembers.size() - 1);

        // Set all ordinals
        for (Member child : leafMembers) {
            ordinal = bottomUpSetParentOrdinals(ordinal, child);
            ordinal = setOrdinal(child, ordinal);
        }

        boolean needsFullTopDown = needsFullTopDown(levelMembers);

        // If we must to a full Top-down, then first reset all ordinal
        // values to -1, and then call the Top-down
        if (needsFullTopDown) {
            for (List<Member> members : levelMembers) {
                for (Member member : members) {
                    if (member instanceof RolapMemberBase) {
                        ((RolapMemberBase) member).resetOrdinal();
                    }
                }
            }

            // call full Top-down
            setOrdinalsTopDown(schemaReader, seedMember);
        }
    } finally {
        if (LOGGER.isDebugEnabled()) {
            long end = System.currentTimeMillis();
            LOGGER.debug("RolapMember.setOrdinals: time=" + (end - start));
        }
    }
}

From source file:ca.nines.ise.cmd.Command.java

/**
 * Get a list of file paths from the command line arguments.
 *
 * @param cmd/*from   w  w w  .j a v  a  2s  .  c o  m*/
 * @return File[]
 */
public File[] getFilePaths(CommandLine cmd) {
    Collection<File> fileList = new ArrayList<>();

    List<?> argList = cmd.getArgList();
    argList = argList.subList(1, argList.size());
    String[] args = argList.toArray(new String[argList.size()]);

    if (argList.isEmpty()) {
        File dir = new File("input");
        SuffixFileFilter sfx = new SuffixFileFilter(".txt");
        fileList = FileUtils.listFiles(dir, sfx, TrueFileFilter.INSTANCE);
    } else {
        for (String name : args) {
            fileList.add(new File(name));
        }
    }

    File[] files = fileList.toArray(new File[fileList.size()]);
    Arrays.sort(files);
    return files;
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.parser.GWikiWikiParser.java

public static List<GWikiFragment> trimBrs(List<GWikiFragment> l) {
    if (l.isEmpty() == true) {
        return l;
    }/*from w w  w . j  ava2 s  .co  m*/
    if (l.get(0) instanceof GWikiFragmentBr) {
        l = l.subList(1, l.size());
    }
    if (l.isEmpty() == true) {
        return l;
    }
    if (l.get(l.size() - 1) instanceof GWikiFragmentBr) {
        l = l.subList(0, l.size() - 1);
    }
    return l;
}

From source file:com.flipkart.zjsonpatch.ApplyProcessor.java

private JsonNode getParentNode(List<String> fromPath) {
    List<String> pathToParent = fromPath.subList(0, fromPath.size() - 1); // would never by out of bound, lets see
    return getNode(target, pathToParent, 1);
}

From source file:org.shredzone.cilla.admin.page.media.MediaDataModel.java

@Override
public List<MediumDto> load(int first, int pageSize, String sortField, SortOrder sortOrder,
        Map<String, String> filters) {
    List<MediumDto> mediaList = pageMediaBean.getMedia();
    setRowCount(mediaList.size());/*from  w w  w.  j av  a2 s .co m*/
    int max = Math.min(first + pageSize, mediaList.size());
    return mediaList.subList(first, max);
}

From source file:com.testritegroup.ec.core.category.dao.impl.ECPBrandDaoImpl.java

@Override
public List<ProductModel> getECPBrandProductsByQuery(FlexibleSearchQuery fQuery) {
    final SearchResult<ProductModel> result = getFlexibleSearchService().search(fQuery);

    List<ProductModel> resultList = result.getResult();
    if (CollectionUtils.isNotEmpty(resultList)) {
        if (resultList.size() >= 5) {
            return resultList.subList(0, 5);
        } else {//from  ww w  . jav a  2 s .c o m
            return resultList.subList(0, resultList.size());
        }
    }

    return new ArrayList<ProductModel>(0);
}

From source file:net.sf.maltcms.chromaui.charts.labels.TopKItemsLabelGenerator.java

/**
 *
 * @param sm// ww  w.  j a va 2  s  .  com
 * @param k
 */
public TopKItemsLabelGenerator(List<Point> sm, int k) {
    //      System.out.println("Length of list: " + sm.size());
    //      System.out.println("K=" + k);
    this.sublist = sm.subList(Math.max(0, sm.size() - k), sm.size());
    topK = new HashSet<>();
    //      System.out.println("Sublist length: " + this.sublist.size());
    topK.addAll(this.sublist);
    //      System.out.println("Top K: " + topK);
}