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:ch.unibas.fittingwizard.application.tools.LPunParser.java

private List<String> removeFooter(List<String> lines) {
    int lraIndex = -1;
    for (int i = 0; i < lines.size(); i++) {
        if (lines.get(i).trim().contains("LRA:"))
            lraIndex = i;/*from  w  ww.j ava  2s.c  om*/
    }
    if (lraIndex == -1)
        throw new LPunParserException("Could not find line containing 'LRA:'.");
    return lines.subList(0, lraIndex);
}

From source file:de.weltraumschaf.registermachine.asm.LineParser.java

private void parseMetaCode(final List<Token> tokens) throws AssemblerSyntaxException {
    final Token metaCode = tokens.get(0);

    if (".function".equals(metaCode.getValue())) {
        parseFunctionMetaCode(tokens.subList(1, tokens.size()));
    } else if (".const".equals(metaCode.getValue())) {
        parseConstantMetaCode(tokens.subList(1, tokens.size()));
    } else if (".var".equals(metaCode.getValue())) {
        parseVariableMetaCode(tokens.subList(1, tokens.size()));
    } else {//  ww  w . ja  va2s  . c  o  m
        throw new AssemblerSyntaxException(String.format("Unsupported meta code mnemonic %s!", metaCode),
                getCurrentLine());
    }
}

From source file:org.apache.streams.messaging.service.impl.CassandraActivityService.java

@Override
public List<String> getActivitiesForFilters(List<String> filters, Date lastUpdated) {
    List<CassandraActivityStreamsEntry> activityObjects = cassandraActivityStreamsRepository
            .getActivitiesForFilters(filters, lastUpdated);
    Collections.sort(activityObjects, Collections.reverseOrder());
    //TODO: make the number of streams returned configurable
    return getJsonList(activityObjects.subList(0, Math.min(activityObjects.size(), 10)));
}

From source file:net.groupbuy.template.method.MessageMethod.java

@SuppressWarnings("rawtypes")
public Object exec(List arguments) throws TemplateModelException {
    if (arguments != null && !arguments.isEmpty() && arguments.get(0) != null
            && StringUtils.isNotEmpty(arguments.get(0).toString())) {
        String message = null;/*www  .java  2 s.c o  m*/
        String code = arguments.get(0).toString();
        if (arguments.size() > 1) {
            Object[] args = arguments.subList(1, arguments.size()).toArray();
            message = SpringUtils.getMessage(code, args);
        } else {
            message = SpringUtils.getMessage(code);
        }
        return new SimpleScalar(message);
    }
    return null;
}

From source file:com.github.jrh3k5.mojo.flume.process.AgentProcessTest.java

/**
 * Test the starting and stopping of the process.
 * /*from  w  w  w .j a va  2  s.co  m*/
 * @throws Exception
 *             If any errors occur during the test run.
 */
@Test
public void testStart() throws Exception {
    @SuppressWarnings("rawtypes")
    final ArgumentCaptor<List> argsCaptor = ArgumentCaptor.forClass(List.class);
    mockAgentStart(argsCaptor);

    @SuppressWarnings("unchecked")
    final List<String> args = argsCaptor.getValue();
    // First two commands needed to start the agent - the rest can be in any orders
    assertThat(args.subList(0, 2)).containsExactly("bin/flume-ng", "agent");
    assertThat(getArguments(args.subList(2, args.size()))).containsOnly(new Argument("-c", "conf"),
            new Argument("-f", configFile.getAbsolutePath()), new Argument("-n", agentName));
}

From source file:com.haulmont.cuba.core.global.RemoteException.java

@SuppressWarnings("unchecked")
public RemoteException(Throwable throwable) {
    List<Throwable> list = ExceptionUtils.getThrowableList(throwable);
    for (int i = 0; i < list.size(); i++) {
        Throwable t = list.get(i);
        boolean suitable = true;
        List<Throwable> causesOfT = list.subList(i, list.size());
        for (Throwable aCauseOfT : causesOfT) {
            if (!isSuitable(aCauseOfT)) {
                suitable = false;/*from  ww w .  j a  va 2 s  . c o m*/
                break;
            }
        }
        if (suitable)
            causes.add(new Cause(t));
        else
            causes.add(new Cause(t.getClass().getName(), t.getMessage()));
    }
}

From source file:com.yahoo.sql4d.insert.BasicInsertMeta.java

private JSONObject getFireHose() {
    Map<String, Object> finalMap = new LinkedHashMap<>();
    Map<String, Object> parserMap = new LinkedHashMap<>();
    String timestampFormat = null;
    String dataFormat = "tsv";

    finalMap.put("type", "local");
    if (dataPath != null) {
        int folderEndIndex = dataPath.lastIndexOf("/");
        finalMap.put("baseDir", dataPath.substring(0, folderEndIndex + 1));
        finalMap.put("filter",
                (folderEndIndex == dataPath.length() - 1) ? "*" : dataPath.substring(folderEndIndex + 1));
        if (dataPath.endsWith("json")) {
            dataFormat = "json";
        } else if (dataPath.endsWith("csv")) {
            dataFormat = "csv";
        }/*from   w w  w . ja  v a 2  s . c o m*/
    } else {
        finalMap.put("baseDir", tmpFolder);
        String fileName = UUID.randomUUID().toString() + ".csv";
        finalMap.put("filter", fileName);
        dataFormat = "csv";
        if (values.isEmpty()) {
            throw new IllegalStateException("No values to insert !!");
        }
        try {
            File file = new File(tmpFolder + File.separator + fileName);
            FileUtils.write(file, Joiner.on(",").join(values));
            System.out.println("Written to " + file);
            Object timestamp = values.get(0);
            timestampFormat = TimeUtils.detectFormat(timestamp.toString());
        } catch (IOException ex) {
            Logger.getLogger(BasicInsertMeta.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    Map<String, String> tsSpec = ImmutableMap.<String, String>builder().put("column", "timestamp")
            .put("format", (timestampFormat != null) ? timestampFormat : "auto").build();
    parserMap.put("timestampSpec", tsSpec);
    List<String> dims = getDimensions(fetchDimensions);
    List<String> metrics = getMetrics(aggregations);

    Map<String, Object> data = new LinkedHashMap<>();
    data.put("format", dataFormat);
    data.put("dimensions", dims.subList(1, dims.size()));
    if (delimiter != null) {
        data.put("delimiter", delimiter);
    }
    if (listDelimiter != null) {
        data.put("listDelimiter", listDelimiter);
    }
    data.put("columns", getColumns(fetchDimensions, aggregations));
    parserMap.put("data", data);
    finalMap.put("parser", parserMap);
    return new JSONObject(finalMap);
}

From source file:io.seldon.api.caching.ActionHistoryCache.java

public List<Long> getRecentActions(String clientName, long userId, int numActions) {
    String mkey = MemCacheKeys.getActionHistory(clientName, userId);
    List<Long> res = (List<Long>) MemCachePeer.get(mkey);
    if (res == null) {
        logger.debug("creating empty action history for user " + userId + " for client " + clientName);
        res = new ArrayList<>();
    } else {/*from ww w.j a v  a2  s.  co  m*/
        if (res.size() > numActions)
            res = res.subList(0, numActions);
        logger.debug("Got action history for user " + userId + " from memcache");
    }
    return res;
}

From source file:edu.uci.ics.asterix.optimizer.rules.UnnestToDataScanRule.java

public void addPrimaryKey(List<LogicalVariable> scanVariables, IOptimizationContext context) {
    int n = scanVariables.size();
    List<LogicalVariable> head = new ArrayList<LogicalVariable>(scanVariables.subList(0, n - 1));
    List<LogicalVariable> tail = new ArrayList<LogicalVariable>(1);
    tail.add(scanVariables.get(n - 1));/*ww w  .ja  va 2 s .c om*/
    FunctionalDependency pk = new FunctionalDependency(head, tail);
    context.addPrimaryKey(pk);
}

From source file:com.cloudera.branchreduce.impl.distributed.TaskMaster.java

public List<T> getWork(int requestorId, G workerState) {
    updateGlobalState(workerState);/*from  w  w w .j  a v a2 s. c om*/
    if (!tasks.isEmpty()) {
        try {
            List<T> ret = ImmutableList.of(tasks.take());
            LOG.info("Sending work to " + requestorId);
            return ret;
        } catch (InterruptedException e) {
            return ImmutableList.of();
        }
    } else {
        // Need to get some more work, if anyone has any.
        Set<Integer> workingIds = Sets.newHashSet(hasWork.keySet());
        for (Integer workingId : workingIds) {
            if (workingId != requestorId) {
                WorkerProxy<T, G> worker = workers.get(workingId);
                List<T> stolen = worker.getTasks();
                if (!stolen.isEmpty()) {
                    List<T> ret = ImmutableList.of(stolen.get(0));
                    tasks.addAll(stolen.subList(1, stolen.size()));
                    LOG.info("Sending stolen work to " + requestorId);
                    return ret;
                }
            }
        }
        LOG.info("Could not send work to " + requestorId);
        hasWork.remove(requestorId);
        return ImmutableList.of();
    }
}