List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:it.unibo.alchemist.test.TestInSimulator.java
@SafeVarargs private static <T> void runSimulation(final String relativeFilePath, final double finalTime, final Consumer<Environment<Object>>... checkProcedures) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, SAXException, IOException, ParserConfigurationException, InterruptedException, ExecutionException { final Resource res = XTEXT.getResource(URI.createURI("classpath:/simulations/" + relativeFilePath), true); final IGenerator generator = INJECTOR.getInstance(IGenerator.class); final InMemoryFileSystemAccess fsa = INJECTOR.getInstance(InMemoryFileSystemAccess.class); generator.doGenerate(res, fsa);/*from ww w .ja v a2s.c o m*/ final Collection<CharSequence> files = fsa.getTextFiles().values(); if (files.size() != 1) { fail(); } final ByteArrayInputStream strIS = new ByteArrayInputStream( files.stream().findFirst().get().toString().getBytes(Charsets.UTF_8)); final Environment<Object> env = EnvironmentBuilder.build(strIS).get().getEnvironment(); final Simulation<Object> sim = new Engine<>(env, new DoubleTime(finalTime)); sim.addCommand(new StateCommand<>().run().build()); /* * Use this thread: intercepts failures. */ sim.run(); Arrays.stream(checkProcedures).forEachOrdered(p -> p.accept(env)); }
From source file:de.hska.ld.sandbox.DataGenerator.java
private void createSandboxUsers(UserService userService, RoleService roleService, String sandboxUsersConcatString) { User admin = userService.findByUsername(Core.BOOTSTRAP_ADMIN); userService.runAs(admin, () -> {//w w w. ja v a2 s . c o m Role dbUserRole = roleService.findByName("ROLE_USER"); if (dbUserRole == null) { // create initial roles String newUserRoleName = "ROLE_USER"; createNewUserRole(roleService, newUserRoleName); String newAdminRoleName = "ROLE_ADMIN"; createNewUserRole(roleService, newAdminRoleName); } final Role adminRole = roleService.findByName("ROLE_ADMIN"); final Role userRole = roleService.findByName("ROLE_USER"); if (sandboxUsersConcatString != null && !"".equals(sandboxUsersConcatString)) { String[] sandboxUsersString = sandboxUsersConcatString.split(";"); Arrays.stream(sandboxUsersString).forEach(userString -> { String[] userData = userString.split(":"); if (userData.length == 4) { User user = userService.findByUsername(userData[0]); if (user == null) { String firstname = userData[0]; String lastname = userData[1]; String password = userData[2]; String role = userData[3]; try { user = userService.save(newUser(firstname, lastname, password, role)); if ("Admin".equals(role)) { List<Role> roleList = new ArrayList<Role>(); roleList.add(adminRole); roleList.add(userRole); user.setRoleList(roleList); userService.save(user); } else { List<Role> roleList = new ArrayList<Role>(); roleList.add(userRole); user.setRoleList(roleList); userService.save(user); } } catch (Exception e) { e.printStackTrace(); } } } }); } }); }
From source file:natalia.dymnikova.cluster.scheduler.impl.requirements.ComputeMemberRequirementsBuilder.java
private List<MemberRequirements> doBuild(final Remote remote) { // TODO deal with 3pp dependencies??? return Arrays.stream(remote.getClass().getDeclaredFields()) .filter(field -> field.isAnnotationPresent(Autowired.class)) .filter(field -> field.getType().getPackage().getName().startsWith(basePackage)) .map(TypeFilterWithField::new).map(this::scan) .map(e -> assemblyRequirement(remote, e.getKey(), e.getValue())).collect(toList()); }
From source file:io.wcm.devops.conga.tooling.maven.plugin.ValidateVersionInfoMojo.java
private List<Properties> getDependencyVersionInfos() throws MojoExecutionException { ClassLoader classLoader = ClassLoaderUtil.buildDependencyClassLoader(project); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader); try {//from w ww . j av a2 s . c om Resource[] resources = resolver.getResources( "classpath*:" + BuildConstants.CLASSPATH_PREFIX + BuildConstants.FILE_VERSION_INFO); return Arrays.stream(resources).map(resource -> toProperties(resource)).collect(Collectors.toList()); } catch (IOException ex) { throw new MojoExecutionException("Unable to get classpath resources: " + ex.getMessage(), ex); } }
From source file:com.appdynamics.cloudfoundry.appdservicebroker.catalog.Service.java
Service tags(String... tags) { synchronized (this.monitor) { if (this.tags == null) { this.tags = new ArrayList<>(); }//from www.ja v a 2 s. c om Arrays.stream(tags).forEach(this.tags::add); return this; } }
From source file:se.uu.it.cs.recsys.constraint.solver.Solver.java
private Set<List<se.uu.it.cs.recsys.api.type.Course>> search(Store store, SetVar[] vars) { LOGGER.debug("Start searching solution ... "); Domain[][] solutions = doSearch(store, vars); if (solutions == null || solutions.length == 0) { LOGGER.debug("No solution found!"); return Collections.emptySet(); }// ww w. j a v a2s. c o m Set<List<se.uu.it.cs.recsys.api.type.Course>> result = new HashSet<>(); Arrays.stream(solutions).filter(solution -> { return solution != null && solution.length > 0; }).forEach(solution -> { result.add(this.resultConverter.convert(solution)); }); return result; }
From source file:alluxio.cli.fs.command.SetFaclCommand.java
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException { SetAclOptions options = SetAclOptions.defaults().setRecursive(false); if (cl.hasOption(RECURSIVE_OPTION.getOpt())) { options.setRecursive(true);//from ww w . j a v a2 s. com } List<AclEntry> entries = Collections.emptyList(); SetAclAction action = SetAclAction.REPLACE; List<String> specifiedActions = new ArrayList<>(1); if (cl.hasOption(SET_OPTION.getLongOpt())) { specifiedActions.add(SET_OPTION.getLongOpt()); action = SetAclAction.REPLACE; String aclList = cl.getOptionValue(SET_OPTION.getLongOpt()); if (cl.hasOption(DEFAULT_OPTION.getOpt())) { entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault).map(AclEntry::fromCliString) .collect(Collectors.toList()); } else { entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliString) .collect(Collectors.toList()); } } if (cl.hasOption(MODIFY_OPTION.getOpt())) { specifiedActions.add(MODIFY_OPTION.getOpt()); action = SetAclAction.MODIFY; String aclList = cl.getOptionValue(MODIFY_OPTION.getOpt()); if (cl.hasOption(DEFAULT_OPTION.getOpt())) { entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault).map(AclEntry::fromCliString) .collect(Collectors.toList()); } else { entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliString) .collect(Collectors.toList()); } } if (cl.hasOption(REMOVE_OPTION.getOpt())) { specifiedActions.add(REMOVE_OPTION.getOpt()); action = SetAclAction.REMOVE; String aclList = cl.getOptionValue(REMOVE_OPTION.getOpt()); if (cl.hasOption(DEFAULT_OPTION.getOpt())) { entries = Arrays.stream(aclList.split(",")).map(AclEntry::toDefault) .map(AclEntry::fromCliStringWithoutPermissions).collect(Collectors.toList()); } else { entries = Arrays.stream(aclList.split(",")).map(AclEntry::fromCliStringWithoutPermissions) .collect(Collectors.toList()); } } if (cl.hasOption(REMOVE_ALL_OPTION.getOpt())) { specifiedActions.add(REMOVE_ALL_OPTION.getOpt()); action = SetAclAction.REMOVE_ALL; } if (cl.hasOption(REMOVE_DEFAULT_OPTION.getOpt())) { specifiedActions.add(REMOVE_DEFAULT_OPTION.getOpt()); action = SetAclAction.REMOVE_DEFAULT; } if (specifiedActions.isEmpty()) { throw new IllegalArgumentException("No actions specified."); } else if (specifiedActions.size() > 1) { throw new IllegalArgumentException( "Only 1 action can be specified: " + String.join(", ", specifiedActions)); } mFileSystem.setAcl(path, action, entries, options); }
From source file:com.thinkbiganalytics.metadata.sla.EmailServiceLevelAgreementAction.java
void sendToAddresses(String desc, String slaName, String emails) { String[] addresses = emails.split(","); Arrays.stream(addresses).forEach(address -> sendToAddress(desc, slaName, address.trim())); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratEventAnnotation.java
public static BratEventAnnotation parse(String aLine) { Matcher m = PATTERN.matcher(aLine); if (!m.matches()) { throw new IllegalArgumentException("Illegal event annotation format [" + aLine + "]"); }//from w ww. jav a 2 s . com List<BratEventArgument> arguments = null; if (StringUtils.isNotBlank(m.group(ARGS))) { arguments = Arrays.stream(m.group(ARGS).trim().split(" ")).map(arg -> BratEventArgument.parse(arg)) .collect(Collectors.toList()); } return new BratEventAnnotation(m.group(ID), m.group(TYPE), m.group(TRIGGER), arguments); }
From source file:io.spring.initializr.metadata.InitializrConfiguration.java
private static String splitCamelCase(String text) { return String.join("", Arrays.stream(text.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])")) .map((it) -> StringUtils.capitalize(it.toLowerCase())).toArray(String[]::new)); }