List of usage examples for java.util List stream
default Stream<E> stream()
From source file:de.metas.ui.web.window.datatypes.json.JSONDocument.java
public static List<JSONDocument> ofDocumentViewList(final List<IDocumentView> documentViews) { return documentViews.stream().map(JSONDocument::ofDocumentView).collect(Collectors.toList()); }
From source file:info.archinnov.achilles.internals.parser.validator.BeanValidator.java
public static void validateViewsAgainstBaseTable(AptUtils aptUtils, List<EntityMetaSignature> viewSignatures, List<EntityMetaSignature> entitySignatures) { final Map<TypeName, List<TypeParsingResult>> entitySignaturesMap = entitySignatures.stream() .collect(toMap(meta -> meta.entityRawClass, meta -> meta.parsingResults)); for (EntityMetaSignature view : viewSignatures) { final TypeName viewBaseClass = view.viewBaseClass.get(); final List<TypeParsingResult> entityParsingResults = entitySignaturesMap.get(viewBaseClass); aptUtils.validateTrue(entityParsingResults != null, "Cannot find base entity class '%s' for view class '%s'", viewBaseClass, view.entityRawClass); // Validate all view columns are in base and have correct name & types for (TypeParsingResult vpr : view.parsingResults) { final long count = entityParsingResults.stream().filter(epr -> epr.equalsTo(vpr)).count(); aptUtils.validateTrue(count == 1, "Cannot find any match in base table for field '%s' in view class '%s'", vpr.toStringForViewCheck(), view.entityRawClass); }//from w w w. j av a 2 s . c o m final List<TypeParsingResult> viewPKColumns = view.parsingResults.stream() .filter(vpr -> vpr.context.columnType == ColumnType.PARTITION || vpr.context.columnType == ColumnType.CLUSTERING) .collect(toList()); final List<TypeParsingResult> basePKColumns = entityParsingResults.stream() .filter(vpr -> vpr.context.columnType == ColumnType.PARTITION || vpr.context.columnType == ColumnType.CLUSTERING) .collect(toList()); final List<TypeParsingResult> baseCollectionColumns = entityParsingResults.stream() .filter(vpr -> vpr.targetType instanceof ParameterizedTypeName).filter(vpr -> { final ClassName rawType = ((ParameterizedTypeName) vpr.targetType).rawType; return rawType.equals(TypeUtils.LIST) || rawType.equals(TypeUtils.SET) || rawType.equals(TypeUtils.MAP) || rawType.equals(TypeUtils.JAVA_DRIVER_UDT_VALUE_TYPE); }).collect(toList()); // Validate all base PK columns are in view PK columns for (TypeParsingResult epr : basePKColumns) { final long count = viewPKColumns.stream().filter(vpr -> vpr.equalsTo(epr)).count(); aptUtils.validateTrue(count == 1, "Primary key column '%s' in base class %s is not found in view class '%s' as primary key column", epr.toStringForViewCheck(), epr.context.entityRawType, view.entityRawClass); } // Validate collections in base should be in view for (TypeParsingResult epr : baseCollectionColumns) { final long count = view.parsingResults.stream().filter(vpr -> vpr.equalsTo(epr)).count(); aptUtils.validateTrue(count == 1, "Collection/UDT column '%s' in base class %s is not found in view class '%s'. It should be included in the view", epr.toStringForViewCheck(), epr.context.entityRawType, view.entityRawClass); } // Validate max 1 non-PK column from base in view PK final List<TypeParsingResult> viewPKColumnNotInBase = new ArrayList<>(); for (TypeParsingResult vpr : viewPKColumns) { final long count = basePKColumns.stream().filter(epr -> epr.equalsTo(vpr)).count(); if (count == 0) viewPKColumnNotInBase.add(vpr); } aptUtils.validateTrue(viewPKColumnNotInBase.size() <= 1, "There should be maximum 1 column in the view %s primary key " + "that is NOT a primary column of the base class '%s'. We have %s", view.entityRawClass, viewBaseClass, viewPKColumnNotInBase.stream().map(x -> x.toStringForViewCheck()).collect(toList())); } }
From source file:api.wiki.WikiGenerator.java
private static String apiClassMethodLinks(Class<?> declaringClass, List<ApiDocumentation> apiDocumentations) { return "## " + declaringClass.getSimpleName() + "\n" + apiDocumentations.stream().map(apiDocumentation -> apiDocumentation.apiMethod) .sorted(comparing(Method::getName)).map(apiMethod -> "* " + hyperLink(apiMethod)) .collect(joining("\n")); }
From source file:alfio.util.Validator.java
public static ValidationResult validateAdditionalFields(List<TicketFieldConfiguration> fieldConf, EventModification.AdditionalField field, Errors errors) { String duplicateName = fieldConf.stream().filter(f -> f.getName().equalsIgnoreCase(field.getName())) .map(TicketFieldConfiguration::getName).findAny().orElse(""); if (StringUtils.isNotBlank(duplicateName)) { errors.rejectValue("name", ErrorCode.DUPLICATE); }//from ww w. j a va2 s . c o m return evaluateValidationResult(errors); }
From source file:io.github.retz.scheduler.Launcher.java
private static void maybeRequeueRunningJobs(String master, String frameworkId, List<Job> running) { LOG.info("{} jobs found in DB 'STARTING' or 'STARTED' state. Requeuing...", running.size()); int offset = 0; int limit = 128; Map<String, Job> runningMap = running.stream().collect(Collectors.toMap(job -> job.taskId(), job -> job)); List<Job> recoveredJobs = new LinkedList<>(); while (true) { try {/*from w w w .j a v a2s .c o m*/ List<Map<String, Object>> tasks = MesosHTTPFetcher.fetchTasks(master, frameworkId, offset, limit); if (tasks.isEmpty()) { break; } for (Map<String, Object> task : tasks) { String state = (String) task.get("state"); // Get TaskId String taskId = (String) task.get("id"); if (runningMap.containsKey(taskId)) { Job job = runningMap.remove(taskId); recoveredJobs.add(JobQueue.updateJobStatus(job, state)); } else { LOG.warn("Unknown job!"); } } offset = offset + tasks.size(); } catch (MalformedURLException e) { LOG.error(e.toString()); throw new RuntimeException(e.toString()); } } Database.getInstance().updateJobs(recoveredJobs); LOG.info("{} jobs rescheduled, {} jobs didn't need change.", recoveredJobs.size(), runningMap.size()); }
From source file:alfio.manager.StripeManager.java
static String getFeeAmount(List<Fee> fees, String feeType) { return fees.stream().filter(f -> f.getType().equals(feeType)).findFirst().map(Fee::getAmount) .map(String::valueOf).orElse(null); }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static List<String> collectFileNames(List<File> files) { return files.stream().map(StringUtils::toUnixString).collect(Collectors.toList()); }
From source file:com.github.mavogel.ilias.utils.IOUtils.java
/** * Expands the ranges.<br>//from w w w . j a v a2 s.c om * Example: * <ul> * <li>1-4 -> 1,2,3,4</li> * <li>1-4,6-8 -> 1,2,3,4,6,7,8</li> * </ul> * * @param ranges the ranges to expand * @return the expanded ranges. */ private static Optional<Stream<Integer>> expandRanges(List<String[]> ranges) { // TODO maybe as Integer[] return ranges.stream().map( eachRange -> IntStream.rangeClosed(Integer.valueOf(eachRange[0]), Integer.valueOf(eachRange[1]))) .map(eachExpandedRange -> eachExpandedRange.mapToObj(Integer::valueOf)).reduce(Stream::concat); }
From source file:com.yahoo.bullet.parsing.RuleUtils.java
public static String makeFilter(List<Clause> values, FilterType operation) { return "{" + "'operation' : " + makeString(getOperationFor(operation)) + ", " + "'clauses' : [" + values.stream().map(RuleUtils::toString).reduce((a, b) -> a + " , " + b).orElse("") + "]" + "}"; }
From source file:com.github.mavogel.ilias.utils.IOUtils.java
/** * Checks for valid characters in tokens. * * @param tokens the tokens @see {@link IOUtils#splitAndTrim(String)} * @throws IllegalArgumentException if there is an invalid token */// w ww.j av a 2s .c o m private static void checkForInvalidCharacters(final List<String> tokens) { Optional<String> invalidChoice = tokens.stream().filter( s -> !Defaults.DIGIT_PATTERN.matcher(s).matches() && !Defaults.RANGE_PATTERN.matcher(s).matches()) .findAny(); if (invalidChoice.isPresent()) throw new IllegalArgumentException("Contains invalid indexes and/or ranges or an invalid wildcard!"); }