List of usage examples for java.util Collection parallelStream
default Stream<E> parallelStream()
From source file:com.github.helenusdriver.driver.impl.PersistedMap.java
/** * {@inheritDoc}/* w ww .j a v a2s. co m*/ * * @author paouelle * * @see java.util.Map#values() */ @Override public Collection<T> values() { if (vcol == null) { final Collection<PersistedValue<T, PT>> vcol = map.values(); this.vcol = new AbstractCollection<T>() { @Override public int size() { return vcol.size(); } @Override public boolean isEmpty() { return vcol.isEmpty(); } @Override public Iterator<T> iterator() { return new TransformIterator<PersistedValue<T, PT>, T>(vcol.iterator()) { @Override protected T transform(PersistedValue<T, PT> pv) { return pv.getDecodedValue(); } }; } @Override public Stream<T> stream() { return vcol.stream().map(pv -> pv.getDecodedValue()); } @Override public Stream<T> parallelStream() { return vcol.parallelStream().map(pv -> pv.getDecodedValue()); } @Override public void clear() { vcol.clear(); } @Override public String toString() { return vcol.toString(); } }; } return vcol; }
From source file:com.fitbur.testify.system.SystemTestVerifier.java
@Override public void configuration() { doPrivileged((PrivilegedAction<Object>) () -> { String testClassName = testContext.getTestClassName(); CutDescriptor cutDescriptor = testContext.getCutDescriptor(); Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values(); if (testContext.getCutCount() == 1) { checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount()); }//from w w w . j ava 2 s.co m // insure that only one field has Cut annotation on it. if (testContext.getCutCount() > 1) { checkState(false, "Found more than one class under test in %s. Please insure " + "that only one field is annotated with @Cut.", testClassName); } //insure that there is a field annotated with @Cut defined or one or more //fields annotated with @Real or @Inject if (testContext.getCutCount() == 0 && fieldDescriptors.isEmpty()) { checkState(false, "Test class '%s' does not define a field annotated with @Cut " + "nor does it define field(s) annotated with @Real or @Inject. " + "Please insure the test class defines a single field annotated " + "with @Cut or defines at least one field annotated with @Real " + "or @Inject.", testClassName); } //insure need providers have default constructors. testContext.getAnnotations(Need.class).parallelStream().map(Need::value).forEach(p -> { try { p.getDeclaredConstructor(); } catch (NoSuchMethodException e) { checkState(false, "Need provider '%s' defined in test class '%s' does not have a " + "zero argument default constructor. Please insure that the need " + "provider defines an accessible zero argument default constructor.", testClassName, p.getSimpleName()); } }); fieldDescriptors.parallelStream().forEach(p -> { Field field = p.getField(); Class<?> fieldType = p.getType(); String fieldName = p.getName(); String fieldTypeName = p.getTypeName(); checkState(!fieldType.isArray(), "Field '%s' in test class '%s' can not be configured because '%s'" + " is an array. Please consider using a List instead of arrays.", fieldName, testClassName, fieldTypeName); Fake fake = field.getDeclaredAnnotation(Fake.class); if (fake != null) { checkState(!isFinal(fieldType.getModifiers()), "Can not fake field '%s' in test class '%s' because '%s'" + " is a final class.", fieldName, testClassName, fieldTypeName); } Real real = field.getDeclaredAnnotation(Real.class); if (real != null && real.value()) { checkState(!isFinal(fieldType.getModifiers()), "Can not create delegated fake of field '%s' in test class '%s' " + "because '%s' is a final class.", fieldName, testClassName, fieldTypeName); } }); return null; }); }
From source file:com.fitbur.testify.integration.IntegrationTestVerifier.java
@Override public void configuration() { doPrivileged((PrivilegedAction<Object>) () -> { String testClassName = testContext.getTestClassName(); CutDescriptor cutDescriptor = testContext.getCutDescriptor(); Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values(); if (testContext.getCutCount() == 1) { checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount()); }/* w ww. j a v a2s.c om*/ // insure that only one field has Cut annotation on it. if (testContext.getCutCount() > 1) { checkState(false, "Found more than one class under test in test class %s. Please insure " + "that only one field is annotated with @Cut.", testClassName); } //insure that there is a field annotated with @Cut defined or one or more //fields annotated with @Real or @Inject if (testContext.getCutCount() == 0 && fieldDescriptors.isEmpty()) { checkState(false, "Test class '%s' does not define a field annotated with @Cut " + "nor does it define field(s) annotated with @Real or @Inject. " + "Please insure the test class defines a single field annotated " + "with @Cut or defines at least one field annotated with @Real " + "or @Inject.", testClassName); } //insure need providers have default constructors. testContext.getAnnotations(Need.class).parallelStream().map(Need::value).forEach(p -> { try { p.getDeclaredConstructor(); } catch (NoSuchMethodException e) { checkState(false, "Need provider '%s' defined in test class '%s' does not have a " + "zero argument default constructor. Please insure that the need " + "provider defines an accessible zero argument default constructor.", testClassName, p.getSimpleName()); } }); fieldDescriptors.parallelStream().forEach(p -> { Field field = p.getField(); Class<?> fieldType = p.getType(); String fieldName = p.getName(); String fieldTypeName = p.getTypeName(); checkState(!fieldType.isArray(), "Field '%s' in test class '%s' can not be configured because '%s'" + " is an array. Please consider using a List instead of arrays.", fieldName, testClassName, fieldTypeName); Fake fake = field.getDeclaredAnnotation(Fake.class); if (fake != null) { checkState(!isFinal(fieldType.getModifiers()), "Can not fake field '%s' in test class '%s' because '%s'" + " is a final class.", fieldName, testClassName, fieldTypeName); } Real real = field.getDeclaredAnnotation(Real.class); if (real != null && real.value()) { checkState(!isFinal(fieldType.getModifiers()), "Can not create delegated fake of field '%s' in test class '%s' " + "because '%s' is a final class.", fieldName, testClassName, fieldTypeName); } }); return null; }); }
From source file:org.apdplat.superword.rule.DynamicSuffixRule.java
public static List<Word> findBySuffix(Collection<Word> words, List<Suffix> suffixes) { if (suffixes == null || suffixes.size() < 2) { return Arrays.asList(); }/*w w w . ja v a 2s. c om*/ return words.parallelStream().filter(word -> { String w = word.getWord(); String p = suffixes.get(0).getSuffix().toLowerCase(); p = p.replaceAll("-", "").replaceAll("\\s+", ""); if (!w.toLowerCase().endsWith(p)) { return false; } String common = w.substring(0, w.length() - p.length()); //?for for (int i = 1; i < suffixes.size(); i++) { String s = suffixes.get(i).getSuffix().toLowerCase(); s = s.replaceAll("-", "").replaceAll("\\s+", ""); if (!words.contains(new Word(common + s, ""))) { return false; } } return true; }).sorted().collect(Collectors.toList()); }
From source file:org.apdplat.superword.rule.PrefixRule.java
public static List<Word> findByPrefix(Collection<Word> words, Prefix prefix, boolean strict) { return words.parallelStream().filter(word -> { String w = word.getWord(); if (Character.isUpperCase(w.charAt(0))) { return false; }/*ww w. j a v a 2 s .c o m*/ String p = prefix.getPrefix().replace("-", "").toLowerCase(); if (strict) { if (w.startsWith(p) && w.length() - p.length() > 2 && words.contains(new Word(w.substring(p.length()), ""))) { return true; } } else if (w.startsWith(p)) { return true; } return false; }).sorted().collect(Collectors.toList()); }
From source file:org.apdplat.superword.rule.RootRule.java
public static List<Word> findByRoot(Collection<Word> words, Word root) { return words.parallelStream().filter(word -> { //??//from w ww . j av a2 s . c o m String w = word.getWord(); if (Character.isUpperCase(w.charAt(0))) { return false; } //??? String[] rs = root.getWord().toLowerCase().split(","); //??????? for (String s : rs) { if (w.contains(s)) { return true; } } return false; }).sorted().collect(Collectors.toList()); }
From source file:org.apdplat.superword.rule.SuffixRule.java
public static List<Word> findBySuffix(Collection<Word> words, Suffix suffix, boolean strict) { return words.parallelStream().filter(word -> { String w = word.getWord(); if (Character.isUpperCase(w.charAt(0))) { return false; }/*from w ww. j a v a 2 s.c o m*/ String s = suffix.getSuffix().replace("-", "").toLowerCase(); if (strict) { if (w.endsWith(s) && w.length() - s.length() > 2 && words.contains(new Word(w.substring(0, w.length() - s.length()), ""))) { return true; } } else if (w.endsWith(s)) { return true; } return false; }).sorted().collect(Collectors.toList()); }
From source file:org.kitodo.filemanagement.locking.LockManagement.java
/** * Checks for a group of locks if they can be returned. * * @param uris//from w w w. j a v a 2 s .c om * the URIs on the locks to be returned * @throws IllegalStateException * if there is still a stream flowing over the lock */ private void canClose(Collection<URI> uris) { String exceptionMessagePrefix = "The lock cannot be released because there are still streams flowing for the following URIs: "; String exceptionMessage = uris.parallelStream().filter(streamManagement::isKnowingAnOpenStreamTo) .map(uri -> uri.toString()).collect(Collectors.joining(", ", exceptionMessagePrefix, "")); if (exceptionMessage.length() > exceptionMessagePrefix.length()) { throw new IllegalStateException(exceptionMessage); } }
From source file:org.kitodo.production.forms.dataeditor.FieldedMetadataTableRow.java
/** * Returns the collection of simple meta-data entries. Throws an * IllegalStateException if a cannot be casted. * * @param values/*from ww w . j a v a 2 s. co m*/ * values obtained * @return a collection of simple meta-data entries */ @SuppressWarnings({ "unchecked", "rawtypes" }) private Collection<MetadataEntry> simpleValues(Collection<Metadata> values) { Optional<Metadata> fault = values.parallelStream().filter(entry -> !(entry instanceof MetadataEntry)) .findAny(); if (fault.isPresent()) { throw new IllegalStateException("Got complex meta-data entry with key \"" + fault.get().getKey() + "\" which isn't declared as substructured key in the rule set."); } return (Collection) values; }
From source file:org.lightjason.agentspeak.action.buildin.agent.CPlanStatistic.java
/** * creates the plan statistic// w ww.j a v a 2 s. c om * * @param p_trigger plan trigger * @param p_agent agent * @param p_return return arguments * @return successfull flag */ private static boolean statistic(final ITrigger p_trigger, final IAgent<?> p_agent, final List<ITerm> p_return) { final Collection<Triple<IPlan, AtomicLong, AtomicLong>> l_plans = p_agent.plans().get(p_trigger); if (l_plans.isEmpty()) return false; final long l_success = l_plans.parallelStream().mapToLong(i -> i.getMiddle().get()).sum(); final long l_fail = l_plans.parallelStream().mapToLong(i -> i.getRight().get()).sum(); p_return.add(CRawTerm.from(l_success)); p_return.add(CRawTerm.from(l_fail)); p_return.add(CRawTerm.from(l_success + l_fail)); return true; }