List of usage examples for java.util List stream
default Stream<E> stream()
From source file:info.archinnov.achilles.internals.parser.CodecFactory.java
public static CodecContext buildCodecContext(AptUtils aptUtils, AnnotationMirror codecFromType) { Optional<Class<Codec>> codecClassO = getElementValueClass(codecFromType, "value", false); if (codecClassO.isPresent()) { Class<Codec> codecClass = codecClassO.get(); List<Type> genericTypes = Arrays.asList(codecClass.getGenericInterfaces()); final List<TypeName> codecTypes = genericTypes.stream().filter(x -> x instanceof ParameterizedType) .map(x -> (ParameterizedType) x) .filter(x -> x.getRawType().getTypeName() .equals(info.archinnov.achilles.type.codec.Codec.class.getCanonicalName())) .flatMap(x -> Arrays.asList(x.getActualTypeArguments()).stream()).map(TypeName::get) .collect(Collectors.toList()); aptUtils.validateTrue(codecTypes.size() == 2, "Codec class '%s' should have 2 parameters: Codec<FROM, TO>", codecClass); return new CodecContext(ClassName.get(codecClass), codecTypes.get(0), codecTypes.get(1)); } else {/*from w w w. ja va 2s . co m*/ return buildCodecContext(aptUtils, getElementValueClassName(codecFromType, "value", false).toString()); } }
From source file:com.thinkbiganalytics.feedmgr.util.ImportUtil.java
public static void addToImportOptionsSensitiveProperties(ImportOptions importOptions, List<NifiProperty> sensitiveProperties, ImportComponent component) { ImportComponentOption option = importOptions.findImportComponentOption(component); if (option.getProperties().isEmpty()) { option.setProperties(sensitiveProperties.stream().map(p -> new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType())).collect(Collectors.toList())); } else {// ww w . ja va2 s .c om //only add in those that are unique Map<String, ImportProperty> propertyMap = option.getProperties().stream() .collect(Collectors.toMap(p -> p.getProcessorNameTypeKey(), p -> p)); sensitiveProperties.stream() .filter(nifiProperty -> !propertyMap.containsKey(nifiProperty.getProcessorNameTypeKey())) .forEach(p -> { option.getProperties().add(new ImportProperty(p.getProcessorName(), p.getProcessorId(), p.getKey(), "", p.getProcessorType())); }); } }
From source file:com.ikanow.aleph2.distributed_services.utils.KafkaUtils.java
/** Generates a connection string by reading ZooKeeper * @param curator/* w w w .jav a 2 s. c om*/ * @param path_override * @return * @throws Exception */ public static String getBrokerListFromZookeeper(final CuratorFramework curator, Optional<String> path_override, final ObjectMapper mapper) throws Exception { final String path = path_override.orElse("/brokers/ids"); final List<String> brokers = curator.getChildren().forPath(path); return brokers.stream() .map(Lambdas.wrap_u(broker_node -> new String(curator.getData().forPath(path + "/" + broker_node)))) .flatMap(Lambdas.flatWrap_i(broker_str -> mapper.readTree(broker_str))) // (just discard any badly formatted nodes) .flatMap(Lambdas.flatWrap_i(json -> json.get("host").asText() + ":" + json.get("port").asText())) .collect(Collectors.joining(",")); }
From source file:com.github.mavogel.ilias.utils.IOUtils.java
/** * Concatenates the digits and ranges to a distinct and sorted range: 1,3,4,6,7,... * * @param digitsInput the single digits//from w w w . j a va 2 s. com * @param rangesInput the ranges @see {@link Defaults#RANGE_PATTERN} for details * @return the sorted range */ private static List<Integer> concatDigitsAndRanges(final List<Integer> digitsInput, final List<String[]> rangesInput) { return Stream.concat(digitsInput.stream(), expandRanges(rangesInput).orElse(Stream.empty())).sorted() .distinct().collect(Collectors.toList()); }
From source file:com.streamsets.datacollector.util.PipelineConfigurationUtil.java
public static StageConfiguration getStageConfigurationWithDefaultValues(StageLibraryTask stageLibraryTask, String library, String stageName, String stageInstanceName, String labelPrefix) { StageDefinition stageDefinition = stageLibraryTask.getStage(library, stageName, false); if (stageDefinition == null) { return null; }/* w ww . ja v a 2 s.c om*/ List<Config> configurationList = new ArrayList<>(); for (ConfigDefinition configDefinition : stageDefinition.getConfigDefinitions()) { configurationList.add(getConfigWithDefaultValue(configDefinition)); } List<ServiceConfiguration> serviceConfigurationList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(stageDefinition.getServices())) { List<ServiceDefinition> serviceDefinitions = stageLibraryTask.getServiceDefinitions(); for (ServiceDependencyDefinition serviceDependencyDefinition : stageDefinition.getServices()) { ServiceDefinition serviceDefinition = serviceDefinitions.stream() .filter(s -> s.getProvides().equals(serviceDependencyDefinition.getService())).findAny() .orElse(null); if (serviceDefinition != null) { List<Config> serviceConfigList = new ArrayList<>(); for (ConfigDefinition configDefinition : serviceDefinition.getConfigDefinitions()) { if (serviceDependencyDefinition.getConfiguration() != null && serviceDependencyDefinition .getConfiguration().containsKey(configDefinition.getName())) { serviceConfigList.add(new Config(configDefinition.getName(), serviceDependencyDefinition .getConfiguration().get(configDefinition.getName()))); } else { serviceConfigList.add(getConfigWithDefaultValue(configDefinition)); } } serviceConfigurationList.add(new ServiceConfiguration(serviceDefinition.getProvides(), serviceDefinition.getVersion(), serviceConfigList)); } } } return new StageConfiguration(stageInstanceName, library, stageName, stageDefinition.getVersion(), configurationList, ImmutableMap.of("label", labelPrefix + stageDefinition.getLabel(), "stageType", stageDefinition.getType().toString()), serviceConfigurationList, new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); }
From source file:com.u2apple.tool.util.AndroidDeviceUtils.java
public static List<AndroidDeviceRanking> parse(List<AndroidDevice> devices) { List<AndroidDeviceRanking> androidDevices = new ArrayList<>(); if (devices != null && !devices.isEmpty()) { // devices.stream().forEach((device) -> { // androidDevices.add(new AndroidDeviceRanking(device)); // }); devices.stream().map(device -> new AndroidDeviceRanking(device)).forEach(androidDevices::add); }//from w w w . j a va 2s . c o m return androidDevices; }
From source file:com.cpjit.swagger4j.util.ReflectUtils.java
/** * ??????//w w w .j a va 2 s . c o m * * @param packageNames * @param recursion * ???? * @return ???null * 0 * <li>?</li> * <li>package-info.java?</li> * <li>?basePackage</li> * @since 1.0.0 */ public static List<Package> scanPackages(List<String> packageNames, boolean recursion) { if (packageNames == null || packageNames.size() < 1) { // ?? return Collections.emptyList(); } return packageNames.stream().flatMap(packName -> scanPackage(packName, recursion).stream()) .collect(Collectors.toList()); }
From source file:main.RankerOCR.java
/** * Show the help on CLI.//from w ww. j a v a 2s.c o m * <p> * Help is from <br> * -The file help.txt in the JAR <br> * -The HelpFormatter <br> * -Options. */ private static void showHelp(HelpFormatter hf, Options options) { try { //First, print the header of help and brief summary of the behaviour //<editor-fold defaultstate="collapsed" desc="Print summary"> InputStream f = RankerOCR.class.getResourceAsStream("/resources/help.txt"); InputStreamReader fr = new InputStreamReader(f); BufferedReader b = new BufferedReader(fr); StringBuilder s = new StringBuilder(); while (true) { String line = b.readLine(); if (line == null) { break; } else { s.append(line); s.append("\n"); } } printFormated(s.toString()); //</editor-fold> //Second, print the options list hf.printHelp("java -jar Ranker-OCR [options]", options); //Finnaly print the rankers list //<editor-fold defaultstate="collapsed" desc="Print rankers"> try { System.out.println("\nRankers list:"); List<Class> lst = PackageClassList.getClasses("ranking"); lst.remove(ranking.Ranker.class); lst.stream().forEach((c) -> { if (!c.isInterface()) { System.out.println(" -" + c.getSimpleName()); } }); } catch (ClassNotFoundException | IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-101); } //</editor-fold> } catch (IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-102); } }
From source file:com.streamsets.pipeline.lib.el.StringEL.java
@ElFunction(prefix = "list", name = "join", description = "Returns each element of a LIST field joined on the specified character sequence.") public static String joinList(@ElParam("list") List<Field> list, @ElParam("separator") String separator) { if (list == null) { return ""; }//from www . j ava 2s .c o m List<String> listOfStrings = list.stream() .map(field -> field.getValue() == null ? "null" : field.getValueAsString()) .collect(Collectors.toList()); return Joiner.on(separator).join(listOfStrings); }
From source file:diffhunter.Indexer.java
public static <K extends Comparable<? super K>, V> Map<K, V> sortByKey(Map<K, V> map) { Map<K, V> result = new LinkedHashMap<>(); map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())) .forEach((entry) -> result.put(entry.getKey(), entry.getValue())); List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); Collections.sort(list, (Map.Entry<K, V> o1, Map.Entry<K, V> o2) -> (o1.getKey()).compareTo(o2.getKey())); list.stream().forEach((entry) -> { result.put(entry.getKey(), entry.getValue()); });//from w w w. ja va 2 s .c o m return result; }