Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased/Snapshot]

### Fixed
- Reduced code smells [#492](https://github.com/ie3-institute/PowerSystemDataModel/issues/492)
- Protected constructors for abstract classes
- Use pattern matching
- Remove unused imports
- Use enhanced switch statements
- Replace lambdas with method references
- Use `Stream#toList`
- Adapt visibility for JUnit 5
- Fix JavaDoc creation
- Create JavaDoc with java 17 instead of java 8
- Let JavDoc pass, if there are warnings **ATTENTION:** Should be removed, when JavaDoc is fixed! (cf. Issue [#494](https://github.com/ie3-institute/PowerSystemDataModel/issues/494))

## [2.1.0] - 2022-01-05

### Added
Expand Down
11 changes: 4 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ node {
gradle('--refresh-dependencies clean spotlessCheck pmdMain pmdTest spotbugsMain ' +
'spotbugsTest test jacocoTestReport jacocoTestCoverageVerification', projectName)

// due to an issue with openjdk-8 we use openjdk-11 for javadocs generation
sh(script: """set +x && cd $projectName""" + ''' set +x; ./gradlew clean javadoc -Dorg.gradle.java.home=/opt/java/openjdk''', returnStdout: true)
sh(script: """set +x && cd $projectName""" + ''' set +x; ./gradlew clean javadoc''', returnStdout: true)
}

// sonarqube analysis
Expand Down Expand Up @@ -159,13 +158,11 @@ node {
]) {

/*
* There is a known bug in JavaDoc generation in JDK 8. Therefore generate the JavaDoc with JDK
* 11 first and do the rest of the tasks with JDK 8. IMPORTANT: Do not issue 'clean' in the
* following task
* IMPORTANT: Do not issue 'clean' in the following task
*/
sh(
script: """set +x && cd $projectName""" +
''' set +x; ./gradlew clean javadoc -Dorg.gradle.java.home=/opt/java/openjdk''',
''' set +x; ./gradlew clean javadoc''',
returnStdout: true
)

Expand Down Expand Up @@ -395,7 +392,7 @@ def deployJavaDocs(String projectName, String sshCredentialsId, String gitChecko
"git config user.name 'Johannes Hiry' && " +
"git fetch --depth=1 origin api-docs && " +
"git checkout api-docs && " +
"cd .. && ./gradlew clean javadoc -Dorg.gradle.java.home=/opt/java/openjdk && " +
"cd .. && ./gradlew clean javadoc && " +
"cp -R build/docs/javadoc/* tmp-api-docs && " +
"cd tmp-api-docs &&" +
"git add --all && git commit -m 'updated api-docs' && git push origin api-docs:api-docs" +
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ tasks.withType(JavaCompile) {

tasks.withType(Javadoc){
options.encoding = 'UTF-8'
failOnError = false // TODO: Temp until JavaDoc issues are resolved
}

task printVersion {
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spotless {

// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
format 'misc', {
target '**/*.md', '**/.gitignore', 'configs/**'
target '**/.gitignore', 'configs/**'
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
package edu.ie3.datamodel.exceptions;

public abstract class ValidationException extends RuntimeException {
public ValidationException(String s) {
protected ValidationException(String s) {
super(s);
}

public ValidationException(String s, Throwable throwable) {
protected ValidationException(String s, Throwable throwable) {
super(s, throwable);
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public abstract class FileNameMetaInformation {
private final UUID uuid;

public FileNameMetaInformation(UUID uuid) {
protected FileNameMetaInformation(UUID uuid) {
this.uuid = uuid;
}

Expand All @@ -23,8 +23,7 @@ public UUID getUuid() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FileNameMetaInformation)) return false;
FileNameMetaInformation that = (FileNameMetaInformation) o;
if (!(o instanceof FileNameMetaInformation that)) return false;
return uuid.equals(that.uuid);
}

Expand Down
30 changes: 15 additions & 15 deletions src/main/java/edu/ie3/datamodel/io/extractor/Extractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ private Extractor() {
public static Set<InputEntity> extractElements(NestedEntity nestedEntity)
throws ExtractorException {
CopyOnWriteArrayList<InputEntity> resultingList = new CopyOnWriteArrayList<>();
if (nestedEntity instanceof HasNodes) {
resultingList.addAll(((HasNodes) nestedEntity).allNodes());
if (nestedEntity instanceof HasNodes nestedHasNode) {
resultingList.addAll((nestedHasNode).allNodes());
}
if (nestedEntity instanceof Operable) {
extractOperator((Operable) nestedEntity).ifPresent(resultingList::add);
if (nestedEntity instanceof Operable nestedOperable) {
extractOperator(nestedOperable).ifPresent(resultingList::add);
}
if (nestedEntity instanceof HasType) {
resultingList.add(extractType((HasType) nestedEntity));
if (nestedEntity instanceof HasType nestedHasType) {
resultingList.add(extractType(nestedHasType));
}
if (nestedEntity instanceof HasThermalBus) {
resultingList.add(((HasThermalBus) nestedEntity).getThermalBus());
if (nestedEntity instanceof HasThermalBus nestedHasThermalBus) {
resultingList.add((nestedHasThermalBus).getThermalBus());
}
if (nestedEntity instanceof HasThermalStorage) {
resultingList.add(((HasThermalStorage) nestedEntity).getThermalStorage());
if (nestedEntity instanceof HasThermalStorage nestedHasThermalStorage) {
resultingList.add((nestedHasThermalStorage).getThermalStorage());
}
if (nestedEntity instanceof HasLine) {
resultingList.add(((HasLine) nestedEntity).getLine());
if (nestedEntity instanceof HasLine nestedHasLine) {
resultingList.add((nestedHasLine).getLine());
}

if (resultingList.contains(null)) {
Expand All @@ -72,9 +72,9 @@ public static Set<InputEntity> extractElements(NestedEntity nestedEntity)
.parallel()
.forEach(
element -> {
if (element instanceof NestedEntity) {
if (element instanceof NestedEntity nestedElement) {
try {
resultingList.addAll(extractElements((NestedEntity) element));
resultingList.addAll(extractElements(nestedElement));
} catch (ExtractorException e) {
log.error(
"An error occurred during extraction of nested entity '{}':{}",
Expand All @@ -84,7 +84,7 @@ public static Set<InputEntity> extractElements(NestedEntity nestedEntity)
}
});

return Collections.unmodifiableSet(new HashSet<>(resultingList));
return Set.copyOf(resultingList);
}

public static AssetTypeInput extractType(HasType entityWithType) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/ie3/datamodel/io/factory/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Optional<Geometry> getGeometry(String field) {
public Optional<LineString> getLineString(String field) {
Optional<Geometry> geom = getGeometry(field);
if (geom.isPresent()) {
if (geom.get() instanceof LineString) return Optional.of((LineString) geom.get());
if (geom.get() instanceof LineString lineString) return Optional.of(lineString);
else
throw new FactoryException(
"Geometry is of type "
Expand All @@ -116,7 +116,7 @@ public Optional<LineString> getLineString(String field) {
public Optional<Point> getPoint(String field) {
Optional<Geometry> geom = getGeometry(field);
if (geom.isPresent()) {
if (geom.get() instanceof Point) return Optional.of((Point) geom.get());
if (geom.get() instanceof Point point) return Optional.of(point);
else
throw new FactoryException(
"Geometry is of type "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package edu.ie3.datamodel.io.factory;

import edu.ie3.datamodel.models.UniqueEntity;
import java.util.*;

/**
* Universal factory class for creating entities with {@link EntityData} data objects.
Expand All @@ -24,7 +23,7 @@ public abstract class EntityFactory<T extends UniqueEntity, D extends EntityData
*
* @param allowedClasses exactly the classes that this factory is allowed and able to build
*/
public EntityFactory(Class<? extends T>... allowedClasses) {
protected EntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}
}
8 changes: 3 additions & 5 deletions src/main/java/edu/ie3/datamodel/io/factory/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class Factory<C, D extends FactoryData, R> {

private final List<Class<? extends C>> supportedClasses;

public Factory(Class<? extends C>... supportedClasses) {
protected Factory(Class<? extends C>... supportedClasses) {
this.supportedClasses = Arrays.asList(supportedClasses);
}

Expand All @@ -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 @@ -17,7 +17,7 @@
public abstract class SimpleEntityFactory<T extends UniqueEntity>
extends EntityFactory<T, SimpleEntityData> {

public SimpleEntityFactory(Class<? extends T>... allowedClasses) {
protected SimpleEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class AssetInputEntityFactory<T extends AssetInput, D extends As
private static final String OPERATES_UNTIL = "operatesuntil";
private static final String ID = "id";

public AssetInputEntityFactory(Class<? extends T>... allowedClasses) {
protected AssetInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class ConnectorInputEntityFactory<
*/
protected static final String PARALLEL_DEVICES = "paralleldevices";

public ConnectorInputEntityFactory(Class<? extends T>... allowedClasses) {
protected ConnectorInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class GraphicInputFactory<T extends GraphicInput, D extends Enti
private static final String GRAPHIC_LAYER = "graphiclayer";
private static final String PATH_LINE_STRING = "path";

public GraphicInputFactory(Class<? extends T>... allowedClasses) {
protected GraphicInputFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import edu.ie3.datamodel.models.input.system.type.HpTypeInput;
import edu.ie3.datamodel.models.input.thermal.ThermalBusInput;
import java.util.Map;
import java.util.Objects;

public class HpInputEntityData extends SystemParticipantTypedEntityData<HpTypeInput> {
private final ThermalBusInput thermalBusInput;
Expand Down Expand Up @@ -38,6 +39,19 @@ public ThermalBusInput getThermalBusInput() {
return thermalBusInput;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof HpInputEntityData that)) return false;
if (!super.equals(o)) return false;
return thermalBusInput.equals(that.thermalBusInput);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), thermalBusInput);
}

@Override
public String toString() {
return "HpInputEntityData{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class SystemParticipantInputEntityFactory<

private static final String Q_CHARACTERISTICS = "qcharacteristics";

public SystemParticipantInputEntityFactory(Class<? extends T>... allowedClasses) {
protected SystemParticipantInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ abstract class ResultEntityFactory<T extends ResultEntity> extends SimpleEntityF

protected final TimeUtil timeUtil;

public ResultEntityFactory(Class<? extends T>... allowedClasses) {
protected ResultEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
timeUtil = TimeUtil.withDefaults;
}

public ResultEntityFactory(String dtfPattern, Class<? extends T>... allowedClasses) {
protected ResultEntityFactory(String dtfPattern, Class<? extends T>... allowedClasses) {
super(allowedClasses);
timeUtil = new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package edu.ie3.datamodel.io.factory.timeseries;

import static edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory.*;

import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.WeatherValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class TimeBasedValueData<V extends Value> extends FactoryData {
* @param fieldsToAttributes attribute map: field name to value
* @param valueClass Class of the underlying value
*/
public TimeBasedValueData(Map<String, String> fieldsToAttributes, Class<V> valueClass) {
protected TimeBasedValueData(Map<String, String> fieldsToAttributes, Class<V> valueClass) {
super(fieldsToAttributes, valueClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public abstract class TimeBasedValueFactory<D extends TimeBasedValueData<V>, V extends Value>
extends Factory<V, D, TimeBasedValue<V>> {
public TimeBasedValueFactory(Class<? extends V>... valueClasses) {
protected TimeBasedValueFactory(Class<? extends V>... valueClasses) {
super(valueClasses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AssetTypeInputEntityFactory<T extends AssetTypeInput>
protected static final String ENTITY_UUID = "uuid";
protected static final String ENTITY_ID = "id";

public AssetTypeInputEntityFactory(Class<? extends T>... allowedClasses) {
protected AssetTypeInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}
}
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 @@ -336,8 +336,7 @@ Optional<String> getEntityName(T timeSeries) {
logger.error("Unable to determine content of time series {}", timeSeries);
return Optional.empty();
}
} else if (timeSeries instanceof LoadProfileInput) {
LoadProfileInput loadProfileInput = (LoadProfileInput) timeSeries;
} else if (timeSeries instanceof LoadProfileInput loadProfileInput) {
return Optional.of(
prefix
.concat("lpts")
Expand Down
Loading