-
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #92 +/- ##
============================================
+ Coverage 61.52% 61.82% +0.29%
- Complexity 777 793 +16
============================================
Files 182 184 +2
Lines 3413 3455 +42
Branches 430 436 +6
============================================
+ Hits 2100 2136 +36
Misses 1188 1188
- Partials 125 131 +6
Continue to review full report at Codecov.
|
- adaptions in Extractor processing to throw an exception for unknown elements - integrate Extractor into CsvFileSink - extended DataSink interface with methods for nested and unnested elements for performance purposes
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.
Despite my comments, your and my approach in #89 differ, especially in terms of the role of the DataSink
. Let's discuss to get the best solution.
* @version 0.1 | ||
* @since 31.03.20 | ||
*/ | ||
public class Extractor { |
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.
public class Extractor { | |
public class NestedEntityUtils { | |
public NestedEntityUtils() { | |
throw new IllegalStateException("Do not instantiate static utility class"); | |
} |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
private List<InputEntity> extractElements(Nested nestedEntity) throws ExtractorException { | |
private Set<InputEntity> extractElements(Collection<Nested> nestedEntities) throws ExtractorException { | |
return Collections.unmodifiableSet(nestedEntities.stream().map(nested -> { | |
if (nestedEntities instanceof Node) { | |
return Collections.singletonList(((Node) nestedEntities).getNode()); | |
} else if (nestedEntities instanceof NodeC) { | |
return Collections.singletonList(((NodeC) nestedEntities).getNodeC()); | |
} else if (nestedEntities instanceof Nodes) { | |
return Arrays.asList(((Nodes) nestedEntities).getNodeA(), ((Nodes) nestedEntities).getNodeB()); | |
} else if (nestedEntities instanceof Type) { | |
return Collections.singletonList(((Type) nestedEntities).getType()); | |
} else { | |
return new ArrayList<InputEntity>(); | |
} | |
}).flatMap(List::stream).collect(Collectors.toSet())); | |
} |
This automatically would ensure, that duplicated nodes etc. are only apparent once.
* @version 0.1 | ||
* @since 31.03.20 | ||
*/ | ||
public interface Nested {} |
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.
public interface Nested {} | |
public interface NestedEntity {} |
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
What about pimpin the Nodes
interface and letting go Node
and NodeC
? See comments below.
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
public interface Nodes extends Nested { | |
public interface WithNestedNodes extends Nested { |
It is not really an Interface describing nodes conceptually, but an entity, that has nodes.
NodeInput getNodeA(); | ||
|
||
NodeInput getNodeB(); |
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.
NodeInput getNodeA(); | |
NodeInput getNodeB(); | |
Collection<NodeInput> getNodes(); |
resolves #78