Java Code Examples for java.util.stream.Stream#empty()

The following examples show how to use java.util.stream.Stream#empty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilterTester.java    From pitest with Apache License 2.0 6 votes vote down vote up
private List<Sample> samples(final String sample) {
  final Function<String, Stream<Sample>> toPair = compiler -> {
    final String clazz = makeClassName(sample, compiler);
    final Optional<byte[]> bs = FilterTester.this.source.getBytes(clazz);
    if (bs.isPresent()) {
      final Sample p = new Sample();
      p.className = ClassName.fromString(clazz);
      p.clazz = ClassTree.fromBytes(bs.get());
      p.compiler = compiler;
      return Stream.of(p);
    }
    return Stream.empty();

  };
  return COMPILERS.stream().flatMap(toPair).collect(Collectors.toList());
}
 
Example 2
Source File: QueryExecutorImpl.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Stream<ConceptMap> match(MatchClause matchClause) {
    Stream<ConceptMap> answerStream;

    try {
        validateClause(matchClause);

        Set<Variable> bindingVars = matchClause.getPatterns().variables();

        Disjunction<Conjunction<Pattern>> disjunction = matchClause.getPatterns().getNegationDNF();
        ResolvableQuery resolvableQuery = reasonerQueryFactory.resolvable(disjunction, bindingVars);

        return resolvableQuery.resolve(infer);
    } catch (ReasonerCheckedException e) {
        LOG.debug(e.getMessage());
        answerStream = Stream.empty();
    }

    return answerStream;
}
 
Example 3
Source File: StateMachineRunner.java    From protonpack with MIT License 5 votes vote down vote up
private Stream<O> _finish() {
  if (isFinished) {
    return Stream.empty();
  }

  isFinished = true;
  return stateMachine.finish(state);
}
 
Example 4
Source File: BdbTruePatchStore.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
public Stream<CursorQuad> getChanges(String subject, String predicate, Direction direction, int version,
                                     boolean assertions) {
  if (bdbWrappers.containsKey(version)) {
    final BdbWrapper<String, String> bdbWrapper = bdbWrappers.get(version);
    return bdbWrapper.databaseGetter()
                     .key(subject + "\n" + version + "\n" + (assertions ? "1" : "0"))
                     .skipNearValue(predicate + "\n" + (direction == OUT ? "1" : "0") + "\n")
                     .onlyValuesMatching((prefix, value) -> value.startsWith(prefix))
                     .forwards()
                     .getValues(bdbWrapper.valueRetriever())
                     .map(v -> makeCursorQuad(subject, assertions, v));
  }

  return Stream.empty();
}
 
Example 5
Source File: DirectoryBasedDeploymentUnitUtil.java    From flux with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to list sub-directories.
 * @param path
 * @return {@code Stream<Path>} representing sub-directories
 */
private Stream<Path> getSubDirectories(Path path) {
    try {
        return Files.list(path).filter(e -> Files.isDirectory(e));
    }
    catch (IOException ioe) {
        return Stream.empty();
    }
}
 
Example 6
Source File: NullSafeCollectionStreamsUsingJava8OptionalContainerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCollectionIsNull_thenExpectAnEmptyStream() {
    Collection<String> collection = null;
    Stream<String> expResult = Stream.empty();
    Stream<String> result = instance.collectionAsStream(collection);
    assertStreamEquals(expResult, result);

}
 
Example 7
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the direct dependences of the given source
 */
Stream<Archive> requires(Archive source) {
    if (!results.containsKey(source)) {
        return Stream.empty();
    }
    return results.get(source).requires()
                  .stream();
}
 
Example 8
Source File: StringMultimapBuilder.java    From armeria with Apache License 2.0 4 votes vote down vote up
public final Stream<String> valueStream(IN_NAME name) {
    final CONTAINER getters = getters();
    return getters != null ? getters.valueStream(name) : Stream.empty();
}
 
Example 9
Source File: NumberPattern.java    From WarpPI with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<SubFunctionPattern> getSubFunctions() {
	return Stream.empty();
}
 
Example 10
Source File: RFC2217PortProvider.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Stream<SerialPortIdentifier> getSerialPortIdentifiers() {
    // TODO implement discovery here. https://github.com/eclipse/smarthome/pull/5560
    return Stream.empty();
}
 
Example 11
Source File: DateDomain.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Returns a random sequence of time values from this domain.
 */
protected Stream<Date> timeValues( ResolverContext context)
  {
  Calendar minDate =
    new Calendar.Builder()
    .setInstant( getMinDate())
    .build();

  long minTime =
    new Calendar.Builder()
    .setDate( minDate.get( YEAR), minDate.get( MONTH), minDate.get( DAY_OF_MONTH))
    .setTimeOfDay( 0, 0, 0, 0)
    .build()
    .getTimeInMillis();

  Calendar maxDate =
    new Calendar.Builder()
    .setInstant( getMaxDate())
    .build();

  long maxTime =
    new Calendar.Builder()
    .setDate( maxDate.get( YEAR), maxDate.get( MONTH), maxDate.get( DAY_OF_MONTH))
    .setTimeOfDay( 0, 0, 0, 0)
    .build()
    .getTimeInMillis();

  long millisPerDay = 86400000;
  long daysCount = (maxTime - minTime) / millisPerDay + 1;

  return
    daysCount < 1?
    Stream.empty() :

    daysCount == 1?
    Stream.of( getMinDate()) :

    context.getRandom().longs( 0, daysCount)
    .map( d -> minTime + d * millisPerDay)
    .mapToObj( Date::new);
  }
 
Example 12
Source File: Unit2MyIntermediate.java    From hol-streams with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<String> strings(Stream<Object> stream) {
    return Stream.empty();
}
 
Example 13
Source File: InputModeller.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Returns an empty stream for a schema of unknown type.
 */
private Stream<IVarDef> unknownSchemaVars( String type)
  {
  notifyError( String.format( "Unknown schema type=%s is not supported", type), "Ignoring unknown schema");
  return Stream.empty();
  }
 
Example 14
Source File: MessageStores.java    From synapse with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<MessageStoreEntry> stream() {
    return Stream.empty();
}
 
Example 15
Source File: ProductsProposalViewFactoryTemplate.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public final Stream<IView> streamAllViews()
{
	return Stream.empty();
}
 
Example 16
Source File: FluxProcessor.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<? extends Scannable> inners() {
	return Stream.empty();
}
 
Example 17
Source File: FluxWindowPredicate.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public Stream<? extends Scannable> inners() {
	return  window == null ? Stream.empty() : Stream.of(window);
}
 
Example 18
Source File: StreamOps.java    From mill with MIT License 3 votes vote down vote up
/**
 * Given any number of streams, returns distinct values such that the set of
 * elements in the returned stream are those distinct elements of the first
 * stream that are not contained in any of the subsequent passed streams.
 *
 * @param streams An array of streams
 * @param <T> All elements in all streams are instances of this single type
 * @return distinct values of the first stream such that the set of elements
 * in the returned stream are not contained in any of the subsequent passed streams
 */
public static <T> Stream<T> difference(Stream<T>... streams) {
    if(streams.length < 1) {
        return Stream.empty();
    } else if(streams.length < 2) {
        return streams[0];
    } else {
        return difference(streams[0], concat(Arrays.copyOfRange(streams, 1, streams.length - 1)));
    }
}
 
Example 19
Source File: CollectionUtils.java    From freecol with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Transform the contents of a stream.
 *
 * @param <T> The collection member type.
 * @param <R> The resulting collection member type.
 * @param <C> The resulting collection type.
 * @param stream The {@code Stream} to transform.
 * @param predicate A {@code Predicate} to select the items.
 * @param mapper A function to transform the selected items.
 * @param collector A {@code Collector} to aggregate the results.
 * @return The result of collecting the mapped predicate matches.
 */
public static <T,R,C> C transform(Stream<T> stream,
    Predicate<? super T> predicate,
    Function<? super T, ? extends R> mapper,
    Collector<R,?,C> collector) {
    final Stream<T> s = (stream == null) ? Stream.<T>empty() : stream;
    return transform_internal(s, predicate, mapper, null, collector);
}
 
Example 20
Source File: FreeColObject.java    From freecol with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the set of abilities with the given identifier from this
 * object.  Subclasses with complex ability handling should
 * override this as all prior routines are derived from it.
 *
 * @param id The object identifier.
 * @param fcgot An optional {@code FreeColSpecObjectType} the
 *     ability applies to.
 * @param turn An optional applicable {@code Turn}.
 * @return A set of abilities.
 */
public Stream<Ability> getAbilities(String id,
                                    FreeColSpecObjectType fcgot,
                                    Turn turn) {
    FeatureContainer fc = getFeatureContainer();
    return (fc == null) ? Stream.<Ability>empty()
        : fc.getAbilities(id, fcgot, turn);
}