Example usage for java.util.stream Stream findAny

List of usage examples for java.util.stream Stream findAny

Introduction

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

Prototype

Optional<T> findAny();

Source Link

Document

Returns an Optional describing some element of the stream, or an empty Optional if the stream is empty.

Usage

From source file:module.siadap.domain.wrappers.UnitSiadapWrapper.java

public static boolean isValidSIADAPUnit(Unit unit, int year) {
    final AccountabilityType unitRelations = SiadapYearConfiguration.getSiadapYearConfiguration(year)
            .getUnitRelations();//from ww w  . j av  a2  s. c  o  m
    final java.util.function.Predicate<Accountability> predicate = AccountabilityPredicate
            .byType(unitRelations);
    // let's get the unit and check to see if it has a unit relationship
    // with some other unit or not
    final Stream<Accountability> children = unit.getChildAccountabilityStream().filter(predicate);
    final Stream<Accountability> parents = unit.getParentAccountabilityStream().filter(predicate);
    return (children.findAny().orElse(null) != null || parents.findAny().orElse(null) != null)
            && new UnitSiadapWrapper(unit, year).isConnectedToTopUnit(unitRelations);
}