List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:pl.edu.icm.comac.vis.server.DataController.java
@RequestMapping("/data/search") Map search(@RequestParam("query") String query) { log.debug("Got a search query: {}", query); Map<String, Object> res = new HashMap<String, Object>(); Map<String, Object> response = new HashMap<String, Object>(); query = query.toLowerCase();// w ww.j a v a2 s . c o m try { List<SearchResult> searchResultList = searchService.search(query, MAX_RESPONSE + 1); boolean hasMore = searchResultList.size() > MAX_SEARCH_RESULTS; if (hasMore) { searchResultList = searchResultList.subList(0, MAX_SEARCH_RESULTS); } response.put("docs", searchResultList); response.put("hasMoreResults", hasMore); res.put("response", response); } catch (Exception e) { res.put("error", e.getMessage()); } return res; }
From source file:edu.emory.cci.aiw.cvrg.eureka.services.resource.PhenotypeResource.java
private void deleteFailed(List<String> phenotypesUsedIn, PhenotypeEntity proposition) throws HttpStatusException { String phenotypeList;//from www. ja va 2s .c o m int size = phenotypesUsedIn.size(); if (size > 1) { List<String> subList = phenotypesUsedIn.subList(0, phenotypesUsedIn.size() - 1); phenotypeList = StringUtils.join(subList, ", ") + " and " + phenotypesUsedIn.get(size - 1); } else { phenotypeList = phenotypesUsedIn.get(0); } MessageFormat usedByOtherPhenotypes = new MessageFormat( messages.getString("phenotypeResource.delete.error.usedByOtherPhenotypes")); String msg = usedByOtherPhenotypes .format(new Object[] { proposition.getDisplayName(), phenotypesUsedIn.size(), phenotypeList }); throw new HttpStatusException(Response.Status.PRECONDITION_FAILED, msg); }
From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.DistributedDeployer.java
private <T extends Account> void reapOrcaServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Orca, T> orcaService) { Orca orca = orcaService.connectToPrimaryService(details, runtimeSettings); Map<String, ActiveExecutions> executions = orca.getActiveExecutions(); ServiceSettings orcaSettings = runtimeSettings.getServiceSettings(orcaService.getService()); RunningServiceDetails orcaDetails = orcaService.getRunningServiceDetails(details, runtimeSettings); Map<String, Integer> executionsByInstance = new HashMap<>(); executions.forEach((s, e) -> {/*w ww . j a v a 2s . c om*/ String instanceId = s.split("@")[1]; executionsByInstance.put(instanceId, e.getCount()); }); Map<Integer, Integer> executionsByServerGroupVersion = new HashMap<>(); orcaDetails.getInstances().forEach((s, is) -> { int count = is.stream().reduce(0, (c, i) -> c + executionsByInstance.getOrDefault(i.getId(), 0), (a, b) -> a + b); executionsByServerGroupVersion.put(s, count); }); // Omit the last deployed orcas from being deleted, since they are kept around for rollbacks. List<Integer> allOrcas = new ArrayList<>(executionsByServerGroupVersion.keySet()); allOrcas.sort(Integer::compareTo); int orcaCount = allOrcas.size(); if (orcaCount <= MAX_REMAINING_SERVER_GROUPS) { return; } allOrcas = allOrcas.subList(0, orcaCount - MAX_REMAINING_SERVER_GROUPS); for (Integer orcaVersion : allOrcas) { // TODO(lwander) consult clouddriver to ensure this orca isn't enabled if (executionsByServerGroupVersion.get(orcaVersion) == 0) { DaemonTaskHandler.message("Reaping old orca instance " + orcaVersion); orcaService.deleteVersion(details, orcaSettings, orcaVersion); } } }
From source file:es.eucm.rage.realtime.states.elasticsearch.EsMapState.java
@Override public void multiPut(List<List<Object>> keys, List<T> vals) { try {//from w w w .ja v a 2 s. c o m BulkRequest request = new BulkRequest(); for (int i = 0; i < keys.size(); i++) { // Update the result List<Object> key = keys.get(i); OpaqueValue val = (OpaqueValue) vals.get(i); String activityId = (String) key.get(0); String gameplayId = (String) key.get(1); setProperty(activityId, gameplayId, key.subList(2, key.size()), val.getCurr()); String keyId = toSingleKey(keys.get(i)); String serialized = ser.serialize(val); String index = ESUtils.getOpaqueValuesIndex(activityId); String type = ESUtils.getOpaqueValuesType(); String id = keyId; String source = serialized; request.add(new UpdateRequest(index, type, id).docAsUpsert(true).doc(source, XContentType.JSON) .retryOnConflict(50)); } BulkResponse bulkResponse = hClient.bulk(request); if (bulkResponse.hasFailures()) { LOG.error("BULK hasFailures proceeding to re-bulk"); for (BulkItemResponse bulkItemResponse : bulkResponse) { if (bulkItemResponse.isFailed()) { BulkItemResponse.Failure failure = bulkItemResponse.getFailure(); LOG.error("Failure " + failure.getCause()); } } } } catch (Exception e) { LOG.error("MULTI PUT error", e); } }
From source file:dk.netarkivet.common.utils.FileUtils.java
/** Given a set, generate a reasonable file name from the set. * @param <T> The type of objects, that the Set IDs argument contains. * @param IDs A set of IDs./*from w ww .j a v a 2 s .c o m*/ * @param suffix A suffix. May be empty string. * @return A reasonable file name. */ public static <T extends Comparable<T>> String generateFileNameFromSet(Set<T> IDs, String suffix) { ArgumentNotValid.checkNotNull(IDs, "Set<T> IDs"); ArgumentNotValid.checkNotNull(suffix, "String suffix"); if (IDs.isEmpty()) { return "empty" + suffix; } List<T> sorted = new ArrayList<T>(IDs); Collections.sort(sorted); String allIDsString = StringUtils.conjoin("-", sorted); String fileName; if (sorted.size() > MAX_IDS_IN_FILENAME) { String firstNIDs = StringUtils.conjoin("-", sorted.subList(0, MAX_IDS_IN_FILENAME)); fileName = firstNIDs + "-" + ChecksumCalculator.calculateMd5(allIDsString.getBytes()) + suffix; } else { fileName = allIDsString + suffix; } return fileName; }
From source file:com.victor.fishhub.service.weatherapi.APIResponseConverterImpl.java
@Override public List<DailyWeather> updateDailyWeatherList(WeatherDataDTO data, List<DailyWeather> weatherList) throws WeatherDataFormatException { List<H3PeriodWeather> h3List = convertToH3PeriodWeatherList(data); if (h3List.size() != 40) { //if response don't contain complete data throw new WeatherDataFormatException(); }// w w w. j a v a 2 s .c om //devide list into 5 periods and sequentially update each corresponding entity for (int i = 0; i < 5; i++) { updateDailyWeather(h3List.subList(0 + 8 * i, 8 + 8 * i), weatherList.get(i)).setDayNumber(i + 1); } return weatherList; }
From source file:com.play.engine.RecommendEngine.java
/*** * keyword result /*from w w w. ja v a 2s.c o m*/ * @param keyWordResult * @param oriResult */ private void insertKeyWordResult(List<ShopInfo> keyWordResult, List<ShopInfo> oriResult) { if (keyWordResult == null || oriResult == null) { return; } int keyWordSize = keyWordResult.size(); int oriSize = oriResult.size(); if (keyWordSize >= oriSize) { oriResult.addAll(0, keyWordResult.subList(0, 1)); } int keyWordSegment = 1;//? int oriSegment = 10;// int keyWordIndex = 0;//? int oriIndex = 0;// while (keyWordIndex < keyWordSize && oriIndex < oriSize) { List<ShopInfo> keyWordSubResult = keyWordResult.subList(keyWordIndex, keyWordIndex + keyWordSegment); oriResult.addAll(oriIndex, keyWordSubResult); keyWordIndex += keyWordSegment; oriIndex += oriSegment; } }
From source file:com.evolveum.midpoint.wf.impl.processors.primary.policy.ApprovalSchemaBuilder.java
private List<Fragment> getMergeGroup(List<Fragment> fragments, int i) { int j = i + 1; while (j < fragments.size() && fragments.get(i).isMergeableWith(fragments.get(j))) { j++;// w ww . ja v a2 s . c o m } return new ArrayList<>(fragments.subList(i, j)); // result should be modifiable independently on the master list }
From source file:com.quigley.filesystem.FilesystemPath.java
public FilesystemPath removeFirst(int count) { List<String> elementsCopy = new ArrayList<String>(elements); elementsCopy = elementsCopy.subList(count, elementsCopy.size()); FilesystemPath pathCopy = new FilesystemPath(elementsCopy); pathCopy.isAbsolute = isAbsolute;/*from w w w .j a v a 2s .c o m*/ return pathCopy; }
From source file:org.kew.rmf.matchconf.web.CustomWireController.java
@RequestMapping(value = "/{configType}_configs/{configName}/wires", produces = "text/html") public String list(@PathVariable("configType") String configType, @PathVariable("configName") String configName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) { uiModel.addAttribute("availableItems", LibraryScanner.availableItems()); List<Wire> wires = Configuration.findConfigurationsByNameEquals(configName).getSingleResult().getWiring(); if (page != null || size != null) { int sizeNo = Math.min(size == null ? 10 : size.intValue(), wires.size()); final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo; uiModel.addAttribute("wires", wires.subList(firstResult, sizeNo)); float nrOfPages = (float) wires.size() / sizeNo; uiModel.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages)); } else {/*w w w .java 2 s . co m*/ uiModel.addAttribute("wires", wires); } uiModel.addAttribute("configName", configName); return String.format("%s_config_wires/list", ConfigSwitch.getTypeForUrl(configName)); }