List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:com.linksinnovation.elearning.controller.api.WishlistController.java
@JsonView(View.SCREEN.class) @RequestMapping(value = "/p/{page}", method = RequestMethod.GET) public Page<Course> get(@PathVariable("page") Integer page, @AuthenticationPrincipal String username) { UserDetails userDetails = userDetailsRepository.findOne(username.toUpperCase()); List<Wishlist> findByUser = wishlistRepository.findByUser(userDetails); List<Course> courses = new ArrayList<>(); findByUser.stream().forEach((wishlist) -> { Course course = wishlist.getCourse(); course.setWishlist(true);/*from www .j a v a2 s . c o m*/ courses.add(course); }); int pageSize = 16; int first = page * pageSize; int last = first + (pageSize); last = (last > courses.size()) ? courses.size() : last; return new PageImpl<>(courses.subList(first, last), new PageRequest(page, pageSize, Sort.Direction.DESC, "id"), courses.size()); }
From source file:org.kordamp.javatrove.example04.impl.GithubImplTest.java
@Test public void happyPath() throws Exception { // given://from w ww .jav a2 s. c om 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: List<Repository> results = new ArrayList<>(); github.repositories(ORGANIZATION).subscribe(results::add); // then: assertThat(results, hasSize(8)); verify(getRequestedFor(urlEqualTo("/orgs/" + ORGANIZATION + "/repos"))); verify(getRequestedFor(urlEqualTo(nextUrl))); }
From source file:com.odo.kcl.mobileminer.OpenBmapCellRequest.java
@Override protected Object doInBackground(Object... cellSpec) { if (cellSpec.length < 4) return null; String Mcc, Mnc, Lac, Id;/* w ww .j ava 2 s.c o m*/ Mcc = (String) cellSpec[0]; Mnc = (String) cellSpec[1]; Lac = (String) cellSpec[2]; Id = (String) cellSpec[3]; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.openbmap.org/api/getGPSfromGSM.php"); List<NameValuePair> postData = new ArrayList<NameValuePair>(4); postData.add(new BasicNameValuePair("mcc", Mcc)); postData.add(new BasicNameValuePair("mnc", Mnc)); postData.add(new BasicNameValuePair("lac", Lac)); postData.add(new BasicNameValuePair("cell_id", Id)); try { String XMLdump, Lat, Long, poly, polyDump; Lat = null; Long = null; poly = null; post.setEntity(new UrlEncodedFormEntity(postData)); XMLdump = EntityUtils.toString(client.execute(post).getEntity()); //Log.i("MobileMiner",XMLdump); Matcher latMatch = latPattern.matcher(XMLdump); while (latMatch.find()) Lat = latMatch.group(1); Matcher longMatch = longPattern.matcher(XMLdump); while (longMatch.find()) Long = longMatch.group(1); Matcher polyMatch = polyPattern.matcher(XMLdump); while (polyMatch.find()) poly = polyMatch.group(1); //Log.i("MobileMiner","Lat "+Lat); //Log.i("MobileMiner","Long "+Long); //Log.i("MobileMiner","Poly "+poly); if (poly != null) { List<String> points = new ArrayList<String>(); String[] point; String[] polyChunks = poly.split(","); for (String chunk : polyChunks) { point = chunk.split("\\s+"); points.add("[" + point[1] + "," + point[0] + "]"); } polyDump = "[" + TextUtils.join(",", points.subList(0, points.size() - 1)) + "]"; //Log.i("MobileMiner",polyDump); } else { polyDump = null; } if (Lat != null && Long != null) { return new String[] { Lat, Long, polyDump }; } else { return null; } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block } // TODO Auto-generated method stub return null; }
From source file:org.jtalks.poulpe.model.dao.hibernate.UserHibernateDaoTest.java
@Test public void testFindUsersNotInList() { List<PoulpeUser> allUsers = TestFixtures.usersListOf(6); allUsers.get(4).setEnabled(false);/* ww w . ja va2s . c o m*/ List<PoulpeUser> usersInGroup = allUsers.subList(0, 3); saveAndEvict(allUsers); int limit = 5; List<PoulpeUser> actual = dao.findUsersNotInList(NO_FILTER, usersInGroup, Pages.paginate(0, limit)); int expectedUserCount = 2; assertEquals(actual.size(), expectedUserCount); }
From source file:uk.ac.cam.cl.dtg.segue.api.InfoFacade.java
/** * This method returns all versions as an immutable map version_list. * // w ww .j a v a2 s . co m * @param limit * parameter if not null will set the limit of the number entries to return the default is the latest 10 * (indices starting at 0). * * @return a Response containing an immutable map version_list: [x..y..] */ @GET @Path("content_versions") @Produces(MediaType.APPLICATION_JSON) @GZIP public final Response getVersionsList(@QueryParam("limit") final String limit) { // try to parse the integer Integer limitAsInt = null; try { if (null == limit) { limitAsInt = DEFAULT_RESULTS_LIMIT; } else { limitAsInt = Integer.parseInt(limit); } } catch (NumberFormatException e) { SegueErrorResponse error = new SegueErrorResponse(Status.BAD_REQUEST, "The limit requested is not a valid number."); log.debug(error.getErrorMessage()); return error.toResponse(); } List<String> allVersions = this.contentManager.listAvailableVersions(); List<String> limitedVersions; try { limitedVersions = new ArrayList<String>(allVersions.subList(0, limitAsInt)); } catch (IndexOutOfBoundsException e) { // they have requested a stupid limit so just give them what we have // got. limitedVersions = allVersions; log.debug("Bad index requested for version number." + " Using maximum index instead."); } catch (IllegalArgumentException e) { SegueErrorResponse error = new SegueErrorResponse(Status.BAD_REQUEST, "Invalid limit specified: " + limit, e); log.debug(error.getErrorMessage(), e); return error.toResponse(); } ImmutableMap<String, Collection<String>> result = new ImmutableMap.Builder<String, Collection<String>>() .put("version_list", limitedVersions).build(); return Response.ok(result).build(); }
From source file:dk.netarkivet.viewerproxy.LocalCDXCache.java
/** * Returns the name of the index file for a set of jobIds. This filename must be unique for these IDs and always * give the same for the same set of IDs. In this implementation, long lists of IDs will be shortened to the first * few IDs followed by an MD5 sum of all the IDs. * * @param jobIDs Set of job IDs, in no particular order. * @return A File that specifies where the index.cdx data for the job IDs should reside. This does not check whether * the file exists or even if the directory it belongs to exists. *///from ww w . ja va 2 s . c o m private File getIndexFile(Set<Long> jobIDs) { List<Long> jobIDList = new ArrayList<Long>(jobIDs); Collections.sort(jobIDList); String allIDsString = StringUtils.conjoin("-", jobIDList); if (jobIDList.size() > MAX_JOB_IDS_IN_FILENAME) { String firstNIDs = StringUtils.conjoin("-", jobIDList.subList(0, MAX_JOB_IDS_IN_FILENAME)); return new File(CACHE_DIR, PREFIX + firstNIDs + "-" + ChecksumCalculator.calculateMd5(allIDsString.getBytes()) + SUFFIX); } else { return new File(CACHE_DIR, PREFIX + allIDsString + SUFFIX); } }
From source file:com.app.inventario.logica.ProveedorLogicaImpl.java
@Transactional(readOnly = true) public jqGridModel obtenerListaTodos(int numeroPagina, int numeroFilas, String ordenarPor, String ordenarAsc) throws Exception { modelo = new jqGridModel<Proveedor>(); int primerResultado = numeroFilas * (numeroPagina - 1); List<Proveedor> proveedores = null; try {/*from ww w. ja v a 2s.co m*/ proveedores = proveedorDAO.obtenerTodosAGrid(ordenarPor, ordenarAsc); modelo.setPage(numeroPagina); modelo.setTotal((int) Math.ceil((double) proveedores.size() / (double) numeroFilas)); modelo.setRecords(proveedores.size()); modelo.setRows(proveedores.subList(primerResultado, numeroFilas > proveedores.size() ? proveedores.size() : numeroFilas)); return modelo; } catch (HibernateException he) { Logger.getLogger(ProveedorLogicaImpl.class.getName()).log(Level.SEVERE, null, he); throw he; } }
From source file:hu.ppke.itk.nlpg.purepos.decoder.AbstractDecoder.java
protected List<Pair<List<Integer>, Double>> cleanResults(List<Pair<List<Integer>, Double>> tagSeqList) { List<Pair<List<Integer>, Double>> ret = new ArrayList<Pair<List<Integer>, Double>>(); for (Pair<List<Integer>, Double> element : tagSeqList) { List<Integer> tagSeq = element.getKey(); List<Integer> newTagSeq = tagSeq.subList(0, tagSeq.size() - 1); ret.add(Pair.of(newTagSeq, element.getValue())); }//from ww w . j a v a 2 s . co m return ret; }
From source file:com.thomasjensen.checkstyle.addons.checks.misc.ModuleDirectoryLayoutCheck.java
private boolean isTopLevelFolderNestingOk(@Nonnull final String pTopLevelFolder, @Nonnull final List<String> pSpecificFolders) { boolean ok = true; if (pSpecificFolders.size() > 1) { ok = !Util.containsString(pSpecificFolders.subList(1, pSpecificFolders.size()), pTopLevelFolder, false); // never case sensitive }/*from w w w. jav a 2 s. co m*/ return ok; }
From source file:com.app.inventario.logica.ProveedorLogicaImpl.java
@Transactional(readOnly = true) public String obtenerListaTodosXML(int numeroPagina, int numeroFilas, String ordenarPor, String ordenarAsc) throws Exception { XStream xstream = new XStream(); xstream.alias("root", jqGridModel.class); xstream.alias("proveedor", Proveedor.class); modelo = new jqGridModel<Proveedor>(); int primerResultado = numeroFilas * (numeroPagina - 1); List<Proveedor> proveedores = null; try {/*from w w w .ja va 2s . c o m*/ proveedores = proveedorDAO.obtenerTodosAGrid(ordenarPor, ordenarAsc); modelo.setPage(numeroPagina); modelo.setTotal((int) Math.ceil((double) proveedores.size() / (double) numeroFilas)); modelo.setRecords(proveedores.size()); modelo.setRows(proveedores.subList(primerResultado, numeroFilas > proveedores.size() ? proveedores.size() : numeroFilas)); return xstream.toXML(modelo); } catch (HibernateException he) { Logger.getLogger(ProveedorLogicaImpl.class.getName()).log(Level.SEVERE, null, he); throw he; } //return map; }