Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sonar code smells #123

Merged
merged 1 commit into from
Aug 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Element;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.lfenergy.compas.scl.auto.alignment.SclAutoAlignmentConstants.SCLXY_NS_URI;
Expand Down Expand Up @@ -34,7 +33,7 @@ public static void cleanSXYDeclarationAndAttributes(Element element) {
.filter(Attr.class::isInstance)
.map(Attr.class::cast)
.filter(attr -> SCLXY_NS_URI.equals(attr.getNamespaceURI()))
.collect(Collectors.toList());
.toList();
// Remove the attribute from the element.
attributesToRemove.forEach(element::removeAttributeNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.w3c.dom.Element;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class GenericBay extends AbstractGenericNameEntity<GenericVoltageLevel> {
Expand All @@ -33,7 +32,7 @@ public List<GenericConnectivityNode> getConnectivityNodes() {
if (connectivityNodes == null) {
connectivityNodes = getElementsStream("ConnectivityNode")
.map(element -> new GenericConnectivityNode(this, element))
.collect(Collectors.toList());
.toList();
}
return connectivityNodes;
}
Expand All @@ -42,7 +41,7 @@ public List<GenericConductingEquipment> getConductingEquipments() {
if (conductingEquipments == null) {
conductingEquipments = getElementsStream("ConductingEquipment")
.map(element -> new GenericConductingEquipment(this, element))
.collect(Collectors.toList());
.toList();
}
return conductingEquipments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import org.w3c.dom.Element;

import java.util.List;
import java.util.stream.Collectors;

public class GenericConductingEquipment extends AbstractGenericNameEntity<GenericBay> {
private List<GenericTerminal> terminals;

public GenericConductingEquipment(GenericBay parent, Element element) {
super(parent, element);
}
Expand All @@ -23,7 +22,7 @@ public List<GenericTerminal> getTerminals() {
if (terminals == null) {
terminals = getElementsStream("Terminal")
.map(element -> new GenericTerminal(this, element))
.collect(Collectors.toList());
.toList();
}
return terminals;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class GenericPowerTransformer extends AbstractGenericNameEntity<GenericSubstation> {
private List<GenericTransformerWinding> transformerWindings;
Expand All @@ -21,7 +20,7 @@ public List<GenericTransformerWinding> getTransformerWindings() {
if (transformerWindings == null) {
transformerWindings = getElementsStream("TransformerWinding")
.map(element -> new GenericTransformerWinding(this, element))
.collect(Collectors.toList());
.toList();
}
return transformerWindings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.lfenergy.compas.scl.auto.alignment.SclAutoAlignmentConstants.*;

Expand Down Expand Up @@ -39,7 +38,7 @@ public List<GenericSubstation> getSubstations() {
if (substations == null) {
substations = ElementUtil.getElementsStream(element, "Substation")
.map(substationElement -> new GenericSubstation(this, substationElement))
.collect(Collectors.toList());
.toList();
}
return substations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class GenericSubstation extends AbstractGenericNameEntity<GenericSCL> {
private List<GenericPowerTransformer> powerTransformers;
Expand All @@ -28,7 +27,7 @@ public List<GenericPowerTransformer> getPowerTransformers() {
if (powerTransformers == null) {
powerTransformers = getElementsStream("PowerTransformer")
.map(element -> new GenericPowerTransformer(this, element))
.collect(Collectors.toList());
.toList();
}
return powerTransformers;
}
Expand All @@ -51,7 +50,7 @@ public List<GenericVoltageLevel> getVoltageLevels() {
if (voltageLevels == null) {
voltageLevels = getElementsStream("VoltageLevel")
.map(element -> new GenericVoltageLevel(this, element))
.collect(Collectors.toList());
.toList();
}
return voltageLevels;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.w3c.dom.Element;

import java.util.List;
import java.util.stream.Collectors;

public class GenericTransformerWinding extends AbstractGenericNameEntity<GenericPowerTransformer> {
private List<GenericTerminal> terminals;
Expand All @@ -19,7 +18,7 @@ public List<GenericTerminal> getTerminals() {
if (terminals == null) {
terminals = getElementsStream("Terminal")
.map(element -> new GenericTerminal(this, element))
.collect(Collectors.toList());
.toList();
}
return terminals;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.w3c.dom.Element;

import java.util.List;
import java.util.stream.Collectors;

import static org.lfenergy.compas.scl.auto.alignment.exception.SclAutoAlignmentErrorCode.NO_VOLTAGE_FOUND_ERROR_CODE;

Expand All @@ -30,7 +29,7 @@ public List<GenericBay> getBays() {
if (bays == null) {
bays = getElementsStream("Bay")
.map(element -> new GenericBay(this, element))
.collect(Collectors.toList());
.toList();
}
return bays;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
import static org.lfenergy.compas.scl.auto.alignment.SclAutoAlignmentConstants.SCLXY_NS_URI;
Expand Down Expand Up @@ -35,15 +34,15 @@ void constructor_WhenCreated_ThenElementSet() {
@Test
void getElementsStream_WhenCallingForKnownElement_ThenReturnElements() {
var result = entity.getElementsStream("Bay")
.collect(Collectors.toList());
.toList();

assertEquals(8, result.size());
}

@Test
void getElementsStream_WhenCallingForUnknownElement_ThenReturnEmptyList() {
var result = entity.getElementsStream("Unknown")
.collect(Collectors.toList());
.toList();

assertTrue(result.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.lfenergy.compas.scl.auto.alignment.common.ElementUtil;

import java.io.IOException;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -52,7 +51,7 @@ void addHistoryItem_WhenCalled_ThenAllElementsAreCreated() {

var history = ElementUtil.getElementsStream(header.getElement(), "History").findFirst().orElse(null);
assertNotNull(history);
var historyItems = ElementUtil.getElementsStream(header.getElement(), "Hitem").collect(Collectors.toList());
var historyItems = ElementUtil.getElementsStream(header.getElement(), "Hitem").toList();
var historyItem = historyItems.get(historyItems.size() - 1);
assertNotNull(historyItem);
assertNotNull(historyItem.getAttribute("revision"));
Expand Down