Example usage for java.util ArrayList subList

List of usage examples for java.util ArrayList subList

Introduction

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

Prototype

public 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:ubic.gemma.core.loader.association.phenotype.OmimDatabaseImporterCli.java

private Map<Long, Collection<Long>> populateOmimIdsToPubmeds(Set<Long> allOmimId) throws InterruptedException {

    // omimID --> all list of publications
    HashMap<Long, Collection<Long>> omimIdToPubmeds = new HashMap<>();

    // HashSet to ArrayList, so no duplicate but can use list methods
    // allOmimId contains all OMIM id (phenotype and gene)
    ArrayList<Long> allOmimIdList = new ArrayList<>(allOmimId);

    int i = 0;/*from ww  w .  j av a  2s.  c  o m*/

    while (i < allOmimIdList.size()) {

        int j = i + 10;

        if (j > allOmimIdList.size()) {
            j = allOmimIdList.size();
        }

        // each List can have a max size of 10, divide allOmimIdList into many lists
        List<Long> listWithLimitSize10 = allOmimIdList.subList(i, j);

        // call the api limiting the request to 10 Omim id and populates omimIdToPubmeds
        OmimAnnotatorClient.findLinkedPublications(listWithLimitSize10, omimIdToPubmeds);

        i = j;
    }

    return omimIdToPubmeds;
}

From source file:pathwaynet.PathwayCalculator.java

private <T> ArrayList<HashSet<T>> generatePermutatedGroups(Collection<T> allComponents, int groupSize) {
    ArrayList<HashSet<T>> componentsInGroupPermutations = new ArrayList<>();
    for (int i = 0; i < numPermutations; i++) {
        HashSet<T> componentsThisPermut = new HashSet<>();
        ArrayList<T> componentsInPathway = new ArrayList<>();
        componentsInPathway.addAll(allComponents);
        Collections.shuffle(componentsInPathway);
        componentsThisPermut.addAll(componentsInPathway.subList(0, groupSize));

        componentsInGroupPermutations.add(componentsThisPermut);
    }//from w ww  .  j  a va2  s .  c o  m
    return componentsInGroupPermutations;
}

From source file:qa.experiment.SRLPerProcessModelCrossValidation.java

public void doCrossValidation(String processName, ArrayList<ProcessFrame> selectedProcessFrame, int foldSize)
        throws IOException, InterruptedException, FileNotFoundException, NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    int startIdx = 0;
    int testSize = selectedProcessFrame.size() / foldSize;
    int endIdx = testSize;
    for (int currentFold = 0; currentFold < foldSize; currentFold++) {
        ArrayList<ProcessFrame> testingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(startIdx, endIdx));
        ArrayList<ProcessFrame> trainingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(0, startIdx));
        trainingFrames.addAll(//  w w  w.j  a v  a 2  s .  c om
                new ArrayList<ProcessFrame>(selectedProcessFrame.subList(endIdx, selectedProcessFrame.size())));
        if (da) {
            GlobalV.sourceIdxStart = trainingFrames.size();
            trainingFrames.addAll(inverseData);
        }
        String trainingFileName = outDirName + "/" + processName + ".train.perprocess.cv." + currentFold;
        String testingFileName = outDirName + "/" + processName + ".test.cv." + currentFold;
        String modelName = outDirName + "/" + processName + ".perprocessmodel.cv." + currentFold;

        testFilePath.add(testingFileName);
        trainingModelFilePath.add(modelName);

        ProcessFrameUtil.toParserFormat(trainingFrames, trainingFileName, srlType);
        ProcessFrameUtil.toParserFormat(testingFrames, testingFileName, srlType);

        doTrain(trainingFileName, modelName);
        startIdx = endIdx;
        if (currentFold == foldSize - 2) {
            endIdx = selectedProcessFrame.size();
        } else {
            endIdx = startIdx + testSize;
        }
    }
}

From source file:jp.alessandro.android.iab.ItemGetter.java

/**
 * In your application, you can query the item details from Google Play using the In-app Billing Version 3 API.
 * To pass a request to the In-app Billing service, first create a Bundle that contains
 * a String ArrayList of product IDs with key "ITEM_ID_LIST",
 * where each string is a product ID for an purchasable item.
 * See https://developer.android.com/google/play/billing/billing_integrate.html#QueryDetails
 *
 * @param service  in-app billing service
 * @param itemType "inapp" or "subs"/*from   w w  w.  j av  a2 s . com*/
 * @param itemIds  contains the list of item ids that you want to request
 * @return
 * @throws BillingException
 */
ItemDetails get(IInAppBillingService service, String itemType, ArrayList<String> itemIds)
        throws BillingException {

    ItemDetails itemDetails = new ItemDetails();
    List<ArrayList<String>> splitItemIdList = new ArrayList<>();

    // There reason why it splits the item ids per request
    // It's because there is a known bug on Google Api
    // https://code.google.com/archive/p/marketbilling/issues/137
    for (int i = 0; i < itemIds.size(); i += ItemGetter.MAX_SKU_PER_REQUEST) {
        int fromIndex = i;
        int toIndex = Math.min(itemIds.size(), i + ItemGetter.MAX_SKU_PER_REQUEST);

        ArrayList<String> list = new ArrayList<>(itemIds.subList(fromIndex, toIndex));
        splitItemIdList.add(list);
    }

    for (ArrayList<String> splitItemIds : splitItemIdList) {
        try {
            Bundle itemIdsBundle = createBundleItemListFromArray(splitItemIds);
            Bundle skuDetails = service.getSkuDetails(mApiVersion, mPackageName, itemType, itemIdsBundle);
            List<String> detailList = getItemsFromResponse(skuDetails);
            putAll(detailList, itemDetails);

        } catch (RemoteException e) {
            throw new BillingException(Constants.ERROR_REMOTE_EXCEPTION, e.getMessage());
        }
    }
    return itemDetails;
}

From source file:org.apache.hadoop.hbase.regionserver.compactions.SortedCompactionPolicy.java

protected ArrayList<StoreFile> getCurrentEligibleFiles(ArrayList<StoreFile> candidateFiles,
        final List<StoreFile> filesCompacting) {
    // candidates = all storefiles not already in compaction queue
    if (!filesCompacting.isEmpty()) {
        // exclude all files older than the newest file we're currently
        // compacting. this allows us to preserve contiguity (HBASE-2856)
        StoreFile last = filesCompacting.get(filesCompacting.size() - 1);
        int idx = candidateFiles.indexOf(last);
        Preconditions.checkArgument(idx != -1);
        candidateFiles.subList(0, idx + 1).clear();
    }/*from   w  ww . j ava 2  s  .c  o m*/
    return candidateFiles;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java

public ActionForward viewAlertMessages(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/*from w w  w .  j  a  v a2s  .  c o  m*/

    TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>(
            Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID));
    orderedMessages.addAll(getLoggedPerson(request).getPhdAlertMessagesSet());
    ArrayList<PhdAlertMessage> lastMessages = new ArrayList<PhdAlertMessage>();
    lastMessages.addAll(orderedMessages);

    request.setAttribute("unread", "false");
    request.setAttribute("alertMessages",
            lastMessages.subList(0, Math.min(lastMessages.size(), NUMBER_OF_LAST_MESSAGES)));
    request.setAttribute("tooManyMessages", (lastMessages.size() > NUMBER_OF_LAST_MESSAGES) ? "true" : "false");
    return mapping.findForward("viewAlertMessages");
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.phd.CommonPhdIndividualProgramProcessDA.java

public ActionForward viewProcessAlertMessages(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {

    TreeSet<PhdAlertMessage> orderedMessages = new TreeSet<PhdAlertMessage>(
            Collections.reverseOrder(PhdAlertMessage.COMPARATOR_BY_WHEN_CREATED_AND_ID));
    orderedMessages.addAll(getProcess(request).getAlertMessagesForLoggedPerson());
    ArrayList<PhdAlertMessage> lastMessages = new ArrayList<PhdAlertMessage>();
    lastMessages.addAll(orderedMessages);

    request.setAttribute("unread", "false");
    request.setAttribute("alertMessages",
            lastMessages.subList(0, Math.min(lastMessages.size(), NUMBER_OF_LAST_MESSAGES)));
    request.setAttribute("tooManyMessages", (lastMessages.size() > NUMBER_OF_LAST_MESSAGES) ? "true" : "false");
    return mapping.findForward("viewProcessAlertMessages");
}

From source file:qa.experiment.SRLDSCombinedModelCrossValidation.java

public void doCrossValidation(String processName, ArrayList<ProcessFrame> selectedProcessFrame, int foldSize)
        throws IOException, InterruptedException, FileNotFoundException, NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    int startIdx = 0;
    int testSize = selectedProcessFrame.size() / foldSize;
    int endIdx = testSize;
    for (int currentFold = 0; currentFold < foldSize; currentFold++) {
        ArrayList<ProcessFrame> testingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(startIdx, endIdx));
        ArrayList<ProcessFrame> trainingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(0, startIdx));
        trainingFrames.addAll(//from  w w  w.  ja va2 s  .c o m
                new ArrayList<ProcessFrame>(selectedProcessFrame.subList(endIdx, selectedProcessFrame.size())));
        trainingFrames.addAll(inverseData);
        trainingFrames.addAll(dsProc.getProcArr());

        String trainingFileName = outDirName + "/" + processName + ".train.dscombined.cv." + currentFold;
        String testingFileName = outDirName + "/" + processName + ".test.cv." + currentFold;
        String modelName = outDirName + "/" + processName + ".dscombinedmodel.cv." + currentFold;

        testFilePath.add(testingFileName);
        trainingModelFilePath.add(modelName);
        System.out.println(testingFileName);
        boolean train = false;
        if (!(new File(trainingFileName).exists())) {
            ProcessFrameUtil.toParserFormat(trainingFrames, trainingFileName, srlType);
            train = true;
        }
        if (!(new File(testingFileName).exists())) {
            ProcessFrameUtil.toParserFormat(testingFrames, testingFileName, srlType);
        }

        if (train) {
            doTrain(trainingFileName, modelName);
        }
        startIdx = endIdx;
        if (currentFold == foldSize - 2) {
            endIdx = selectedProcessFrame.size();
        } else {
            endIdx = startIdx + testSize;
        }
    }
}

From source file:qa.experiment.SRLCombinedModelCrossValidation.java

public void doCrossValidation(String processName, ArrayList<ProcessFrame> selectedProcessFrame, int foldSize)
        throws IOException, InterruptedException, FileNotFoundException, NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    int startIdx = 0;
    int testSize = selectedProcessFrame.size() / foldSize;
    int endIdx = testSize;
    for (int currentFold = 0; currentFold < foldSize; currentFold++) {
        ArrayList<ProcessFrame> testingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(startIdx, endIdx));
        ArrayList<ProcessFrame> trainingFrames = new ArrayList<ProcessFrame>(
                selectedProcessFrame.subList(0, startIdx));
        trainingFrames.addAll(//from   www  .  ja  v  a  2 s.c o  m
                new ArrayList<ProcessFrame>(selectedProcessFrame.subList(endIdx, selectedProcessFrame.size())));
        trainingFrames.addAll(inverseData);

        String trainingFileName = outDirName + "/" + processName + ".train.combined.cv." + currentFold;
        String testingFileName = outDirName + "/" + processName + ".test.cv." + currentFold;
        String modelName = outDirName + "/" + processName + ".combinedmodel.cv." + currentFold;

        testFilePath.add(testingFileName);
        trainingModelFilePath.add(modelName);

        new ProcessFrameUtil().toParserFormat(trainingFrames, trainingFileName, srlType);
        new ProcessFrameUtil().toParserFormat(testingFrames, testingFileName, srlType);

        doTrain(trainingFileName, modelName);
        startIdx = endIdx;
        if (currentFold == foldSize - 2) {
            endIdx = selectedProcessFrame.size();
        } else {
            endIdx = startIdx + testSize;
        }
    }
}

From source file:org.apache.solr.response.transform.TestSubQueryTransformer.java

@Test
public void testRowsStartForSubqueryAndScores() throws Exception {

    String johnDeptsIds = h/*from  w  w w .  j  ava  2s.co  m*/
            .query(req(new String[] { "q", "{!join from=dept_ss_dv to=dept_id_s}name_s:john", "wt", "csv",
                    "csv.header", "false", "fl", "id", "rows", "" + deptMultiplier, "sort", "id_i desc" }));

    ArrayList<Object> deptIds = Collections.list(new StringTokenizer(johnDeptsIds));

    final int a = random().nextInt(deptMultiplier + 1);
    final int b = random().nextInt(deptMultiplier + 1);
    final int start = Math.min(a, b);
    final int toIndex = Math.max(a, b);
    List<Object> expectIds = deptIds.subList(start, toIndex);
    ArrayList<String> assertions = new ArrayList<>();
    // count((//result/doc/str[@name='name_s_dv'][.='john']/../result[@name='depts'])[1]/doc/str[@name='id'])
    // random().nextInt(peopleMultiplier);
    assertions.add("count((//result/doc/str[@name='name_s_dv'][.='john']/.."
            + "/result[@name='depts'][@numFound='" + deptMultiplier + "'][@start='" + start + "'])["
            + (random().nextInt(peopleMultiplier) + 1) + "]/doc/str[@name='id'])=" + (toIndex - start));

    // System.out.println(expectIds);

    for (int i = 0; i < expectIds.size(); i++) {
        // (//result/doc/str[@name='name_s_dv'][.='john']/../result[@name='depts'])[1]/doc[1]/str[@name='id']='15'
        String ithDoc = "(//result/doc/str[@name='name_s_dv'][.='john']/.."
                + "/result[@name='depts'][@numFound='" + deptMultiplier + "'][@start='" + start + "'])["
                + (random().nextInt(peopleMultiplier) + 1) + "]/doc[" + (i + 1) + "]";
        assertions.add(ithDoc + "/str[@name='id'][.='" + expectIds.get(i) + "']");
        // let's test scores right there
        assertions.add(ithDoc + "/float[@name='score'][.='" + expectIds.get(i) + ".0']");

    }

    String[] john = new String[] { "q", "name_s:john", "indent", "true", "fl",
            "dept_ss_dv,name_s_dv,depts:[subquery]", "rows", "" + (2 * peopleMultiplier), "depts.q",
            "+{!term f=dept_id_s v=$row.dept_ss_dv}^=0 _val_:id_i", "depts.fl", "id", "depts.fl", "score",
            "depts.indent", "true", "depts.rows", "" + (toIndex - start), "depts.start", "" + start };

    assertQ(req(john), assertions.toArray(new String[] {}));
}