Skip to content

Commit

Permalink
Merge pull request #437 from com-pas/436-add-connectedapservice-and-s…
Browse files Browse the repository at this point in the history
…ubnetworkservice

feat(#436): Add ConnectedAPService and SubnetworkService
  • Loading branch information
samirromdhani authored Oct 22, 2024
2 parents d7f8a85 + 2fec318 commit f92c09c
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 f92c09c

Please sign in to comment.