List of usage examples for java.util List subList
List<E> subList(int fromIndex, int toIndex);
From source file:com.acc.storefront.controllers.pages.SearchPageController.java
protected <E> List<E> subList(final List<E> list, final int maxElements) { if (CollectionUtils.isEmpty(list)) { return Collections.emptyList(); }//from ww w . j av a 2 s .c o m if (list.size() > maxElements) { return list.subList(0, maxElements); } return list; }
From source file:au.edu.anu.metadatastores.service.search.SearchOptions.java
/** * Search metadata stores for the values * /*from w ww . j a va 2s . c o m*/ * @param system The source system * @param searchTerms The search terms defined by their field and value * @return */ public Map<String, Object> advancedSearch(String system, List<SearchTerm> searchTerms, int offset, int rows) { Map<String, Object> model = new HashMap<String, Object>(); model.put("rows", getRows(rows)); SearchService searchService = SearchService.getSingleton(); if (searchTerms != null && searchTerms.size() > 0) { List<ItemDTO> items = searchService.queryItems(system, searchTerms); items = permissionService.filterItems(items); model.put("numItems", items.size()); if (rows > 0) { items = items.subList(offset, Math.min(items.size(), offset + rows)); } model.put("items", items); } model.put("systemTypes", getSystemTypes()); model.put("attrTypes", getAttributeTypes(system)); return model; }
From source file:net.duckling.ddl.service.browselog.impl.BrowseLogServiceImpl.java
@Override public List<BrowseLog> getVisitor(int rid, int count) { List<BrowseLog> historyLog = historyDao.getResourceVisitor(rid, count); List<BrowseLog> todayLog = todayDao.getResourceVisitor(rid, count); todayLog.addAll(historyLog);/*ww w . ja va2 s .c om*/ if (todayLog == null || todayLog.isEmpty()) { return Collections.emptyList(); } else if (todayLog.size() < count) { return todayLog; } return todayLog.subList(0, count); }
From source file:com.hp.octane.integrations.uft.UftTestDispatchUtils.java
private static boolean postScmResources(EntitiesService entitiesService, List<ScmResourceFile> resources, String workspaceId, String scmRepositoryId) { if (!resources.isEmpty()) { //CONVERT TO DTO List<Entity> entitiesForPost = new ArrayList<>(resources.size()); Entity scmRepository = dtoFactory.newDTO(Entity.class) .setType(EntityConstants.ScmRepository.ENTITY_NAME).setId(scmRepositoryId); for (ScmResourceFile resource : resources) { Entity entity = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmResourceFile.ENTITY_NAME) .setName(resource.getName()) .setField(EntityConstants.ScmResourceFile.SCM_REPOSITORY_FIELD, scmRepository) .setField(EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD, resource.getRelativePath()); entitiesForPost.add(entity); }/*w w w . j ava 2 s. c o m*/ //POST for (int i = 0; i < resources.size(); i += POST_BULK_SIZE) try { List<Entity> subList = entitiesForPost.subList(i, Math.min(i + POST_BULK_SIZE, entitiesForPost.size())); entitiesService.postEntities(Long.parseLong(workspaceId), EntityConstants.ScmResourceFile.COLLECTION_NAME, subList); } catch (OctaneBulkException e) { return checkIfExceptionCanBeIgnoredInPOST(e, "Failed to post scm resource files"); } } return true; }
From source file:com.netflix.spinnaker.clouddriver.jobs.JobRequest.java
private CommandLine createCommandLine(List<String> tokenizedCommand) { if (tokenizedCommand == null || tokenizedCommand.size() == 0) { throw new IllegalArgumentException("No tokenizedCommand specified."); }/*from w w w . j ava2 s . co m*/ // Grab the first element as the command. CommandLine commandLine = new CommandLine(tokenizedCommand.get(0)); int size = tokenizedCommand.size(); String[] arguments = tokenizedCommand.subList(1, size).toArray(new String[size - 1]); commandLine.addArguments(arguments, false); return commandLine; }
From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.ProviderInterface.java
public void reapOrcaServerGroups(AccountDeploymentDetails<T> details, OrcaService orcaService) { Orca orca = connectTo(details, orcaService); Map<String, Orca.ActiveExecutions> executions = orca.getActiveExecutions(); Map<String, Integer> executionsByServerGroup = new HashMap<>(); // Record the total number of executions in each pool of orcas. executions.forEach((s, e) -> {/*from ww w . j ava 2s. c om*/ String instanceName = s.split("@")[1]; String serverGroupName = getServerGroupFromInstanceId(details, orcaService, instanceName); int count = executionsByServerGroup.getOrDefault(serverGroupName, 0); count += e.getCount(); executionsByServerGroup.put(serverGroupName, count); }); // Omit the last deployed orcas from being deleted, since they are kept around for rollbacks. List<String> allOrcas = new ArrayList<>(executionsByServerGroup.keySet()); allOrcas.sort(String::compareTo); int orcaCount = allOrcas.size(); if (orcaCount <= MAX_REMAINING_SERVER_GROUPS) { return; } allOrcas = allOrcas.subList(0, orcaCount - MAX_REMAINING_SERVER_GROUPS); for (String orcaName : allOrcas) { // TODO(lwander) consult clouddriver to ensure this orca isn't enabled if (executionsByServerGroup.get(orcaName) == 0) { DaemonTaskHandler.log("Reaping old orca instance " + orcaName); deleteServerGroup(details, orcaService, orcaName); } } }
From source file:com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot.java
public ResourceWorkerSlot(WorkerAssignment worker, Map<String, List<Integer>> componentToTask) { super(worker.getNodeId(), worker.getPort()); this.hostname = worker.getHostName(); this.tasks = new HashSet<Integer>(); this.cpu = worker.getCpu(); this.memSize = worker.getMem(); this.jvm = worker.getJvm(); for (Entry<String, Integer> entry : worker.getComponentToNum().entrySet()) { List<Integer> tasks = componentToTask.get(entry.getKey()); if (tasks == null || tasks.size() == 0) continue; int num = Math.min(tasks.size(), entry.getValue().intValue()); List<Integer> cTasks = new ArrayList<Integer>(); cTasks.addAll(tasks.subList(0, num)); this.tasks.addAll(cTasks); tasks.removeAll(cTasks);/*from ww w .ja v a 2 s .c om*/ } }
From source file:co.rsk.mine.BlockToMineBuilder.java
/** * build creates a block to mine based on the given block as parent. * * @param newBlockParent the new block parent. * @param extraData extra data to pass to the block being built *//*from w ww .jav a 2s.c o m*/ public Block build(Block newBlockParent, byte[] extraData) { List<BlockHeader> uncles = FamilyUtils.getUnclesHeaders(blockStore, newBlockParent.getNumber() + 1, newBlockParent.getHash().getBytes(), miningConfig.getUncleGenerationLimit()); if (uncles.size() > miningConfig.getUncleListLimit()) { uncles = uncles.subList(0, miningConfig.getUncleListLimit()); } Coin minimumGasPrice = minimumGasPriceCalculator.calculate(newBlockParent.getMinimumGasPrice(), minerMinGasPriceTarget); final List<Transaction> txsToRemove = new ArrayList<>(); final List<Transaction> txs = getTransactions(txsToRemove, newBlockParent, minimumGasPrice); final Block newBlock = createBlock(newBlockParent, uncles, txs, minimumGasPrice); newBlock.setExtraData(extraData); removePendingTransactions(txsToRemove); executor.executeAndFill(newBlock, newBlockParent); return newBlock; }
From source file:com.ewcms.common.query.cache.CacheResult.java
public void appendResultList(List<Object> list) { int space = count - resultList.size(); if (space <= 0) { return;//ww w .ja v a 2s . c o m } modified = true; if (space > list.size()) { resultList.addAll(list); } else { resultList.addAll(list.subList(0, space)); } }
From source file:com.all.login.services.LoginModelDao.java
public List<Login> getLastLogins() { List<Login> allLogins = new ArrayList<Login>(db.getDB().getLogins()); Collections.sort(allLogins);/*from w w w. j a va 2 s .com*/ return allLogins.subList(0, Math.min(5, allLogins.size())); }