-
Notifications
You must be signed in to change notification settings - Fork 7
Extractor for nested models #92
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
Changes from all commits
b5fb4fd
86c54e4
ce6a95a
4cb0463
6bfa59f
8b50db6
795fcc3
7e1a634
bddcb0e
2c07caf
8869594
39e83f7
27cc3bd
1376151
5547b54
c47866f
d45c2a9
7b484fb
25008b0
17e7438
65040e1
f6d8106
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* © 2020. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.exceptions; | ||
|
||
/** | ||
* Exception that should be used whenevery something invalid happens in a implementation of a {@link | ||
* edu.ie3.datamodel.io.connectors.DataConnector} | ||
* | ||
* @version 0.1 | ||
* @since 20.03.20 | ||
*/ | ||
public class ExtractorException extends Exception { | ||
|
||
public ExtractorException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ExtractorException(final Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ExtractorException(final String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||
* © 2020. TU Dortmund University, | ||||||||||||||||||||||||||||||||||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||||||||||||||||||||||||||||||||||
* Research group Distribution grid planning and operation | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
package edu.ie3.datamodel.io.extractor; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
import edu.ie3.datamodel.exceptions.ExtractorException; | ||||||||||||||||||||||||||||||||||
import edu.ie3.datamodel.models.input.InputEntity; | ||||||||||||||||||||||||||||||||||
import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||
import java.util.Arrays; | ||||||||||||||||||||||||||||||||||
import java.util.Collections; | ||||||||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||
* A simple utility class that can be used by sinks to extract nested elements (e.g. nodes, types) | ||||||||||||||||||||||||||||||||||
* that should be persisted. | ||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||
* @version 0.1 | ||||||||||||||||||||||||||||||||||
* @since 31.03.20 | ||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
public class Extractor { | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
private final List<InputEntity> extractedEntities; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public Extractor(Nested nestedEntity) throws ExtractorException { | ||||||||||||||||||||||||||||||||||
this.extractedEntities = extractElements(nestedEntity); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
private List<InputEntity> extractElements(Nested nestedEntity) throws ExtractorException { | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This automatically would ensure, that duplicated nodes etc. are only apparent once. |
||||||||||||||||||||||||||||||||||
List<InputEntity> resultingList = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||
if (nestedEntity instanceof Node) { | ||||||||||||||||||||||||||||||||||
resultingList.add(((Node) nestedEntity).getNode()); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (nestedEntity instanceof NodeC) { | ||||||||||||||||||||||||||||||||||
resultingList.add(((NodeC) nestedEntity).getNodeC()); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (nestedEntity instanceof Nodes) { | ||||||||||||||||||||||||||||||||||
resultingList.addAll( | ||||||||||||||||||||||||||||||||||
Arrays.asList(((Nodes) nestedEntity).getNodeA(), ((Nodes) nestedEntity).getNodeB())); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (nestedEntity instanceof Type) { | ||||||||||||||||||||||||||||||||||
resultingList.add(((Type) nestedEntity).getType()); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if (resultingList.isEmpty()) { | ||||||||||||||||||||||||||||||||||
throw new ExtractorException( | ||||||||||||||||||||||||||||||||||
"The interface 'Nested' is not meant to be extended. The provided entity of class '" | ||||||||||||||||||||||||||||||||||
+ nestedEntity.getClass().getSimpleName() | ||||||||||||||||||||||||||||||||||
+ "' and cannot be processed by " | ||||||||||||||||||||||||||||||||||
+ "the extractor! Currently only the interfaces 'Node', 'NodeC', ‘Nodes‘ and ‘Type' are supported!"); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return Collections.unmodifiableList(resultingList); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
public List<InputEntity> getExtractedEntities() { | ||||||||||||||||||||||||||||||||||
return extractedEntities; | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
/* | ||||||
* © 2020. TU Dortmund University, | ||||||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||||||
* Research group Distribution grid planning and operation | ||||||
*/ | ||||||
package edu.ie3.datamodel.io.extractor; | ||||||
|
||||||
/** | ||||||
* This interface should be implemented only by other interfaces that should be used by the {@link | ||||||
* Extractor} It provides the entry point for the extraction method in the {@link Extractor}. If | ||||||
* this interface is implemented by other interfaces one has to take care about, that the | ||||||
* corresponding method {@link Extractor.extractElements()} is extended accordingly. | ||||||
* | ||||||
* @version 0.1 | ||||||
* @since 31.03.20 | ||||||
*/ | ||||||
public interface Nested {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* © 2020. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io.extractor; | ||
|
||
import edu.ie3.datamodel.models.input.NodeInput; | ||
|
||
/** | ||
* Interface that should be implemented by all elements holding a {@link NodeInput} and should be | ||
* processable by the {@link Extractor} | ||
* | ||
* @version 0.1 | ||
* @since 31.03.20 | ||
*/ | ||
public interface Node extends Nested { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about pimpin the |
||
|
||
NodeInput getNode(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* © 2020. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io.extractor; | ||
|
||
import edu.ie3.datamodel.models.input.NodeInput; | ||
|
||
/** | ||
* Interface that should be implemented by all elements holding a third {@link NodeInput} and should | ||
* be processable by the {@link Extractor}. For now, this only holds true by the {@link | ||
* edu.ie3.datamodel.models.input.connector.Transformer3WInput} | ||
* | ||
* @version 0.1 | ||
* @since 31.03.20 | ||
*/ | ||
public interface NodeC extends Nested { | ||
|
||
NodeInput getNodeC(); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||||||
/* | ||||||||||
* © 2020. TU Dortmund University, | ||||||||||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||||||||||
* Research group Distribution grid planning and operation | ||||||||||
*/ | ||||||||||
package edu.ie3.datamodel.io.extractor; | ||||||||||
|
||||||||||
import edu.ie3.datamodel.models.input.NodeInput; | ||||||||||
|
||||||||||
/** | ||||||||||
* Interface that should be implemented by all elements holding a two {@link NodeInput} elements and | ||||||||||
* should be processable by the {@link Extractor}. For now, this only holds true by all {@link | ||||||||||
* edu.ie3.datamodel.models.input.connector.ConnectorInput} and {@link | ||||||||||
* edu.ie3.datamodel.models.input.connector.TransformerInput} | ||||||||||
* | ||||||||||
* @version 0.1 | ||||||||||
* @since 31.03.20 | ||||||||||
*/ | ||||||||||
public interface Nodes extends Nested { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It is not really an Interface describing nodes conceptually, but an entity, that has nodes. |
||||||||||
|
||||||||||
NodeInput getNodeA(); | ||||||||||
|
||||||||||
NodeInput getNodeB(); | ||||||||||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* © 2020. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io.extractor; | ||
|
||
import edu.ie3.datamodel.models.input.AssetTypeInput; | ||
|
||
/** | ||
* Interface that should be implemented by all elements holding a {@link AssetTypeInput} and should | ||
* be processable by the {@link Extractor}. | ||
* | ||
* @version 0.1 | ||
* @since 31.03.20 | ||
*/ | ||
public interface Type extends Nested { | ||
|
||
AssetTypeInput getType(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to have a simple static class. So then you could save the instantiation.