use of java.util.stream.Stream in project neo4j by neo4j.
the class BuiltInProcedures method listConstraints.
@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ)
public Stream<ConstraintResult> listConstraints() {
Statement statement = tx.acquireStatement();
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
return asList(operations.constraintsGetAll()).stream().map((constraint) -> constraint.prettyPrint(tokens)).sorted().map(ConstraintResult::new).onClose(statement::close);
}
use of java.util.stream.Stream in project neo4j by neo4j.
the class ProcedureIT method shouldBeAbleToUseCallYieldWithPeriodicCommit.
@Test
public void shouldBeAbleToUseCallYieldWithPeriodicCommit() throws IOException {
// GIVEN
String[] lines = IntStream.rangeClosed(1, 100).boxed().map(i -> Integer.toString(i)).toArray(String[]::new);
String url = createCsvFile(lines);
//WHEN
Result result = db.execute("USING PERIODIC COMMIT 1 " + "LOAD CSV FROM '" + url + "' AS line " + "CALL org.neo4j.procedure.createNode(line[0]) YIELD node as n " + "RETURN n.prop");
// THEN
for (int i = 1; i <= 100; i++) {
assertThat(result.next().get("n.prop"), equalTo(Integer.toString(i)));
}
//Make sure all the lines has been properly commited to the database.
String[] dbContents = db.execute("MATCH (n) return n.prop").stream().map(m -> (String) m.get("n.prop")).toArray(String[]::new);
assertThat(dbContents, equalTo(lines));
}
use of java.util.stream.Stream in project traffic-engine by opentraffic.
the class VehicleStates method processLocationUpdates.
public void processLocationUpdates() {
Map<Fun.Tuple2<Integer, Integer>, AtomicInteger> sortedMap = sortByValue(tileCount);
for (Fun.Tuple2<Integer, Integer> tile : sortedMap.keySet()) {
if (sortedMap.get(tile).get() >= MINIMUM_VEHICLE_COUNT) {
if (!osmData.isLoadingOSM() || osmData.osmAreas.containsKey(tile)) {
Map<Long, Boolean> vehicles = tileVehicleMap.get(tile);
for (Long vehicleId : vehicles.keySet()) {
Vehicle vehicle = getVehicle(vehicleId, false);
if (vehicle != null && vehicle.tryLock()) {
try {
long processedLocations = vehicle.processVehicle();
synchronized (lastEmptyVehicleUpdateMap) {
if (processedLocations == 0 || vehicle.queueSize.get() == 0) {
if (!lastEmptyVehicleUpdateMap.containsKey(vehicleId)) {
lastEmptyVehicleUpdateMap.put(vehicleId, System.currentTimeMillis());
}
} else {
lastEmptyVehicleUpdateMap.remove(vehicleId);
}
}
updateProcessingRate();
} finally {
vehicle.unlock();
}
}
}
}
} else {
Map<Long, Boolean> vehicles = tileVehicleMap.get(tile);
for (Long vehicleId : vehicles.keySet()) {
if (!lastEmptyVehicleUpdateMap.containsKey(vehicleId)) {
lastEmptyVehicleUpdateMap.put(vehicleId, System.currentTimeMillis());
}
}
}
updateProcessingRate();
}
synchronized (lastEmptyVehicleUpdateMap) {
lastEmptyVehicleUpdateMap.keySet().stream().filter(vehicleId -> lastEmptyVehicleUpdateMap.containsKey(vehicleId)).forEach(vehicleId -> {
long lastEmptyUpdate = lastEmptyVehicleUpdateMap.get(vehicleId);
Vehicle vehicle = getVehicle(vehicleId, false);
if (vehicle != null && System.currentTimeMillis() - lastEmptyUpdate > VEHICLE_INVALIDATION_TIME) {
if (vehicle.tile != null && tileCount.containsKey(vehicle.tile) && tileCount.get(vehicle.tile).get() < MINIMUM_VEHICLE_COUNT) {
removeVehicle(vehicleId);
} else if (vehicle.queueSize.get() == 0) {
removeVehicle(vehicleId);
}
}
});
}
}
use of java.util.stream.Stream in project presto by prestodb.
the class PlanPrinter method textDistributedPlan.
public static String textDistributedPlan(List<StageInfo> stages, Metadata metadata, Session session) {
StringBuilder builder = new StringBuilder();
List<StageInfo> allStages = stages.stream().flatMap(stage -> getAllStages(Optional.of(stage)).stream()).collect(toImmutableList());
for (StageInfo stageInfo : allStages) {
Map<PlanNodeId, PlanNodeStats> aggregatedStats = new HashMap<>();
List<PlanNodeStats> planNodeStats = stageInfo.getTasks().stream().map(TaskInfo::getStats).flatMap(taskStats -> getPlanNodeStats(taskStats).stream()).collect(toList());
for (PlanNodeStats stats : planNodeStats) {
aggregatedStats.merge(stats.getPlanNodeId(), stats, PlanNodeStats::merge);
}
builder.append(formatFragment(metadata, session, stageInfo.getPlan(), Optional.of(stageInfo.getStageStats()), Optional.of(aggregatedStats)));
}
return builder.toString();
}
use of java.util.stream.Stream in project ratpack by ratpack.
the class AbstractPropertiesConfigSource method loadConfigData.
@Override
public ObjectNode loadConfigData(ObjectMapper objectMapper, FileSystemBinding fileSystemBinding) throws Exception {
ObjectNode rootNode = objectMapper.createObjectNode();
Properties properties = loadProperties();
Stream<Pair<String, String>> pairs = properties.stringPropertyNames().stream().map(key -> Pair.of(key, properties.getProperty(key)));
if (prefix.isPresent()) {
pairs = pairs.filter(p -> p.left.startsWith(prefix.get())).map(((Function<Pair<String, String>, Pair<String, String>>) p -> p.mapLeft(s -> s.substring(prefix.get().length()))).toFunction());
}
pairs.forEach(p -> populate(rootNode, p.left, p.right));
return rootNode;
}
Aggregations