List of usage examples for java.util List removeIf
default boolean removeIf(Predicate<? super E> filter)
From source file:com.bombardier.plugin.scheduling.TestScheduler.java
/** * Used to get the number of lines in a file ignoring lines that are empty * or contain only white spaces./*from w w w.ja va 2s . c om*/ * * @param file * the file to be read * @return the number of lines * @throws Exception * @since 1.0 */ private int getNumOfLines(FilePath file) throws Exception { List<String> list = Files.readAllLines(Paths.get(file.absolutize().toURI()), StandardCharsets.UTF_8); // remove empty lines list.removeIf(new Predicate<String>() { @Override public boolean test(String arg0) { return !StringUtils.isNotBlank(arg0); } }); return list.size(); }
From source file:org.egov.tl.web.actions.viewtradelicense.ViewTradeLicenseAction.java
@Override public List<String> getValidActions() { List<String> validActions = new ArrayList<>(); if (null == getModel() || null == getModel().getId() || getModel().getCurrentState() == null || (getModel() != null && getModel().getCurrentState() != null ? getModel().getCurrentState().isEnded() : false)) {/*from w ww . j a va 2 s . com*/ validActions = Arrays.asList(FORWARD); } else if (getModel().getCurrentState() != null) { validActions.addAll(this.customizedWorkFlowService.getNextValidActions(getModel().getStateType(), getWorkFlowDepartment(), getAmountRule(), getAdditionalRule(), getModel().getCurrentState().getValue(), getPendingActions(), getModel().getCreatedDate())); validActions.removeIf(validAction -> "Reassign".equals(validAction) && getModel().getState().getCreatedBy().getId().equals(ApplicationThreadLocals.getUserId())); } return validActions; }
From source file:com.codelanx.codelanxlib.command.CommandNode.java
/** * Called from Bukkit to indicate a call for tab completing * <br><br> {@inheritDoc}//from w w w . j av a 2s . c o m * * @since 0.1.0 * @version 0.1.0 * * @param sender {@inheritDoc} * @param command {@inheritDoc} * @param alias {@inheritDoc} * @param args {@inheritDoc} * @return {@inheritDoc} */ @Override public final List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { Exceptions.illegalPluginAccess(Reflections.accessedFromBukkit(), "Only bukkit may call this method"); CommandNode<? extends Plugin> child = this.getClosestChild(StringUtils.join(args, " ")); List<String> back = new ArrayList<>(); List<String> tabd = child.tabComplete(sender, args); Exceptions.notNull(tabd, "Cannot return null from CommandNode#tabComplete", IllegalReturnException.class); Exceptions.isTrue(tabd.stream().noneMatch(Lambdas::isNull), "Cannot return null elements from CommandNode#tabComplete", IllegalReturnException.class); back.addAll(tabd); if (!child.subcommands.isEmpty()) { List<String> valid = child.subcommands.entrySet().stream().filter(ent -> { return ent.getValue().perms.stream().allMatch(p -> p.has(sender)); }).map(ent -> ent.getKey()).collect(Collectors.toList()); if (args.length == 1) { valid.removeIf(s -> !s.startsWith(args[0])); } back.addAll(valid); } return back; }
From source file:gov.llnl.lc.smt.command.file.SmtFile.java
private List<String> getFileList(String fileName) { List<String> fileList = new ArrayList<String>(); try {// w w w.j a v a2s . co m BufferedReader br = Files.newBufferedReader(Paths.get(fileName)); //br returns as stream and convert it into a List fileList = br.lines().collect(Collectors.toList()); // trim empty lines from list fileList.removeIf(s -> s.isEmpty()); // trim comment lines from list fileList.removeIf(s -> s.startsWith("#")); } catch (IOException e) { e.printStackTrace(); } return fileList; }
From source file:io.druid.query.lookup.LookupReferencesManager.java
private void startLookups(final List<LookupBean> lookupBeanList) { final ImmutableMap.Builder<String, LookupExtractorFactoryContainer> builder = ImmutableMap.builder(); final ExecutorService executorService = Execs.multiThreaded(lookupConfig.getNumLookupLoadingThreads(), "LookupReferencesManager-Startup-%s"); final CompletionService<Map.Entry<String, LookupExtractorFactoryContainer>> completionService = new ExecutorCompletionService<>( executorService);//from w w w . java 2 s . com final List<LookupBean> remainingLookups = new ArrayList<>(lookupBeanList); try { LOG.info("Starting lookup loading process"); for (int i = 0; i < lookupConfig.getLookupStartRetries() && !remainingLookups.isEmpty(); i++) { LOG.info("Round of attempts #%d, [%d] lookups", i + 1, remainingLookups.size()); final Map<String, LookupExtractorFactoryContainer> successfulLookups = startLookups( remainingLookups, completionService); builder.putAll(successfulLookups); remainingLookups.removeIf(l -> successfulLookups.containsKey(l.getName())); } if (!remainingLookups.isEmpty()) { LOG.warn("Failed to start the following lookups after [%d] attempts: [%s]", lookupConfig.getLookupStartRetries(), remainingLookups); } stateRef.set(new LookupUpdateState(builder.build(), ImmutableList.of(), ImmutableList.of())); } catch (InterruptedException | RuntimeException e) { LOG.error(e, "Failed to finish lookup load process."); } finally { executorService.shutdownNow(); } }
From source file:io.dockstore.webservice.helpers.Helper.java
@SuppressWarnings("checkstyle:parameternumber") public static Tool refreshContainer(final long containerId, final long userId, final HttpClient client, final ObjectMapper objectMapper, final UserDAO userDAO, final ToolDAO toolDAO, final TokenDAO tokenDAO, final TagDAO tagDAO, final FileDAO fileDAO) { Tool tool = toolDAO.findById(containerId); String gitUrl = tool.getGitUrl(); Map<String, String> gitMap = SourceCodeRepoFactory.parseGitUrl(gitUrl); if (gitMap == null) { LOG.info("Could not parse Git URL. Unable to refresh tool!"); return tool; }//w w w .j ava 2s . c om String gitSource = gitMap.get("Source"); String gitUsername = gitMap.get("Username"); String gitRepository = gitMap.get("Repository"); // Get user's quay and git tokens List<Token> tokens = tokenDAO.findByUserId(userId); Token quayToken = extractToken(tokens, TokenType.QUAY_IO.toString()); Token githubToken = extractToken(tokens, TokenType.GITHUB_COM.toString()); Token bitbucketToken = extractToken(tokens, TokenType.BITBUCKET_ORG.toString()); // with Docker Hub support it is now possible that there is no quayToken if (gitSource.equals("github.com") && githubToken == null) { LOG.info("WARNING: GITHUB token not found!"); throw new CustomWebApplicationException("A valid GitHub token is required to refresh this tool.", HttpStatus.SC_CONFLICT); //throw new CustomWebApplicationException("A valid GitHub token is required to refresh this tool.", HttpStatus.SC_CONFLICT); } if (gitSource.equals("bitbucket.org") && bitbucketToken == null) { LOG.info("WARNING: BITBUCKET token not found!"); throw new CustomWebApplicationException("A valid Bitbucket token is required to refresh this tool.", HttpStatus.SC_BAD_REQUEST); } if (tool.getRegistry() == Registry.QUAY_IO && quayToken == null) { LOG.info("WARNING: QUAY.IO token not found!"); throw new CustomWebApplicationException("A valid Quay.io token is required to refresh this tool.", HttpStatus.SC_BAD_REQUEST); } ImageRegistryFactory factory = new ImageRegistryFactory(client, objectMapper, quayToken); final ImageRegistryInterface anInterface = factory.createImageRegistry(tool.getRegistry()); List<Tool> apiTools = new ArrayList<>(); // Find a tool with the given tool's Path and is not manual Tool duplicatePath = null; List<Tool> containersList = toolDAO.findByPath(tool.getPath()); for (Tool c : containersList) { if (c.getMode() != ToolMode.MANUAL_IMAGE_PATH) { duplicatePath = c; break; } } // If exists, check conditions to see if it should be changed to auto (in sync with quay tags and git repo) if (tool.getMode() == ToolMode.MANUAL_IMAGE_PATH && duplicatePath != null && tool.getRegistry().toString().equals(Registry.QUAY_IO.toString()) && duplicatePath.getGitUrl().equals(tool.getGitUrl())) { tool.setMode(duplicatePath.getMode()); } if (tool.getMode() == ToolMode.MANUAL_IMAGE_PATH) { apiTools.add(tool); } else { List<String> namespaces = new ArrayList<>(); namespaces.add(tool.getNamespace()); if (anInterface != null) { apiTools.addAll(anInterface.getContainers(namespaces)); } } apiTools.removeIf(container1 -> !container1.getPath().equals(tool.getPath())); Map<String, ArrayList<?>> mapOfBuilds = new HashMap<>(); if (anInterface != null) { mapOfBuilds.putAll(anInterface.getBuildMap(apiTools)); } List<Tool> dbTools = new ArrayList<>(); dbTools.add(tool); removeContainersThatCannotBeUpdated(dbTools); final User dockstoreUser = userDAO.findById(userId); // update information on a tool by tool level updateContainers(apiTools, dbTools, dockstoreUser, toolDAO); userDAO.clearCache(); final List<Tool> newDBTools = new ArrayList<>(); newDBTools.add(toolDAO.findById(tool.getId())); // update information on a tag by tag level final Map<String, List<Tag>> tagMap = getTags(client, newDBTools, objectMapper, quayToken, mapOfBuilds); updateTags(newDBTools, client, toolDAO, tagDAO, fileDAO, githubToken, bitbucketToken, tagMap); userDAO.clearCache(); return toolDAO.findById(tool.getId()); }
From source file:org.openlmis.fulfillment.web.ProofOfDeliveryController.java
/** * Get all proofs of delivery./* w w w . j ava 2 s .co m*/ * * @return proofs of delivery. */ @RequestMapping(value = "/proofsOfDelivery", method = RequestMethod.GET) @ResponseBody public Page<ProofOfDeliveryDto> getAllProofsOfDelivery(@RequestParam(required = false) UUID orderId, @RequestParam(required = false) UUID shipmentId, Pageable pageable) { XLOGGER.entry(shipmentId, pageable); Profiler profiler = new Profiler("GET_PODS"); profiler.setLogger(XLOGGER); List<ProofOfDelivery> content; if (null == shipmentId && null == orderId) { profiler.start("GET_ALL_PODS"); content = proofOfDeliveryRepository.findAll(); } else if (null != shipmentId) { profiler.start("FIND_PODS_BY_SHIPMENT_ID"); content = proofOfDeliveryRepository.findByShipmentId(shipmentId); } else { profiler.start("FIND_PODS_BY_ORDER_ID"); content = proofOfDeliveryRepository.findByOrderId(orderId); } UserDto user = authenticationHelper.getCurrentUser(); if (null != user) { profiler.start(CHECK_PERMISSION); PermissionStrings.Handler handler = permissionService.getPermissionStrings(user.getId()); Set<PermissionStringDto> permissionStrings = handler.get(); content.removeIf(proofOfDelivery -> { UUID receivingFacilityId = proofOfDelivery.getReceivingFacilityId(); UUID supplyingFacilityId = proofOfDelivery.getSupplyingFacilityId(); UUID programId = proofOfDelivery.getProgramId(); return permissionStrings.stream() .noneMatch(elem -> elem.match(PODS_MANAGE, receivingFacilityId, programId) || elem.match(PODS_VIEW, receivingFacilityId, programId) || elem.match(SHIPMENTS_EDIT, supplyingFacilityId, null)); }); } profiler.start("BUILD_DTOS"); List<ProofOfDeliveryDto> dto = dtoBuilder.build(content); profiler.start("BUILD_DTO_PAGE"); Page<ProofOfDeliveryDto> dtoPage = Pagination.getPage(dto, pageable); profiler.stop().log(); XLOGGER.exit(dtoPage); return dtoPage; }
From source file:com.dgtlrepublic.anitomyj.Parser.java
/** Search for episode number. */ private void SearchForEpisodeNumber() { // List all unknown tokens that contain a number List<Result> tokens = new ArrayList<>(); for (int i = 0; i < this.tokens.size(); i++) { Token token = this.tokens.get(i); if (token.getCategory() == kUnknown && ParserHelper.indexOfFirstDigit(token.getContent()) != -1) { tokens.add(new Result(token, i)); }// www . ja v a 2s . c o m } if (tokens.isEmpty()) return; isEpisodeKeywordsFound = !empty(kElementEpisodeNumber); // If a token matches a known episode pattern, it has to be the episode number if (parserNumber.searchForEpisodePatterns(tokens)) return; // We have previously found an episode number via keywords if (!empty(kElementEpisodeNumber)) return; // From now on, we're only interested in numeric tokens tokens.removeIf(r -> !StringHelper.isNumericString(r.token.getContent())); // e.g. "01 (176)", "29 (04)" if (parserNumber.searchForEquivalentNumbers(tokens)) return; // e.g. " - 08" if (parserNumber.searchForSeparatedNumbers(tokens)) return; // e.g. "[12]", "(2006)" if (parserNumber.searchForIsolatedNumbers(tokens)) return; // Consider using the last number as a last resort parserNumber.searchForLastNumber(tokens); }
From source file:org.codice.ddf.catalog.ui.config.ConfigurationApplication.java
private void findDifferences(List<Map<String, Object>> innerList, List<Map<String, Object>> outerList, List<Map<String, Object>> differences) { differences.addAll(outerList);//from ww w . jav a2 s.co m differences.removeIf(innerList::contains); }
From source file:org.wso2.is.portal.user.client.api.ChallengeQuestionManagerClientServiceImpl.java
public List<ChallengeQuestionSetEntry> getRemainingChallengeQuestions(String userUniqueId) throws IdentityRecoveryException, IdentityStoreException, UserNotFoundException { if (challengeQuestionManager == null) { throw new IdentityRecoveryException("Challenge question manager is not available."); }//from w w w . ja v a2s.c o m if (realmService == null) { throw new IdentityRecoveryException("Realm service is not available."); } List<ChallengeQuestionSetEntry> challengeQuestionSetEntries = getChallengeQuestionList(userUniqueId); List<UserChallengeAnswer> existingAnswers = getChallengeAnswersOfUser(userUniqueId); List<String> listofSetIds = new ArrayList<String>(); for (ChallengeQuestionSetEntry challengeQuestionSetEntry : challengeQuestionSetEntries) { listofSetIds.add(challengeQuestionSetEntry.getChallengeQuestionSetId()); } Iterator<UserChallengeAnswer> existingAnswersIterator = existingAnswers.iterator(); while (existingAnswersIterator.hasNext()) { ChallengeQuestion challengeQuestion = existingAnswersIterator.next().getQuestion(); for (int i = 0; i < listofSetIds.size(); i++) { if (StringUtils.equals(challengeQuestion.getQuestionSetId(), new String(Base64.getDecoder().decode(listofSetIds.get(i).getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8))) { String setId = listofSetIds.get(i); challengeQuestionSetEntries.removeIf(challengeQuestionSetEntry -> StringUtils .equals(challengeQuestionSetEntry.getChallengeQuestionSetId(), setId)); } } } return challengeQuestionSetEntries; }