List of usage examples for java.util Collection parallelStream
default Stream<E> parallelStream()
From source file:Main.java
public static <T> Stream<T> parallelStream(Collection<T> collection) { return collection.parallelStream(); }
From source file:Main.java
/** * Returns the given collection as stream. * * @param <T>//from www . ja v a 2 s . com * the generic type * @param source * the source * @param parallel * <code>true</code> if the stream should be a parallel stream * @return the stream */ public static <T> Stream<T> asStream(Collection<T> source, boolean parallel) { return parallel ? source.parallelStream() : source.stream(); }
From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java
public static List<Map<Integer, Double>> appendFeatures(Collection<List<Map<Integer, Double>>> list) { return list.parallelStream().reduce(new ArrayList<>(), (list1, list2) -> appendFeatures(list1, list2)); }
From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java
public static List<String> addValues(Collection<Pair<Double, List<String>>> input) { return range(0, input.stream().findAny().get().getRight().size()).boxed().map(i -> { return input.parallelStream().map(pair -> multiplyValues(asMap(pair.getRight().get(i)), pair.getLeft())) .reduce(new HashMap<>(), (map1, map2) -> sum(map1, map2)); }).map(LibSVMUtils::asString).collect(toList()); }
From source file:com.civprod.util.ChainListWrapper.java
public static <T> List<T> createList(Collection<T> inList) { java.util.function.Supplier<List<T>> SupplierFun = () -> { return org.apache.commons.collections4.list.SetUniqueList.setUniqueList(new ArrayList<T>()); };//from w ww.j a v a 2s . c om List<T> rList = inList.parallelStream().collect(SupplierFun, (List<T> coll, T curItem) -> { if (curItem instanceof ChainListWrapper) { coll.addAll(createList((ChainListWrapper) curItem)); } else { coll.add(curItem); } }, List<T>::addAll); return rList; }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * Found out the item that col1 contains but col2 not contains. * @param col1 Collection 1/* w ww . j a v a 2 s. com*/ * @param col2 Collection 2 * @return The items only in col1 but not col2 */ @SuppressWarnings("unchecked") public static <T> Collection<T> diff(Collection<T> col1, Collection<T> col2) { if (ValidationUtils.isEmpty(col1)) return col2; else if (ValidationUtils.isEmpty(col2)) return col1; try { Collection<T> diff = col1.getClass().newInstance(); col1.stream().forEach((item1) -> { if (col2.parallelStream().noneMatch((item2) -> ValidationUtils.eq(item1, item2))) { diff.add(item1); } }); return diff; } catch (InstantiationException | IllegalAccessException e) { LOG.warn("[diff] Could not create instance for {} with empty parameter constructor", col1.getClass()); } return null; }
From source file:com.adaptris.core.MessageLoggerImpl.java
protected Collection<MetadataElement> format(Collection<MetadataElement> set) { MetadataCollection metadata = new MetadataCollection(); set.parallelStream().forEach(e -> { metadata.add(wrap(e.getKey(), e.getValue())); });//from ww w . j a v a 2 s . c o m return metadata; }
From source file:edu.umd.umiacs.clip.tools.lang.TFIDFVector.java
public TFIDFVector(Collection<Triple<String, Integer, Integer>> terms, double logNumDocs) { double one_over_n_j = 1.0d / terms.parallelStream().mapToInt(Triple::getMiddle).sum(); termToTFIDF = terms.stream().collect(toMap(Triple::getLeft, triple -> (triple.getMiddle() * one_over_n_j) * (logNumDocs - log(triple.getRight())))); normalize();// ww w . j ava 2 s. c o m }
From source file:com.fitbur.jestify.junit.spring.IntegrationTestCreator.java
void create() { Map<DescriptorKey, ParameterDescriptor> parameterDescriptors = context.getParamaterDescriptors(); Map<DescriptorKey, FieldDescriptor> fieldDescriptors = context.getFieldDescriptors(); Object[] arguments = new Object[parameterDescriptors.size()]; Collection<FieldDescriptor> descriptors = fieldDescriptors.values(); Set<FieldDescriptor> mockDescriptors = descriptors.parallelStream().filter(p -> p.getMock().isPresent()) .collect(toSet());/*w w w .j ava 2 s. c om*/ //process fields with a custom index first mockDescriptors.parallelStream().filter(p -> p.getMock().get().index() != -1) .map(p -> new IndexMockInjector(context, testReifier, appContext, p, arguments)) .forEach(IndexMockInjector::inject); //process fields with custom names second mockDescriptors.parallelStream().filter(p -> !p.getMock().get().name().isEmpty()) .map(p -> new NameMockInjector(context, testReifier, appContext, p, arguments)) .forEach(NameMockInjector::inject); //process fields with type based injection mockDescriptors.parallelStream() .filter(p -> p.getMock().get().index() == -1 && p.getMock().get().name().isEmpty()) .map(p -> new TypeMockInjector(context, testReifier, appContext, p, arguments)) .forEach(TypeMockInjector::inject); //process fields with custom names second descriptors.parallelStream().filter(p -> !p.getMock().isPresent() && (p.getAnnotation(Inject.class).isPresent() || p.getAnnotation(Autowired.class).isPresent())) .map(p -> new RealInjector(context, testReifier, appContext, p, arguments)) .forEach(RealInjector::inject); testReifier.reifyCut(context.getCutDescriptor(), arguments); }
From source file:de.kaiserpfalzEdv.office.contacts.contact.ContactDO.java
@SuppressWarnings("deprecation") public void setAddresses(@NotNull final Collection<? extends Address> addresses) { HashSet<AddressDO> addressDOs = new HashSet<>(addresses.size()); addresses.parallelStream().forEach(a -> addressDOs.add((AddressDO) a)); setAddresses(addressDOs);//from w w w .j a v a 2 s . c om }