List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:org.kordamp.javatrove.example04.FunctionalTest.java
@Test public void _01_happy_path() throws Exception { // given:/*from w ww .j ava2s . 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, 10), objectMapper)))); // when: testfx.clickOn("#organization").eraseText(ORGANIZATION.length()).write(ORGANIZATION); testfx.clickOn("#loadButton"); // wait Button loadButton = testfx.lookup("#loadButton").query(); new WaitUntilSupport().waitUntil(loadButton, isEnabled(), 2); // then: verifyThat("#total", hasText("10")); verifyThat("#repositories", hasItems(10)); }
From source file:org.syncope.core.util.ImportExport.java
private List<String> sortByForeignKeys(final Connection conn, final Set<String> tableNames) throws SQLException, CycleInMultiParentTreeException { MultiParentNode<String> root = new MultiParentNode<String>(ROOT_ELEMENT); for (String tableName : tableNames) { MultiParentNode<String> node = MultiParentNodeOp.findInTree(root, tableName); if (node == null) { node = new MultiParentNode<String>(tableName); root.addChild(node);//from w ww. ja v a 2 s . c o m } ResultSet rs = null; try { rs = conn.getMetaData().getExportedKeys(conn.getCatalog(), readSchema(), tableName); while (rs.next()) { String fkTableName = rs.getString("FKTABLE_NAME"); if (!tableName.equals(fkTableName)) { MultiParentNode<String> fkNode = MultiParentNodeOp.findInTree(root, fkTableName); if (fkNode == null) { fkNode = new MultiParentNode<String>(fkTableName); root.addChild(fkNode); } fkNode.addChild(node); if (root.isParent(node)) { root.removeChild(node); } } } } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("While closing tables result set", e); } } } } List<String> sortedTableNames = new ArrayList<String>(tableNames.size()); MultiParentNodeOp.traverseTree(root, sortedTableNames); return sortedTableNames.subList(0, sortedTableNames.size() - 1); }
From source file:eu.trentorise.opendata.jackan.test.ckan.ReadCkanIT.java
@Test @Parameters(method = "clients") public void testOrganization(CkanClient client) { List<CkanOrganization> gl = client.getOrganizationList(); assertTrue(gl.size() > 0);// ww w.jav a 2s .co m for (CkanOrganization g : gl.subList(0, Math.min(gl.size(), TEST_ELEMENTS))) { CkanOrganization fetchedOrganization = client.getOrganization(g.getId()); assertEquals(g.getName(), fetchedOrganization.getName()); } }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.artifact.KubernetesCleanupArtifactsOperation.java
private List<Artifact> artifactsToDelete(KubernetesManifest manifest) { KubernetesManifestStrategy strategy = KubernetesManifestAnnotater.getStrategy(manifest); if (strategy.getMaxVersionHistory() == null) { return new ArrayList<>(); }/*from w w w. j a v a 2s .com*/ int maxVersionHistory = strategy.getMaxVersionHistory(); Optional<Artifact> optional = KubernetesManifestAnnotater.getArtifact(manifest); if (!optional.isPresent()) { return new ArrayList<>(); } Artifact artifact = optional.get(); List<Artifact> artifacts = artifactProvider .getArtifacts(artifact.getType(), artifact.getName(), artifact.getLocation()).stream() .filter(a -> a.getMetadata() != null && accountName.equals(a.getMetadata().get("account"))) .collect(Collectors.toList()); if (maxVersionHistory >= artifacts.size()) { return new ArrayList<>(); } else { return artifacts.subList(0, artifacts.size() - maxVersionHistory); } }
From source file:com.pari.nm.modules.jobs.VSEMImporter.java
public static <T> List<List<T>> split(List<T> alist, int len) { List<List<T>> listOfLists = new ArrayList<>(); int hi = 0;/* w w w . ja v a2 s. co m*/ for (int lo = 0; lo < alist.size(); lo = hi) { hi = lo + len; if (hi > alist.size()) { hi = alist.size(); } listOfLists.add(new ArrayList<T>(alist.subList(lo, hi))); } return listOfLists; }
From source file:com.pureinfo.srmcenter.datasync.client.uploader.impl.SyncUploaderImpl.java
private void doUpdatePost(String _sHostUrl, SyncRequest _request, int _nRetryCount) { SyncResponse response = null;// w w w . ja v a 2 s . co m boolean bFlag = true; for (int i = 0; i < _nRetryCount && bFlag; i++) { response = postRequest(_sHostUrl, _request, _nRetryCount); if (response == null) { logger.warn("retry post request #" + (i + 1)); try { Thread.sleep(100); } catch (Exception ex) { } } else { bFlag = false; } } if (response == null) { List updates = _request.getUpdates(); if (updates.size() == 1) { logger.warn("update error " + updates); } else { SyncRequest request1 = copyRequest(_request); request1.setUpdates(updates.subList(0, updates.size() / 2)); doUpdatePost(_sHostUrl, request1, _nRetryCount); SyncRequest request2 = copyRequest(_request); request2.setUpdates(updates.subList(updates.size() / 2, updates.size())); doUpdatePost(_sHostUrl, request2, _nRetryCount); } } else { handleResponse(response); } }
From source file:org.easit.core.controllers.facebook.FacebookFeedController.java
@RequestMapping(value = "/facebook/wall", method = RequestMethod.GET) public String showWall(Model model, String offset, String size, String ro) { int int_offset = 0; int listSize = 0; if (offset != null) { int_offset = Integer.valueOf(offset); }//from w ww . jav a 2s .c o m //Get the posts int fromIndex = int_offset; int toIndex = fromIndex + PSMetadata.FACEBOOK_LIMIT_RESULT; List<Post> posts = facebook.feedOperations().getFeed(0, PSMetadata.MAX_RESULTS_SEARCH); toIndex = Math.min(toIndex, posts.size()); //Get the n of the posts if (size != null) { listSize = Integer.valueOf(size); } else { listSize = posts.size(); } model.addAttribute("userProf", facebook.userOperations().getUserProfile()); model.addAttribute("feed", posts.subList(fromIndex, toIndex)); model.addAttribute("offset", int_offset); model.addAttribute("pageSize", listSize); return "facebook/wall"; }
From source file:managers.nodes.CombinationGroupManager.java
private List<String> combineStrings(String string, List<String> slot, List<String> result) { if (slot.isEmpty()) { return result; }//from www. j a v a 2s . com String combinedString = string + " " + slot.get(0); result.add(combinedString); return this.combineStrings(string, slot.subList(1, slot.size()), result); }
From source file:org.graylog2.alarmcallbacks.pagerduty.PagerDutyClient.java
protected List<Message> getAlarmBacklog(AlertCondition.CheckResult result) { final AlertCondition alertCondition = result.getTriggeredCondition(); final List<MessageSummary> matchingMessages = result.getMatchingMessages(); final int effectiveBacklogSize = Math.min(alertCondition.getBacklog(), matchingMessages.size()); if (effectiveBacklogSize == 0) { return Collections.emptyList(); }//from www . jav a2s. c o m final List<MessageSummary> backlogSummaries = matchingMessages.subList(0, effectiveBacklogSize); final List<Message> backlog = Lists.newArrayListWithCapacity(effectiveBacklogSize); for (MessageSummary messageSummary : backlogSummaries) { backlog.add(messageSummary.getRawMessage()); } return backlog; }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testSubList() { List<Integer> wrappedList = createListWithContent(new int[] { 1, 2, 3, 4, 5 }); List<Integer> testList = wrappedList.subList(1, 4); assertEquals(3, testList.size());/*from w w w. j a v a 2 s . c o m*/ assertEquals(testList, Arrays.asList(2, 3, 4)); checkListSizeAndContent(testList, 2, 3, 4); testList.add(1, 6); assertEquals(testList, Arrays.asList(2, 6, 3, 4)); checkListSizeAndContent(testList, 2, 6, 3, 4); assertEquals(wrappedList, Arrays.asList(1, 2, 6, 3, 4, 5)); checkListSizeAndContent(wrappedList, 1, 2, 6, 3, 4, 5); testList.remove(2); assertEquals(testList, Arrays.asList(2, 6, 4)); checkListSizeAndContent(testList, 2, 6, 4); try { testList.remove(3); fail("Expected remove to fail"); } catch (IndexOutOfBoundsException e) { } checkListSizeAndContent(wrappedList, 1, 2, 6, 4, 5); testList.set(0, 7); checkListSizeAndContent(testList, 7, 6, 4); checkListSizeAndContent(wrappedList, 1, 7, 6, 4, 5); try { wrappedList.subList(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 15); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(5, 1); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { wrappedList.subList(0, 1).add(2, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).add(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).get(1); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).get(-1); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).set(2, 2); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).set(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } }