List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:de.flashpixx.rrd_antlr4.CMain.java
/** * main/*from w w w .java2 s.co m*/ * * @param p_args command-line arguments * @throws IOException on any io error */ public static void main(final String[] p_args) throws IOException { // --- define CLI options --- final Options l_clioptions = new Options(); l_clioptions.addOption("help", false, CCommon.languagestring(CMain.class, "help")); l_clioptions.addOption("output", true, CCommon.languagestring(CMain.class, "output", DEFAULTOUTPUT)); l_clioptions.addOption("imports", true, CCommon.languagestring(CMain.class, "import")); l_clioptions.addOption("excludes", true, CCommon.languagestring(CMain.class, "exclude")); l_clioptions.addOption("grammar", true, CCommon.languagestring(CMain.class, "grammar")); l_clioptions.addOption("language", true, CCommon.languagestring(CMain.class, "language")); l_clioptions.addOption("docclean", true, CCommon.languagestring(CMain.class, "documentationclean")); l_clioptions.addOption("templates", true, CCommon.languagestring(CMain.class, "template", Arrays.asList(ETemplate.values()), DEFAULTTEMPLATE)); final CommandLine l_cli; try { l_cli = new DefaultParser().parse(l_clioptions, p_args); } catch (final Exception l_exception) { System.err .println(CCommon.languagestring(CMain.class, "parseerror", l_exception.getLocalizedMessage())); System.exit(-1); return; } // --- process CLI arguments and push configuration --- if (l_cli.hasOption("help")) { final HelpFormatter l_formatter = new HelpFormatter(); l_formatter.printHelp( new java.io.File(CMain.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getName(), l_clioptions); System.exit(0); } if (!l_cli.hasOption("grammar")) { System.err.println(CCommon.languagestring(CMain.class, "grammarnotset")); System.exit(-1); } final Tuple5<File, Set<ETemplate>, Set<File>, Set<String>, Set<String>> l_initdata = CMain.initialize( l_cli.getOptionValue("language"), l_cli.hasOption("output") ? l_cli.getOptionValue("output") : DEFAULTOUTPUT, l_cli.hasOption("templates") ? l_cli.getOptionValue("templates").split(",") : new String[] { DEFAULTTEMPLATE }, l_cli.getOptionValue("imports", "").split(","), l_cli.getOptionValue("excludes", "").split(","), l_cli.getOptionValue("docclean", "").split(",")); // --- run generator --- final IGenerator l_generator = new CStandalone(l_initdata.v1(), l_initdata.v3(), l_initdata.v5(), l_initdata.v2()); if (Arrays.stream(l_cli.getOptionValue("grammar").split(",")) .flatMap(i -> CMain.filelist(new File(i.trim()), l_initdata.v3(), l_initdata.v4())) .map(i -> l_generator.generate(i).hasError()).findFirst().isPresent()) System.exit(-1); l_generator.finish(); }
From source file:Main.java
public static <T> Set<T> asSet(T... values) { return Arrays.stream(values).collect(Collectors.toCollection(LinkedHashSet::new)); }
From source file:Main.java
public static <T> List<T> asList(T... values) { return Arrays.stream(values).collect(Collectors.toList()); }
From source file:Main.java
public static <T> List<T> arrayToList(T[] array) { return Arrays.stream(array).collect(Collectors.toList());//NOSONAR: This stream doesn't need to be closed }
From source file:Main.java
@SafeVarargs public static <T> Set<T> setOfNotNull(T... objects) { return Arrays.stream(objects).filter(obj -> obj != null).collect(Collectors.toSet()); }
From source file:Main.java
public static <T> Stream<T> cartesian(BinaryOperator<T> aggregator, Supplier<Stream<T>>... streams) { return Arrays.stream(streams) .reduce((s1, s2) -> () -> s1.get().flatMap(t1 -> s2.get().map(t2 -> aggregator.apply(t1, t2)))) .orElse(Stream::empty).get(); }
From source file:Main.java
public static <T> List<String> toStringsList(T[] array) { return Arrays.stream(array).map(x -> x.toString()).collect(Collectors.toList()); }
From source file:Main.java
/** * Creates a {@link ButtonGroup} and adds all the given buttons to it. * @param buttons the buttons to group// w w w .j a v a 2s .c om * @return the created ButtonGroup */ public static ButtonGroup group(AbstractButton... buttons) { final ButtonGroup group = new ButtonGroup(); Arrays.stream(buttons).forEach(group::add); return group; }
From source file:Main.java
public static int getStringHeight(Graphics g, Font font, String text) { if (font == null || g == null || text == null) { return -1; }//w ww . ja v a 2 s . c o m FontMetrics fm = g.getFontMetrics(font); if (!text.contains(("\\n"))) { return (int) fm.getStringBounds(text, g).getHeight(); } return Arrays.stream(text.split("\\\\n")).mapToInt(row -> (int) fm.getStringBounds(text, g).getHeight()) .reduce(Integer::sum).getAsInt(); }
From source file:Main.java
/** * Places the given components in a JPanel with a FlowLayout. * @param components the components to add * @return a JPanel with a FlowLayout with the given components *//* ww w. ja v a2 s .co m*/ public static JPanel flowLayout(Component... components) { final JPanel result = new JPanel(); // FlowLayout is default Arrays.stream(components).forEach(result::add); return result; }