List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:com.threewks.thundr.validation.ConstraintViolationSetToMapTransformer.java
/** * Add an error to the error map. Nested properties are put into sub maps to make for nice property style * lookups in JavaScript, EL etc.// ww w . ja v a 2 s . c o m */ @SuppressWarnings("unchecked") private void putError(Map<String, Object> errorMap, String propertyPath, String message) { if (propertyPath.contains(PROPERTY_PATH_DELIMITER)) { List<String> parts = Arrays.asList(propertyPath.split(PROPERTY_PATH_DELIMITER_PATTERN)); String key = parts.get(0); Map<String, Object> subMap = (Map<String, Object>) errorMap.get(key); if (subMap == null) { subMap = Expressive.map(); errorMap.put(key, subMap); } String subPath = StringUtils.join(parts.subList(1, parts.size()), PROPERTY_PATH_DELIMITER); putError(subMap, subPath, message); return; } errorMap.put(propertyPath, message); }
From source file:io.seldon.client.test.ApiClientTest.java
@Test public void retrieveRecommendationsWithDimensionsForUser() throws ApiException { List<UserBean> users = apiClient.getUsers(USER_LIMIT, false); List<DimensionBean> dimensions = apiClient.getDimensions(); for (UserBean user : users) { String userId = user.getId(); int limit = Math.min(dimensions.size(), DIMENSIONS_LIMIT); for (DimensionBean dimension : dimensions.subList(0, limit)) { int dimensionId = dimension.getDimId(); @SuppressWarnings({ "NullableProblems" }) final int recommendations_limit = USER_RECOMMENDATIONS_LIMIT; List<ItemBean> recommendations = apiClient.getRecommendations(userId, null, dimensionId, recommendations_limit); for (ItemBean recommendation : recommendations) { logger.debug("Recommendation for user: " + userId + " => in dimension: " + dimension + " => " + recommendation); }//from w w w. ja v a2 s . com } } }
From source file:azkaban.executor.MockExecutorLoader.java
@Override public List<ExecutorLogEvent> getExecutorEvents(final Executor executor, final int num, final int skip) throws ExecutorManagerException { if (!this.executorEvents.containsKey(executor.getId())) { final List<ExecutorLogEvent> events = this.executorEvents.get(executor.getId()); return events.subList(skip, Math.min(num + skip - 1, events.size() - 1)); }/* w w w. jav a 2s .co m*/ return null; }
From source file:edu.unc.lib.dl.services.FolderManager.java
/** * Given a repository path string, creates any folders that do not yet exist along this path. * /* w w w.ja v a 2 s . c o m*/ * @param path * the desired folder path * @throws IngestException * if the path cannot be created */ public PID createPath(String path, String owner, String user) throws IngestException { log.debug("attempting to create path: " + path); if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } if (!PathUtil.isValidPathString(path)) { throw new IngestException("The proposed path is not valid: " + path); } List<String> slugs = new ArrayList<String>(); slugs.addAll(Arrays.asList(path.split("/"))); slugs.remove(0); Stack<String> createFolders = new Stack<String>(); String containerPath = null; for (int i = slugs.size(); i >= 0; i--) { String test = "/" + StringUtils.join(slugs.subList(0, i), "/"); PID pid = this.getTripleStoreQueryService().fetchByRepositoryPath(test); if (pid == null) { // does not exist yet, must create it createFolders.add(slugs.get(i - 1)); } else { List<URI> types = this.getTripleStoreQueryService().lookupContentModels(pid); if (!types.contains(ContentModelHelper.Model.CONTAINER.getURI())) { StringBuffer s = new StringBuffer(); for (URI type : types) { s.append(type.toString()).append("\t"); } throw new IngestException("The object at the path '" + test + "' is not a folder. It has these content models:\n" + s.toString()); } containerPath = test; break; } } // add folders PID lastpid = null; while (createFolders.size() > 0) { String slug = createFolders.pop(); SingleFolderSIP sip = new SingleFolderSIP(); PID containerPID = this.getTripleStoreQueryService().fetchByRepositoryPath(containerPath); sip.setContainerPID(containerPID); if ("/".equals(containerPath)) { containerPath = containerPath + slug; } else { containerPath = containerPath + "/" + slug; } sip.setSlug(slug); sip.setAllowIndexing(true); DepositRecord record = new DepositRecord(user, owner, DepositMethod.Unspecified); record.setMessage("creating a new folder path"); IngestResult result = this.getDigitalObjectManager().addWhileBlocking(sip, record); lastpid = result.derivedPIDs.iterator().next(); } return lastpid; }
From source file:net.ripe.ipresource.etree.NestedIntervalMap.java
private List<InternalNode<K, V>> internalFindAllMoreSpecific(K range) { List<InternalNode<K, V>> result = internalFindExactAndAllMoreSpecific(range); if (!result.isEmpty() && result.get(0).getKey().equals(range)) { return result.subList(1, result.size()); } else {//w w w .j a va 2 s . co m return result; } }
From source file:dk.frankbille.scoreboard.service.DefaultScoreBoardService.java
@Transactional(readOnly = true) @Override// w ww. j a v a2 s . co m public List<Game> getAllGames(League league, int numberOfGames) { List<Game> allGames = getAllGames(league); numberOfGames = Math.min(numberOfGames, allGames.size()); return allGames.subList(0, numberOfGames - 1); }
From source file:net.sourceforge.atunes.kernel.actions.PrintSongListRemoteAction.java
@Override public String runCommand(final List<String> parameters) { Collection<ILocalAudioObject> objects = null; if (!CollectionUtils.isEmpty(parameters)) { String query = null;/*from w w w . j a v a 2 s .c om*/ if (parameters.size() > 1) { query = StringUtils.join(parameters.subList(1, parameters.size()), ' '); } String firstParameter = parameters.get(0); if (firstParameter.equalsIgnoreCase(ARTIST)) { objects = processArtistParameter(query); if (objects == null) { return "Artist not found."; } } else if (firstParameter.equalsIgnoreCase(ALBUM)) { objects = processAlbumParameter(query); if (objects == null) { return "Album not found"; } } else if (firstParameter.equalsIgnoreCase(PLAYLIST)) { return processPlaylistParameter(); } else { return "Bad command"; } } else { objects = processAllSongs(); } StringBuilder sb = new StringBuilder(); if (objects != null) { for (ILocalAudioObject iao : objects) { sb.append(fileManager.getPath(iao)).append("\n"); } } return sb.toString(); }
From source file:org.carewebframework.vista.api.mbroker.BrokerResponse.java
public BrokerResponse(List<String> response) { super(createStatusLine(response.get(0))); ContentType contentType = null;//from www.j a va 2 s . c o m InputStream body = null; for (int i = 1; i < response.size(); i++) { String s = response.get(i).trim(); if (s.isEmpty()) { body = new ListInputStream(response.subList(i + 1, response.size())); break; } String[] pcs = s.split("\\:", 2); Header header = new BasicHeader(pcs[0].trim(), pcs[1].trim()); addHeader(header); if (contentType == null && header.getName().equalsIgnoreCase(HttpHeaders.CONTENT_TYPE)) { contentType = parseContentType(header.getValue()); } } setEntity(new InputStreamEntity(body, contentType)); }
From source file:info.archinnov.achilles.compound.CQLSliceQueryValidator.java
public <T> void validateComponentsForSliceQuery(SliceQuery<T> sliceQuery) { final List<Object> clusteringsFrom = sliceQuery.getClusteringsFrom(); final List<Object> clusteringsTo = sliceQuery.getClusteringsTo(); final OrderingMode validationOrdering = sliceQuery.getOrdering(); final int partitionComponentsSize = sliceQuery.partitionComponentsSize(); final String startDescription = StringUtils .join(clusteringsFrom.subList(partitionComponentsSize, clusteringsFrom.size()), ","); final String endDescription = StringUtils .join(clusteringsTo.subList(partitionComponentsSize, clusteringsTo.size()), ","); log.trace("Check components {} / {}", startDescription, endDescription); final int startIndex = getLastNonNullIndex(clusteringsFrom); final int endIndex = getLastNonNullIndex(clusteringsTo); // No more than 1 non-null component difference between clustering keys Validator.validateTrue(Math.abs(endIndex - startIndex) <= 1, "There should be no more than 1 component difference between clustering keys: [[%s]," + "[%s]", startDescription, endDescription); for (int i = partitionComponentsSize; i <= Math.max(startIndex, endIndex) - 1; i++) { Object startComp = clusteringsFrom.get(i); Object endComp = clusteringsTo.get(i); int comparisonResult = comparator.compare(startComp, endComp); Validator.validateTrue(comparisonResult == 0, (i + 1 - partitionComponentsSize) + "th component for clustering keys should be equal: [[%s],[%s]", startDescription, endDescription); }//from w w w . jav a 2 s . c o m if (startIndex > 0 && startIndex == endIndex) { Object startComp = clusteringsFrom.get(startIndex); Object endComp = clusteringsTo.get(endIndex); if (ASCENDING.equals(validationOrdering)) { Validator.validateTrue(comparator.compare(startComp, endComp) <= 0, "For slice query with ascending order, start clustering last component should be " + "'lesser or equal' to end clustering last component: [[%s],[%s]", startDescription, endDescription); } else { Validator.validateTrue(comparator.compare(startComp, endComp) >= 0, "For slice query with descending order, start clustering last component should be " + "'greater or equal' to end clustering last component: [[%s],[%s]", startDescription, endDescription); } } }
From source file:com.collective.celos.ci.mode.TestTask.java
void waitForCompletion(List<Future> futures) throws Throwable { List<Throwable> throwables = Lists.newArrayList(); for (Future future : futures) { try {//ww w . j a v a2s. c o m future.get(); } catch (ExecutionException ee) { throwables.add(ee.getCause()); } } if (!throwables.isEmpty()) { List<Throwable> throwablesWOLast = throwables.subList(0, throwables.size() - 1); for (Throwable t : throwablesWOLast) { t.printStackTrace(); } Throwable lastThrowable = throwables.get(throwables.size() - 1); throw lastThrowable; } }