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.rosehulman.sws.extension.AbstractPlugin.java

private IServlet findServlet(String servletKey) {
    List<String> keyParts = Arrays.asList(servletKey.split("/"));
    IServlet servlet = null;//from  www.  java  2s  . c o m
    for (int i = keyParts.size(); i > 0; i--) {
        String key = StringUtils.join(keyParts.subList(0, i), "/");
        //System.out.println("KEY CHECK: " + key);
        servlet = this.servletMap.get(key);
        if (servlet != null)
            break;
    }
    return servlet;
}

From source file:com.temenos.useragent.generic.mediatype.JsonEntityHandler.java

@Override
public String getValue(String fqPropertyName) {
    List<String> pathParts = Arrays.asList(flattenPropertyName(fqPropertyName));
    Optional<JSONObject> parent = navigateJsonObjectforPropertyPath(Optional.ofNullable(jsonObject),
            pathParts.subList(0, pathParts.size() - 1), fqPropertyName, false);
    String lastPathPart = pathParts.get(pathParts.size() - 1);
    if (parent.isPresent()) {
        if (isPropertyNameWithIndex(lastPathPart)) {
            JSONArray jsonArr = parent.get().optJSONArray(extractPropertyName(lastPathPart));
            if (jsonArr != null) {
                return jsonArr.opt(extractIndex(lastPathPart)) != null
                        ? String.valueOf(jsonArr.opt(extractIndex(lastPathPart)))
                        : null;//from   www .jav a 2  s  .c om
            }
        } else {
            return parent.get().opt(lastPathPart) != null ? String.valueOf(parent.get().opt(lastPathPart))
                    : null;
        }
    }
    return null;
}

From source file:com.blackducksoftware.integration.hub.detect.detector.pear.PearParser.java

List<String> findDependencyNames(final List<String> content) {
    final List<String> nameList = new ArrayList<>();

    if (content.size() > 5) {
        final List<String> listing = content.subList(5, content.size() - 1);
        listing.forEach(line -> {//from w  ww  .  j av  a  2  s  .c o  m
            final String[] dependencyInfo = splitIgnoringWhitespace(line, " ");

            final String dependencyName = dependencyInfo[2].trim();
            final String dependencyRequired = dependencyInfo[0].trim();

            if (StringUtils.isNotBlank(dependencyName)) {
                if (!detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PEAR_ONLY_REQUIRED_DEPS,
                        PropertyAuthority.None)) {
                    nameList.add(last(dependencyName.split("/")));
                } else {
                    if (BooleanUtils.toBoolean(dependencyRequired)) {
                        nameList.add(last(dependencyName.split("/")));
                    }
                }
            }
        });
    }

    return nameList;

}

From source file:com.torchmind.stockpile.server.controller.v1.BlacklistController.java

/**
 * Checks an IP address against the blacklist.
 *
 * @param address an address.//  w  ww . j av a  2  s.c  om
 * @return a blacklist result.
 */
@Nonnull
private BlacklistResult checkAddress(@Nonnull String address) {
    List<String> addressParts = Splitter.on('.').splitToList(address);

    for (int i = (addressParts.size() - 1); i >= 1; --i) {
        String currentAddress = Joiner.on('.').join(addressParts.subList(0, i)) + ".*";
        String hash = Hashing.sha1().hashString(currentAddress, StandardCharsets.ISO_8859_1).toString();

        if (this.hashes.contains(hash)) {
            return new BlacklistResult(currentAddress, true);
        }
    }

    return new BlacklistResult(address, false);
}

From source file:org.obiba.mica.dataset.service.VariableSetService.java

/**
 * Get a subset of the variables referred by the {@link DocumentSet}.
 *
 * @param documentSet// w  w w. j  ava  2 s  .co m
 * @param from
 * @param limit
 * @return
 */
public List<DatasetVariable> getVariables(DocumentSet documentSet, int from, int limit) {
    ensureType(documentSet);
    if (documentSet.getIdentifiers().isEmpty())
        return Lists.newArrayList();
    List<String> ids = Lists.newArrayList(documentSet.getIdentifiers());
    Collections.sort(ids);
    int to = from + limit;
    if (to > ids.size())
        to = ids.size();
    return publishedDatasetVariableService.findByIds(ids.subList(from, to));
}

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

protected List<E> findListByQueryLimit(final String query, final int first, final int max,
        final Object... params) {
    Collection<E> values = this.entities.values();
    List<E> filtered = new ArrayList<>();
    for (E e : values) {
        if (this.findListByQueryLimitFilter(e, query, params)) {
            filtered.add(e);/* ww  w. j  a v a2  s  . co m*/
        }
    }

    List<E> sorted = this.findListByQueryLimitSort(filtered, query, params);

    if (first >= 0) {
        if (max >= 0) {
            return Collections.unmodifiableList(sorted.subList(first, Math.max(first + max, values.size())));
        }
        return Collections.unmodifiableList(sorted.subList(first, values.size()));
    }
    if (max >= 0) {
        return Collections.unmodifiableList(sorted.subList(0, Math.max(first + max, values.size())));
    }
    return Collections.unmodifiableList(sorted);
}

From source file:io.github.robwin.markup.builder.markdown.MarkdownBuilder.java

@Override
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV) {
    String headersInPSV = rowsInPSV.get(0);
    List<String> contentRowsInPSV = rowsInPSV.subList(1, rowsInPSV.size());
    String[] headersAsArray = headersInPSV
            .split(String.format("\\%s", Markdown.TABLE_COLUMN_DELIMITER.toString()));
    List<String> headers = Arrays.asList(headersAsArray);

    newLine();/*from  w ww.j a va2 s .c  om*/
    // Header
    documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
    documentBuilder.append(headersInPSV);
    documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
    newLine();
    // Header/Content separator
    documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
    for (String header : headers) {
        for (int i = 1; i < 5; i++) {
            documentBuilder.append(Markdown.TABLE_ROW);
        }
        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
    }
    newLine();
    // Content
    for (String contentRowInPSV : contentRowsInPSV) {
        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
        documentBuilder.append(contentRowInPSV);
        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
        newLine();
    }
    newLine().newLine();
    return this;
}

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

@Test
public void testRemoveExpectOneLeft() throws Exception {
    // setup/*from  w  ww .  j  a v a  2 s  .c om*/
    List<WiFiDetail> expected = withData();
    // execute
    List<BaseSeries<DataPoint>> actual = fixture.remove(expected.subList(1, expected.size()));
    // validate
    assertEquals(2, actual.size());
    for (int i = 1; i < expected.size(); i++) {
        assertTrue(series.contains(actual.get(i - 1)));
        assertFalse(fixture.contains(expected.get(i)));
    }
    assertTrue(fixture.contains(expected.get(0)));
}

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

@Test
public void testRemoveExpectMoreThanOneLeft() throws Exception {
    // setup/*  w  ww  . jav  a2s .  co m*/
    List<WiFiDetail> expected = withData();
    // execute
    List<BaseSeries<DataPoint>> actual = fixture.remove(expected.subList(0, 1));
    // validate
    assertEquals(1, actual.size());
    assertTrue(series.contains(actual.get(0)));
    for (int i = 1; i < expected.size(); i++) {
        assertTrue(fixture.contains(expected.get(i)));
    }
    assertFalse(fixture.contains(expected.get(0)));
}

From source file:com.torchmind.stockpile.server.controller.v1.BlacklistController.java

/**
 * Checks a hostname against the blacklist.
 *
 * @param hostname a hostname.//from w w  w .j  a va 2  s.c o  m
 * @return a blacklist result.
 */
@Nonnull
private BlacklistResult checkHostname(@Nonnull String hostname) {
    List<String> hostnameParts = Splitter.on('.').splitToList(hostname);

    for (int i = 1; i < hostnameParts.size(); ++i) {
        String currentHostname = "*." + Joiner.on('.').join(hostnameParts.subList(i, hostnameParts.size()));
        String hash = Hashing.sha1().hashString(currentHostname, StandardCharsets.ISO_8859_1).toString();

        if (this.hashes.contains(hash)) {
            return new BlacklistResult(currentHostname, true);
        }
    }

    return new BlacklistResult(hostname, false);
}