Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

In this page you can find the example usage for java.util Collection stream.

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.megahardcore.features.Explosions.java

/**
 * Make blocks fly//w ww .java  2s  .c om
 *
 * @param blocks        list of blocks
 * @param center        center from which to spread blocks out
 * @param flyPercentage percentage of blocks affected
 * @param upVel         how fast to propel upwards
 * @param spreadVel     how fast to propel on horizontal axis
 */
public void applyExplosionPhysics(Collection<Block> blocks, final Location center, final int flyPercentage,
        final double upVel, final double spreadVel) {
    final List<FallingBlock> fallingBlockList = new ArrayList<>();
    //Only a few of the blocks fly as an effect
    //decide on the distance if block should be placed
    //fall.setMetadata("drops", new FixedMetadataValue(plugin, block.getDrops()));
    //block.setType(Material.AIR);
    blocks.stream().filter(block -> block.getType().isSolid()).filter(block -> plugin.random(flyPercentage))
            .forEach(block -> {
                FallingBlock fall = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(),
                        block.getType(), block.getData());
                fall.setMetadata(tag, new FixedMetadataValue(plugin, block.getLocation())); //decide on the distance if block should be placed
                //fall.setMetadata("drops", new FixedMetadataValue(plugin, block.getDrops()));
                fall.setDropItem(
                        CFG.getBoolean(RootNode.MORE_FALLING_BLOCKS_DROP_ITEM, block.getWorld().getName()));
                UtilityModule.moveUp(fall, upVel);
                //block.setType(Material.AIR);
                fallingBlockList.add(fall);
            });

    plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
        for (FallingBlock fall : fallingBlockList) {
            UtilityModule.moveAway(fall, center, spreadVel);
        }
    }, 2L);
}

From source file:com.evolveum.midpoint.prism.marshaller.PrismBeanInspector.java

private boolean matches(TypeDefinition type, Collection<QName> fields) {
    if (!(type instanceof ComplexTypeDefinition)) {
        return false;
    }// www. jav a  2s  . c  om
    ComplexTypeDefinition ctd = (ComplexTypeDefinition) type;
    return fields.stream().allMatch(field -> ctd.containsItemDefinition(field));
}

From source file:com.datumbox.framework.common.dataobjects.Dataframe.java

/** {@inheritDoc} */
@Override/*www.  java2 s  . co m*/
public boolean addAll(Collection<? extends Record> c) {
    c.stream().forEach(r -> {
        add(r);
    });
    return true;
}

From source file:com.haulmont.cuba.gui.app.security.role.browse.RoleBrowser.java

protected void importRoles() {
    File file = fileUploadingAPI.getFile(importRolesUpload.getFileId());
    if (file == null) {
        String errorMsg = String.format("Entities import upload error. File with id %s not found",
                importRolesUpload.getFileId());
        throw new RuntimeException(errorMsg);
    }//from  ww  w  .jav  a 2s .c  o m

    byte[] fileBytes;
    try (InputStream is = new FileInputStream(file)) {
        fileBytes = IOUtils.toByteArray(is);
    } catch (IOException e) {
        throw new RuntimeException("Unable to import file", e);
    }

    try {
        Collection<Entity> importedEntities;
        if ("json".equals(Files.getFileExtension(importRolesUpload.getFileName()))) {
            String jsonContent = new String(fileBytes, StandardCharsets.UTF_8);
            importedEntities = entityImportExportService.importEntitiesFromJSON(jsonContent,
                    createRolesImportView());
        } else {
            importedEntities = entityImportExportService.importEntitiesFromZIP(fileBytes,
                    createRolesImportView());
        }
        long importedRolesCount = importedEntities.stream().filter(entity -> entity instanceof Role).count();
        showNotification(importedRolesCount + " roles imported", NotificationType.HUMANIZED);
        rolesDs.refresh();
    } catch (Exception e) {
        showNotification(formatMessage("importError", e.getMessage()), NotificationType.ERROR);
    }

    try {
        fileUploadingAPI.deleteFile(importRolesUpload.getFileId());
    } catch (FileStorageException e) {
        log.error("Unable to delete temp file", e);
    }
}

From source file:net.staticsnow.nexus.repository.apt.internal.hosted.AptHostedFacet.java

private String buildReleaseFile(String distribution, Collection<String> architectures, String md5,
        String sha256) {/*from   w  ww  .j  av  a  2s .  co m*/
    Paragraph p = new Paragraph(Arrays.asList(new ControlFile.ControlField("Suite", distribution),
            new ControlFile.ControlField("Codename", distribution),
            new ControlFile.ControlField("Components", "main"),
            new ControlFile.ControlField("Date", DateUtils.formatDate(new Date())),
            new ControlFile.ControlField("Architectures",
                    architectures.stream().collect(Collectors.joining(" "))),
            new ControlFile.ControlField("SHA256", sha256), new ControlFile.ControlField("MD5Sum", md5)));
    return p.toString();
}

From source file:com.thoughtworks.go.plugin.infra.FelixGoPluginOSGiFramework.java

@Override
public <T extends GoPlugin> Map<String, List<String>> getExtensionsInfoFromThePlugin(String pluginId) {
    if (framework == null) {
        LOGGER.warn(/*from w w w  . j  a  va 2  s. c  om*/
                "[Plugin Framework] Plugins are not enabled, so cannot do an action on all implementations of {}",
                GoPlugin.class);
        return null;
    }

    final BundleContext bundleContext = framework.getBundleContext();
    final Collection<ServiceReference<T>> serviceReferences = new HashSet<>(
            findServiceReferenceByPluginId((Class<T>) GoPlugin.class, pluginId, bundleContext));

    ActionWithReturn<T, DefaultKeyValue<String, List<String>>> action = (goPlugin,
            descriptor) -> new DefaultKeyValue<>(goPlugin.pluginIdentifier().getExtension(),
                    goPlugin.pluginIdentifier().getSupportedExtensionVersions());

    return convertToMap(pluginId, serviceReferences.stream().map(serviceReference -> {
        T service = bundleContext.getService(serviceReference);
        return executeActionOnTheService(action, service, getDescriptorFor(serviceReference));
    }).collect(toList()));
}

From source file:de.hska.ld.core.service.impl.UserServiceImpl.java

private void createRoleListForUser(User user) {
    Collection<Role> roleList;
    boolean adminAvailable = findByUsername(Core.BOOTSTRAP_ADMIN) != null;
    // Trust role list if the current user is a admin
    if (Core.isAdmin() || !adminAvailable) {
        roleList = user.getRoleList();/*ww  w. ja v a 2  s  .  c o m*/
    } else {
        roleList = new ArrayList<>();
    }
    // Add user role if not exists
    if (!roleList.stream().anyMatch(r -> Core.ROLE_USER.equals(r.getName()))) {
        Role userRole = roleService.findByName(Core.ROLE_USER);
        roleList.add(userRole);
    }
    user.setRoleList(roleList);
}

From source file:com.evolveum.midpoint.test.AbstractHigherUnitTest.java

protected <O extends ObjectType> void assertObjectOids(String message, Collection<PrismObject<O>> objects,
        String... oids) {/*from w ww  . j a  v a  2s  .c o m*/
    List<String> objectOids = objects.stream().map(o -> o.getOid()).collect(Collectors.toList());
    PrismAsserts.assertEqualsCollectionUnordered(message, objectOids, oids);
}

From source file:de.ingrid.ibus.comm.registry.Registry.java

/**
 * Returns all registered IPlugs./*from  w  w w.  j ava  2 s .co  m*/
 *
 * @return All registered IPlugs without checking the time stamp.
 */
public PlugDescription[] getAllIPlugsWithoutTimeLimitation() {
    Collection<PlugDescription> plugDescriptions;

    synchronized (this.fPlugDescriptionByPlugId) {
        plugDescriptions = this.fPlugDescriptionByPlugId.values();

        PlugDescription[] pdCopy = plugDescriptions.stream().map(pd -> {
            PlugDescription pdCopy1 = new PlugDescription();
            pdCopy1.putAll(pd);
            return pdCopy1;
        }).toArray(PlugDescription[]::new);

        for (PlugDescription pd : pdCopy) {
            if (ManagementService.MANAGEMENT_IPLUG_ID.equals(pd.getProxyServiceURL())
                    || SearchService.CENTRAL_INDEX_ID.equals(pd.getProxyServiceURL())) {
                pd.remove("overrideProxy");
            }
        }
        return pdCopy;
    }
}

From source file:com.qpark.eip.core.model.analysis.AnalysisDao.java

/**
 * Get the list of {@link FlowType}s matching the name pattern.
 *
 * @param modelVersion//from w  w w  .  j av a 2  s  .  co  m
 *            the model version.
 * @param namePattern
 *            the name pattern.
 * @return the list of {@link FlowType}s matching the name pattern.
 * @since 3.5.1
 */
@Transactional(value = EipModelAnalysisPersistenceConfig.TRANSACTION_MANAGER_NAME, propagation = Propagation.REQUIRED)
public List<FlowType> getFlowByNamePattern(final String modelVersion, final Collection<String> namePattern) {
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery<FlowType> q = cb.createQuery(FlowType.class);
    final Root<FlowType> f = q.from(FlowType.class);

    final Predicate or = cb.disjunction();
    namePattern.stream()
            .forEach(id -> or.getExpressions().add(cb.like(f.<String>get(FlowType_.name), "%" + id + "%")));
    final Predicate and = cb.conjunction();
    and.getExpressions().add(cb.equal(f.<String>get(FlowType_.modelVersion), modelVersion));
    and.getExpressions().add(or);
    q.where(and);
    final TypedQuery<FlowType> typedQuery = this.em.createQuery(q);
    final List<FlowType> value = typedQuery.getResultList();
    value.stream().forEach(ft -> EagerLoader.load(ft));
    return value;
}