Skip to content

Commit

Permalink
Use Stream#toList
Browse files Browse the repository at this point in the history
  • Loading branch information
ckittl committed Jan 6, 2022
1 parent 83b4f27 commit 1550173
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove unused imports
- Use enhanced switch statements
- Replace lambdas with method references
- Use `Stream#toList`
- Create JavaDoc with java 17 instead of java 8

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.couchbase.client.java.query.QueryResult;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
* Implements a DataConnector for Couchbase. Couchbase is a JSON document based database. <br>
Expand Down Expand Up @@ -115,7 +114,7 @@ public CompletableFuture<QueryResult> query(String query) {
*/
public List<CompletableFuture<GetResult>> bulkGet(List<String> keys) {
final Collection session = getSession();
return keys.stream().map(key -> session.async().get(key)).collect(Collectors.toList());
return keys.stream().map(key -> session.async().get(key)).toList();
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/edu/ie3/datamodel/io/factory/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<R> get(D data) {
// magic: case-insensitive get/set calls on set strings
final List<Set<String>> allFields = getFields(data);

validateParameters(data, allFields.stream().toArray((IntFunction<Set<String>[]>) Set[]::new));
validateParameters(data, allFields.toArray((IntFunction<Set<String>[]>) Set[]::new));

try {
// build the model
Expand Down Expand Up @@ -116,9 +116,7 @@ protected int validateParameters(D data, Set<String>... fieldSets) {

// get all sets that match the fields to attributes
List<Set<String>> validFieldSets =
Arrays.stream(fieldSets)
.filter(x -> x.equals(fieldsToValues.keySet()))
.collect(Collectors.toList());
Arrays.stream(fieldSets).filter(x -> x.equals(fieldsToValues.keySet())).toList();

if (validFieldSets.size() == 1) {
// if we can identify a unique parameter set for a constructor, we take it and return the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void checkExpectedDirectories() throws FileException {
*/
private void checkFurtherDirectoryElements() throws FileException {
try (Stream<Path> apparentElementsStream = Files.list(projectDirectory)) {
for (Path apparentPath : apparentElementsStream.collect(Collectors.toList())) {
for (Path apparentPath : apparentElementsStream.toList()) {
if (Files.isDirectory(apparentPath)
&& !subDirectories.containsKey(apparentPath)
&& apparentPath.compareTo(inputTree) != 0
Expand Down Expand Up @@ -219,7 +219,7 @@ public Optional<String> getSubDirectory(Class<? extends UniqueEntity> cls, Strin
.anyMatch(definedClass -> definedClass.isAssignableFrom(cls)))
.findFirst();

if (!maybeSubDirectory.isPresent()) {
if (maybeSubDirectory.isEmpty()) {
logger.debug("Don't know a fitting sub directory for class '{}'.", cls.getSimpleName());
return Optional.empty();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.ie3.util.geo.CoordinateDistance;
import edu.ie3.util.geo.GeoUtils;
import java.util.*;
import java.util.stream.Collectors;
import org.locationtech.jts.geom.Point;

/**
Expand Down Expand Up @@ -78,6 +77,6 @@ default List<CoordinateDistance> getNearestCoordinates(
(allCoordinates == null || allCoordinates.isEmpty())
? getAllCoordinates()
: allCoordinates);
return sortedDistances.stream().limit(n).collect(Collectors.toList());
return sortedDistances.stream().limit(n).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ protected List<Map<String, String>> csvRowFieldValueMapping(
.parallel()
.map(csvRow -> buildFieldsToAttributes(csvRow, headline))
.filter(map -> !map.isEmpty())
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.locationtech.jts.geom.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -118,7 +117,7 @@ public Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(
Set<Integer> coordinateIds =
coordinates.stream()
.map(idCoordinateSource::getId)
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
.flatMap(Optional::stream)
.collect(Collectors.toSet());
if (coordinateIds.isEmpty()) {
logger.warn("Unable to match coordinates to coordinate ID");
Expand All @@ -141,7 +140,7 @@ public Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(
public Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime date, Point coordinate) {
List<TimeBasedValue<WeatherValue>> timeBasedValues = Collections.emptyList();
Optional<Integer> coordinateId = idCoordinateSource.getId(coordinate);
if (!coordinateId.isPresent()) {
if (coordinateId.isEmpty()) {
logger.warn("Unable to match coordinate {} to a coordinate ID", coordinate);
return Optional.empty();
}
Expand Down Expand Up @@ -298,10 +297,7 @@ private List<TimeBasedValue<WeatherValue>> processWeatherQuery(PreparedStatement
*/
private List<TimeBasedValue<WeatherValue>> toTimeBasedWeatherValues(
Collection<Map<String, String>> fieldMaps) {
return fieldMaps.stream()
.map(this::toTimeBasedWeatherValue)
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
.collect(Collectors.toList());
return fieldMaps.stream().map(this::toTimeBasedWeatherValue).flatMap(Optional::stream).toList();
}

/**
Expand All @@ -314,7 +310,7 @@ private Optional<TimeBasedValue<WeatherValue>> toTimeBasedWeatherValue(
Map<String, String> fieldMap) {
fieldMap.remove("tid");
Optional<TimeBasedWeatherValueData> data = toTimeBasedWeatherValueData(fieldMap);
if (!data.isPresent()) return Optional.empty();
if (data.isEmpty()) return Optional.empty();
return weatherFactory.get(data.get());
}

Expand All @@ -331,7 +327,7 @@ private Optional<TimeBasedWeatherValueData> toTimeBasedWeatherValueData(
fieldMap.putIfAbsent("uuid", UUID.randomUUID().toString());
int coordinateId = Integer.parseInt(coordinateValue);
Optional<Point> coordinate = idCoordinateSource.getCoordinate(coordinateId);
if (!coordinate.isPresent()) {
if (coordinate.isEmpty()) {
logger.warn("Unable to match coordinate ID {} to a point", coordinateId);
return Optional.empty();
}
Expand Down

0 comments on commit 1550173

Please sign in to comment.