use of java.util.stream.Stream in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranchTest method newSwitchToSlaveSpy.
private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy() throws Exception {
PageCache pageCacheMock = mock(PageCache.class);
PagedFile pagedFileMock = mock(PagedFile.class);
when(pagedFileMock.getLastPageId()).thenReturn(1L);
when(pageCacheMock.map(any(File.class), anyInt())).thenReturn(pagedFileMock);
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
Stream mockStream = mock(Stream.class);
when(mockStream.filter(any(Predicate.class))).thenReturn(mock(Stream.class));
when(pageCacheMock.streamFilesRecursive(any(File.class))).thenReturn(mockStream);
return newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
}
use of java.util.stream.Stream in project sonarqube by SonarSource.
the class SearchProjectsAction method addFacets.
private static SearchProjectsWsResponse.Builder addFacets(SearchResults searchResults, SearchProjectsWsResponse.Builder wsResponse) {
Facets esFacets = searchResults.facets;
EsToWsFacet esToWsFacet = new EsToWsFacet();
searchResults.query.getLanguages().ifPresent(languages -> addMandatoryValuesToFacet(esFacets, FILTER_LANGUAGES, languages));
searchResults.query.getTags().ifPresent(tags -> addMandatoryValuesToFacet(esFacets, FILTER_TAGS, tags));
Common.Facets wsFacets = esFacets.getAll().entrySet().stream().map(esToWsFacet).collect(Collector.of(Common.Facets::newBuilder, Common.Facets.Builder::addFacets, (result1, result2) -> {
throw new IllegalStateException("Parallel execution forbidden");
}, Common.Facets.Builder::build));
wsResponse.setFacets(wsFacets);
return wsResponse;
}
use of java.util.stream.Stream in project processing by processing.
the class ChangeDetector method checkFiles.
// Synchronize, we are running async and touching fields
private synchronized void checkFiles() {
List<String> filenames = new ArrayList<>();
sketch.getSketchCodeFiles(filenames, null);
SketchCode[] codes = sketch.getCode();
// Separate codes with and without files
Map<Boolean, List<SketchCode>> existsMap = Arrays.stream(codes).collect(Collectors.groupingBy(code -> filenames.contains(code.getFileName())));
// ADDED FILES
List<String> codeFilenames = Arrays.stream(codes).map(SketchCode::getFileName).collect(Collectors.toList());
// Get filenames which are in filesystem but don't have code
List<String> addedFilenames = filenames.stream().filter(f -> !codeFilenames.contains(f)).collect(Collectors.toList());
// Show prompt if there are any added files which were not previously ignored
boolean added = addedFilenames.stream().anyMatch(f -> !ignoredAdditions.contains(f));
// REMOVED FILES
// Get codes which don't have file
List<SketchCode> removedCodes = Optional.ofNullable(existsMap.get(Boolean.FALSE)).orElse(Collections.emptyList());
// Show prompt if there are any removed codes which were not previously ignored
boolean removed = removedCodes.stream().anyMatch(code -> !ignoredRemovals.contains(code));
/// MODIFIED FILES
// Get codes which have file with different modification time
List<SketchCode> modifiedCodes = Optional.ofNullable(existsMap.get(Boolean.TRUE)).orElse(Collections.emptyList()).stream().filter(code -> {
long fileLastModified = code.getFile().lastModified();
long codeLastModified = code.getLastModified();
long diff = fileLastModified - codeLastModified;
return fileLastModified == 0L || diff > MODIFICATION_WINDOW_MILLIS;
}).collect(Collectors.toList());
// Show prompt if any open codes were modified
boolean modified = !modifiedCodes.isEmpty();
boolean ask = added || removed || modified;
if (DEBUG) {
System.out.println("ask: " + ask + "\n" + "added filenames: " + addedFilenames + ",\n" + "ignored added: " + ignoredAdditions + ",\n" + "removed codes: " + removedCodes + ",\n" + "ignored removed: " + ignoredRemovals + ",\n" + "modified codes: " + modifiedCodes);
}
// dismissing the prompt and we get another prompt before we even finished.
try {
// Wait for EDT to finish its business
// We need to stay in synchronized scope because of ignore lists
EventQueue.invokeAndWait(() -> {
// Show prompt if something interesting happened
if (ask && showReloadPrompt()) {
// She said yes!!!
if (sketch.getMainFile().exists()) {
sketch.reload();
editor.rebuildHeader();
} else {
// Mark everything as modified so that it saves properly
for (SketchCode code : codes) {
code.setModified(true);
}
try {
sketch.save();
} catch (Exception e) {
//if that didn't work, tell them it's un-recoverable
Messages.showError("Reload Failed", "The main file for this sketch was deleted\n" + "and could not be rewritten.", e);
}
}
// Sketch was reloaded, clear ignore lists
ignoredAdditions.clear();
ignoredRemovals.clear();
return;
}
// Update ignore lists to get rid of old stuff
ignoredAdditions = addedFilenames;
ignoredRemovals = removedCodes;
// If something changed, set modified flags and modification times
if (!removedCodes.isEmpty() || !modifiedCodes.isEmpty()) {
Stream.concat(removedCodes.stream(), modifiedCodes.stream()).forEach(code -> {
code.setModified(true);
code.setLastModified();
});
// Not sure if this is needed
editor.rebuildHeader();
}
});
} catch (InterruptedException ignore) {
} catch (InvocationTargetException e) {
Messages.loge("exception in ChangeDetector", e);
}
}
use of java.util.stream.Stream in project presto by prestodb.
the class AbstractTestQueries method testNonDeterministic.
@Test
public void testNonDeterministic() {
MaterializedResult materializedResult = computeActual("SELECT rand() FROM orders LIMIT 10");
long distinctCount = materializedResult.getMaterializedRows().stream().map(row -> row.getField(0)).distinct().count();
assertTrue(distinctCount >= 8, "rand() must produce different rows");
materializedResult = computeActual("SELECT apply(1, x -> x + rand()) FROM orders LIMIT 10");
distinctCount = materializedResult.getMaterializedRows().stream().map(row -> row.getField(0)).distinct().count();
assertTrue(distinctCount >= 8, "rand() must produce different rows");
}
use of java.util.stream.Stream in project aerosolve by airbnb.
the class Util method flattenFeatureWithDropoutAsStream.
/**
* Convert a feature vector from example to a nested stream(feature family, stream(feature name.
* feature value)) with dropout
*
* @apiNote Understand Stream can only be iterated once just like iterator, it is crucial to set a
* random seed if one wants to reproduce consistent dropout result.
*/
public static Stream<? extends Map.Entry<String, Stream<? extends Map.Entry<String, Double>>>> flattenFeatureWithDropoutAsStream(FeatureVector featureVector, double dropout, long seed) {
// collect string features into a stream
Stream<? extends Map.Entry<String, Stream<? extends Map.Entry<String, Double>>>> stringFeatures = Stream.empty();
if (featureVector.stringFeatures != null) {
stringFeatures = featureVector.stringFeatures.entrySet().stream().map(entry -> {
Stream<? extends Map.Entry<String, Double>> values = entry.getValue().stream().map(feature -> new HashMap.SimpleImmutableEntry<>(feature, 1.0));
return new HashMap.SimpleImmutableEntry<>(entry.getKey(), values);
});
}
// collect float features into a stream
Stream<? extends Map.Entry<String, Stream<? extends Map.Entry<String, Double>>>> floatFeatures = Stream.empty();
if (featureVector.floatFeatures != null) {
floatFeatures = featureVector.floatFeatures.entrySet().stream().map(entry -> new HashMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().entrySet().stream()));
}
// concat string and float features and apply dropout if necessary
Stream<? extends Map.Entry<String, Stream<? extends Map.Entry<String, Double>>>> flatFeatures = Stream.concat(stringFeatures, floatFeatures);
if (dropout > 0) {
Random random = new Random(seed);
// dropout needs to be applied in the inner most stream
return flatFeatures.map(entry -> new HashMap.SimpleImmutableEntry<>(entry.getKey(), entry.getValue().filter(x -> random.nextDouble() >= dropout)));
} else {
return flatFeatures;
}
}
Aggregations