List of usage examples for java.util.stream Stream empty
public static <T> Stream<T> empty()
From source file:de.mas.wiiu.jnus.utils.FSTUtils.java
public static Stream<FSTEntry> getFSTEntriesByContentIndexAsStream(FSTEntry entry, short index) { return entry.getChildren().stream()// .flatMap(e -> {//from ww w .ja v a2 s . c om if (!e.isDir()) { if (e.getContentIndex() == index) { return Stream.of(e); } return Stream.empty(); } return getFSTEntriesByContentIndexAsStream(e, index); }); }
From source file:org.fcrepo.apix.binding.impl.RuntimeExtensionBinding.java
private static Stream<WebResource> getExtensionResource(final Extension e) { try {//www . java2 s .co m return Stream.of(e.getResource()); } catch (final ResourceNotFoundException x) { return Stream.empty(); } }
From source file:com.meltmedia.dropwizard.etcd.json.EtcdDirectoryDao.java
/** * Returns a stream of the values in this directory. * //from w w w .ja v a 2 s .c o m * @return a stream of the values in this directory. */ public Stream<T> stream() { try { EtcdKeysResponse response = clientSupplier.get().getDir(directory).send().get(); if (response.node == null || response.node.nodes == null) { return Stream.empty(); } return response.node.nodes.stream().map(n -> { try { return mapper.readValue(n.value, type); } catch (Exception e) { return null; } }); } catch (Exception e) { if (e instanceof EtcdException && ((EtcdException) e).errorCode == 100) return Stream.empty(); throw new EtcdDirectoryException(String.format("failed to list directory %s", directory), e); } }
From source file:com.wrmsr.wava.TestWhatever.java
public static Stream<BasicSet> collapseIfOr(BasicSet basics, Basic basic) { return matchBoolean(basic).flatMap(m1 -> { Basic or = basics.get(m1.ifFalse); if (!or.getBody().isEmpty() || !basics.getInputs(or).equals(ImmutableSet.of(basic.getName()))) { return Stream.empty(); }/*from w w w. j ava2 s .co m*/ Basic then = basics.get(m1.ifTrue); if (!basics.getInputs(then).equals(ImmutableSet.of(basic.getName(), or.getName()))) { return Stream.empty(); } Optional<Name> after = getUnconditionalTarget(then.getBreakTable()); if (!after.isPresent()) { return Stream.empty(); } return matchBoolean(or).flatMap(m2 -> { if (!m2.ifTrue.equals(then.getName()) || !m2.ifFalse.equals(after.get())) { return Stream.empty(); } Basic newBasic = new Basic(basic.getName(), ImmutableList.<Node>builder().addAll(basic.getBody()) .add(new If(new Binary(BinaryOp.CondOr, Type.I32, m1.condition, m2.condition), nodify(then.getBody()), new Nop())) .build(), new BreakTable(ImmutableList.of(), after.get(), new Nop()), minBasicIndex(basic, or, then)); return Stream.of(basics.replace(newBasic).remove(or).remove(then)); }); }); }
From source file:com.sillelien.dollar.api.types.AbstractDollarSingleValue.java
@NotNull public Stream<String> keyStream() { return Stream.empty(); }
From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java
protected Stream<CredentialFlowState> tryToFinishAcquisition(final HttpServletRequest request, final CredentialFlowState flowState) { try {/*from w ww . ja v a2 s . c o m*/ return Stream.of(credentials.finishAcquisition(flowState, Urls.apiBase(request))); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final RuntimeException e) { LOG.debug("Unable to perform OAuth callback on flow state: {}", flowState, e); return Stream.empty(); } }
From source file:org.codice.ddf.configuration.admin.ImportMigrationConfigurationAdminContext.java
public Stream<ImportMigrationConfigurationAdminEntry> memoryEntries() { if (!isValid) { return Stream.empty(); }//w ww .j ava 2 s .com return Stream.concat(exportedServices.values().stream(), exportedFactoryServices.values().stream().flatMap(List::stream)); }
From source file:org.silverpeas.core.calendar.ical4j.ICal4JImporter.java
@Override public void imports(final ImportDescriptor descriptor, final Consumer<Stream<Pair<CalendarEvent, List<CalendarEventOccurrence>>>> consumer) throws ImportException { try {//from w w w.j a v a 2s.co m PropertyFactoryRegistry propertyFactoryRegistry = new PropertyFactoryRegistry(); propertyFactoryRegistry.register(HtmlProperty.PROPERTY_NAME, HtmlProperty.FACTORY); CalendarBuilder builder = new CalendarBuilder(CalendarParserFactory.getInstance().createParser(), propertyFactoryRegistry, new ParameterFactoryRegistry(), TimeZoneRegistryFactory.getInstance().createRegistry()); Calendar calendar = builder.build(getCalendarInputStream(descriptor)); if (calendar.getComponents().isEmpty()) { consumer.accept(Stream.empty()); return; } calendar.validate(); Mutable<ZoneId> zoneId = Mutable.of(ZoneOffset.systemDefault()); Map<String, List<VEvent>> readEvents = new LinkedHashMap<>(); calendar.getComponents().forEach(component -> { if (component instanceof VEvent) { VEvent vEvent = (VEvent) component; String vEventId = vEvent.getUid().getValue(); List<VEvent> vEvents = readEvents.computeIfAbsent(vEventId, k -> new ArrayList<>()); if (vEvent.getRecurrenceId() != null) { vEvents.add(vEvent); } else { vEvents.add(0, vEvent); } } else if (component instanceof VTimeZone) { VTimeZone vTimeZone = (VTimeZone) component; zoneId.set(toZoneId(vTimeZone.getTimeZoneId().getValue())); } else { SilverLogger.getLogger(this).debug("iCalendar component ''{0}'' is not handled", component.getName()); } }); List<Pair<CalendarEvent, List<CalendarEventOccurrence>>> events = new ArrayList<>(readEvents.size()); readEvents.forEach((vEventId, vEvents) -> { // For now the following stuffs are not handled: // - the attendees // - triggers VEvent vEvent = vEvents.remove(0); CalendarEvent event = eventFromICalEvent(zoneId, vEventId, vEvent); // Occurrences List<CalendarEventOccurrence> occurrences = new ArrayList<>(vEvents.size()); vEvents.forEach(v -> { CalendarEventOccurrence occurrence = occurrenceFromICalEvent(zoneId, event, v); occurrences.add(occurrence); }); if (!event.isRecurrent() && !occurrences.isEmpty()) { SilverLogger.getLogger(this) .warn("event with uuid {0} has no recurrence set whereas {1,choice, 1#one linked " + "occurrence exists| 1<{1} linked occurrences exist}... Setting a default " + "recurrence (RRULE:FREQ=DAILY;COUNT=1) to get correct data for Silverpeas", event.getExternalId(), occurrences.size()); event.recur(Recurrence.every(1, TimeUnit.DAY).until(1)); } // New event to perform events.add(Pair.of(event, occurrences)); }); // The events will be performed by the caller consumer.accept(events.stream()); } catch (IOException | ParserException e) { throw new ImportException(e); } }
From source file:org.sonar.java.se.xproc.MethodYield.java
static Stream<Constraint> pmapToStream(@Nullable PMap<Class<? extends Constraint>, Constraint> pmap) { if (pmap == null) { return Stream.empty(); }// w ww .j a v a2 s . c o m Stream.Builder<Constraint> result = Stream.builder(); pmap.forEach((d, c) -> result.add(c)); return result.build(); }
From source file:fi.hsl.parkandride.core.service.PredictionServiceTest.java
private static void inParallel(Runnable... commands) throws InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(commands.length); List<Future<?>> futures = Stream.of(commands).map(executor::submit).collect(toList()); List<Exception> exceptions = futures.stream().flatMap(future -> { try {//w w w . ja v a 2s . c o m future.get(); return Stream.empty(); } catch (Exception e) { return Stream.of(e); } }).collect(toList()); if (!exceptions.isEmpty()) { AssertionError e = new AssertionError( "There were " + exceptions.size() + " uncaught exceptions in the background threads"); exceptions.forEach(e::addSuppressed); throw e; } }