List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:com.redhat.rhn.manager.user.UserManager.java
/** * Returns visible Systems as a SystemSearchResult Object * @param user the user we want//from www.ja v a2 s .c o m * @param ids the list of desired system ids * @return DataResult of systems */ public static DataResult<SystemSearchResult> visibleSystemsAsDtoFromList(User user, List<Long> ids) { SelectMode m = ModeFactory.getMode("System_queries", "visible_to_user_from_sysid_list"); DataResult<SystemSearchResult> dr = null; int batchSize = 500; for (int batch = 0; batch < ids.size(); batch = batch + batchSize) { int toIndex = batch + batchSize; if (toIndex > ids.size()) { toIndex = ids.size(); } Map params = new HashMap(); params.put("user_id", user.getId()); DataResult partial = m.execute(params, ids.subList(batch, toIndex)); partial.setElaborationParams(Collections.EMPTY_MAP); if (dr == null) { dr = partial; } else { dr.addAll(partial); } } return dr; }
From source file:com.brighttag.trident.kairos.KairosState.java
/** * Store multiple metrics into KairosDB. This save is idempotent; any data for * {@code keys} that already exists is overwritten with the new {@code vals}. * * @param keys list of metric key fields in this order: * (start_date [long], exclusive_end_date [long], name [string], tags [map<string, string>]...) *///from www. ja v a 2 s . c o m @Override public void multiPut(List<List<Object>> keys, List<T> vals) { MetricBuilder builder = MetricBuilder.getInstance(); for (int i = 0; i < keys.size(); i++) { List<Object> k = keys.get(i); String name = k.get(2).toString(); Map<String, String> tags = toTags(k.subList(3, k.size())); Metric metric = builder.addMetric(name, type).addTags(tags); serialize(metric, toDate(k.get(0)), vals.get(i)); } try { client.pushMetrics(builder); waitForWrite(); } catch (URISyntaxException e) { throw Throwables.propagate(e); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.hpe.application.automation.tools.octane.executor.UftTestDiscoveryDispatcher.java
private static boolean updateTests(MqmRestClient client, Collection<AutomatedTest> tests, String workspaceId) { try {/*from w w w.ja va2s . co m*/ //build testsForUpdate List<AutomatedTest> testsForUpdate = new ArrayList<>(); for (AutomatedTest test : tests) { AutomatedTest testForUpdate = new AutomatedTest(); if (test.getDescription() != null) { testForUpdate.setDescription(test.getDescription()); } testForUpdate.setExecutable(test.getExecutable()); testForUpdate.setId(test.getId()); testsForUpdate.add(testForUpdate); } if (!testsForUpdate.isEmpty()) { for (int i = 0; i < tests.size(); i += POST_BULK_SIZE) { AutomatedTests data = AutomatedTests .createWithTests(testsForUpdate.subList(i, Math.min(i + POST_BULK_SIZE, tests.size()))); String uftTestJson = convertToJsonString(data); client.updateEntities(Long.parseLong(workspaceId), OctaneConstants.Tests.COLLECTION_NAME, uftTestJson); } } return true; } catch (Exception e) { logger.error("Failed to update tests : " + e.getMessage()); return false; } }
From source file:org.kordamp.javatrove.example02.impl.GithubImplTest.java
@Test public void happyPath() throws Exception { // given://from w w w . ja va 2 s . c o m String nextUrl = "/organizations/1/repos?page=2"; List<Repository> repositories = createSampleRepositories(); stubFor(get(urlEqualTo("/orgs/" + ORGANIZATION + "/repos")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/json") .withHeader("Link", "<http://localhost:8080" + nextUrl + ">; rel=\"next\"") .withBody(repositoriesAsJSON(repositories.subList(0, 5), objectMapper)))); stubFor(get(urlEqualTo(nextUrl)) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/json") .withBody(repositoriesAsJSON(repositories.subList(5, 8), objectMapper)))); // when: Promise<Collection<Repository>, Throwable, Repository> promise = github.repositories(ORGANIZATION, 8); await().timeout(2, SECONDS).until(promise::state, equalTo(Promise.State.RESOLVED)); // then: promise.done(result -> assertThat(result, equalTo(repositories.subList(0, 8)))); verify(getRequestedFor(urlEqualTo("/orgs/" + ORGANIZATION + "/repos"))); }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.util.WekaUtils.java
/** * Feature selection using Mulan.//from w ww.j a v a 2 s . c o m * * @param trainData * training data * @param labelTransformationMethod * method to transform multi-label data into single-label data * @param attributeEvaluator * @param numLabelsToKeep * number of labels that should be kept * @param featureSelectionResultsFile * a file to write the evaluated attributes to * @return a filter to reduce the attribute dimension * @throws TextClassificationException */ public static Remove multiLabelAttributeSelection(Instances trainData, String labelTransformationMethod, List<String> attributeEvaluator, int numLabelsToKeep, File featureSelectionResultsFile) throws TextClassificationException { Remove filterRemove = new Remove(); try { MultiLabelInstances mulanInstances = convertMekaInstancesToMulanInstances(trainData); ASEvaluation eval = ASEvaluation.forName(attributeEvaluator.get(0), attributeEvaluator.subList(1, attributeEvaluator.size()).toArray(new String[0])); AttributeEvaluator attributeSelectionFilter; // We currently only support the following Mulan Transformation methods (configuration // is complicated due to missing commandline support of mulan): if (labelTransformationMethod.equals("LabelPowersetAttributeEvaluator")) { attributeSelectionFilter = new LabelPowersetAttributeEvaluator(eval, mulanInstances); } else if (labelTransformationMethod.equals("BinaryRelevanceAttributeEvaluator")) { attributeSelectionFilter = new BinaryRelevanceAttributeEvaluator(eval, mulanInstances, "max", "none", "rank"); } else { throw new TextClassificationException("This Label Transformation Method is not supported."); } Ranker r = new Ranker(); int[] result = r.search(attributeSelectionFilter, mulanInstances); // collect evaluation for *all* attributes and write to file StringBuffer evalFile = new StringBuffer(); for (Attribute att : mulanInstances.getFeatureAttributes()) { evalFile.append(att.name() + ": " + attributeSelectionFilter.evaluateAttribute(att.index() - mulanInstances.getNumLabels()) + "\n"); } FileUtils.writeStringToFile(featureSelectionResultsFile, evalFile.toString()); // create a filter to reduce the dimension of the attributes int[] toKeep = new int[numLabelsToKeep + mulanInstances.getNumLabels()]; System.arraycopy(result, 0, toKeep, 0, numLabelsToKeep); int[] labelIndices = mulanInstances.getLabelIndices(); System.arraycopy(labelIndices, 0, toKeep, numLabelsToKeep, mulanInstances.getNumLabels()); filterRemove.setAttributeIndicesArray(toKeep); filterRemove.setInvertSelection(true); filterRemove.setInputFormat(mulanInstances.getDataSet()); } catch (ArrayIndexOutOfBoundsException e) { // less attributes than we want => no filtering return null; } catch (Exception e) { throw new TextClassificationException(e); } return filterRemove; }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testSubListRemove() { List<Integer> baseList = createListWithContent(new int[] { 1, 2, 3, 4, 5 }); List<Integer> sublist = baseList.subList(1, 3); sublist.remove(0);/*w w w . j a v a2s . c om*/ assertEquals(4, baseList.size()); assertEquals(3, baseList.get(1).intValue()); try { sublist.remove(1); fail("Expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException expected) { } assertFalse(sublist.remove(Integer.valueOf(4))); assertTrue(sublist.remove(Integer.valueOf(3))); assertEquals(0, sublist.size()); assertEquals(3, baseList.size()); sublist.add(6); checkListSizeAndContent(baseList, 1, 6, 4, 5); }
From source file:edu.cornell.mannlib.ld4lindexing.documents.InstanceDocument.java
private void addTitleFields(SolrDocument doc) { List<? extends Object> titles = values.get("titles"); if (titles == null || titles.isEmpty()) { return;/* w w w . j a va 2s.c o m*/ } doc.addFieldValue("title_display", titles.get(0)); if (titles.size() > 1) { doc.addFieldValues("alt_titles_t", titles.subList(1, titles.size())); } }
From source file:com.bitranger.parknshop.common.service.ads.ItemAdService.java
public List<PsPromotItem> randomReduce(List<PsPromotItem> src, int limit) { if (src.size() > limit) { ThreadLocalRandom rand = ThreadLocalRandom.current(); int idx = rand.nextInt(limit); int nidx = rand.nextInt(limit, src.size()); src.set(idx, src.get(nidx));//from www .j av a 2 s . c o m return new ArrayList<>(src.subList(0, limit)); } else { return src; } }
From source file:com.dianping.cat.consumer.problem.ProblemReportMerger.java
protected List<String> mergeList(List<String> oldMessages, List<String> newMessages, int size) { int originalSize = oldMessages.size(); if (originalSize < size) { int remainingSize = size - originalSize; if (remainingSize >= newMessages.size()) { oldMessages.addAll(newMessages); } else {/*from w w w .j a v a 2s. co m*/ oldMessages.addAll(newMessages.subList(0, remainingSize)); } } return oldMessages; }
From source file:edu.emory.cci.aiw.cvrg.eureka.services.resource.DataElementResource.java
private void deleteFailed(List<String> dataElementsUsedIn, DataElementEntity proposition) throws HttpStatusException { String dataElementList;/*www . j a v a 2 s . co m*/ int size = dataElementsUsedIn.size(); if (size > 1) { List<String> subList = dataElementsUsedIn.subList(0, dataElementsUsedIn.size() - 1); dataElementList = StringUtils.join(subList, ", ") + " and " + dataElementsUsedIn.get(size - 1); } else { dataElementList = dataElementsUsedIn.get(0); } MessageFormat usedByOtherDataElements = new MessageFormat( messages.getString("dataElementResource.delete.error.usedByOtherDataElements")); String msg = usedByOtherDataElements .format(new Object[] { proposition.getDisplayName(), dataElementsUsedIn.size(), dataElementList }); throw new HttpStatusException(Response.Status.PRECONDITION_FAILED, msg); }