Skip to content

Commit

Permalink
feat(#436): Add ConnectedAPService and SubnetworkService
Browse files Browse the repository at this point in the history
Signed-off-by: gleizesDor <[email protected]>
  • Loading branch information
gleizesDor committed Oct 18, 2024
1 parent d7f8a85 commit 2fec318
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
import org.lfenergy.compas.scl2007b4.model.TSubNetwork;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class ConnectedAPService {

public Stream<TConnectedAP> getConnectedAP(TSubNetwork tSubNetwork) {
if (!tSubNetwork.isSetConnectedAP()) {
return Stream.empty();
}
return tSubNetwork.getConnectedAP().stream();
}

public Stream<TConnectedAP> getFilteredConnectedAP(TSubNetwork tSubNetwork, Predicate<TConnectedAP> tConnectedAPPredicate) {
return getConnectedAP(tSubNetwork).filter(tConnectedAPPredicate);
}

public Optional<TConnectedAP> findConnectedAP(TSubNetwork tSubNetwork, Predicate<TConnectedAP> tConnectedAPPredicate) {
return getFilteredConnectedAP(tSubNetwork, tConnectedAPPredicate).findFirst();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.TSubNetwork;
import org.lfenergy.compas.scl2007b4.model.SCL;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class SubNetworkService {

public Stream<TSubNetwork> getSubNetworks(SCL scl) {
if (!scl.isSetCommunication()) {
return Stream.empty();
}
if (!scl.getCommunication().isSetSubNetwork()) {
return Stream.empty();
}
return scl.getCommunication().getSubNetwork().stream();
}

public Stream<TSubNetwork> getFilteredSubNetworks(SCL tlNodeType, Predicate<TSubNetwork> tdoPredicate) {
return getSubNetworks(tlNodeType).filter(tdoPredicate);
}

public Optional<TSubNetwork> findSubNetwork(SCL tlNodeType, Predicate<TSubNetwork> tdoPredicate) {
return getFilteredSubNetworks(tlNodeType, tdoPredicate).findFirst();
}

}

0 comments on commit 2fec318

Please sign in to comment.