diff --git a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java index c34f630f95fe5523711d7a04d231d77fce308515..e98181d4d24dc86662cc24cd65d84b7bbe8b2fdd 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java @@ -2,10 +2,25 @@ import info.textgrid.namespaces.metadata.core._2010.ObjectType; +import java.util.List; + +import com.google.common.collect.Lists; + public class Aggregation extends AggregationEntry { + private final List<AggregationEntry> children = Lists.newArrayList(); + public Aggregation(final ObjectType metadata) { super(metadata); } + public Aggregation(final ObjectType metadata, final Aggregation parent) { + super(metadata, parent); + } + + protected Aggregation add(final AggregationEntry child) { + children.add(child); + return this; + } + } diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java index 6f29b923d92a073eb596aa3e483afff81948ef1a..7bfcc7a4be83cad86759427055e83a355df4d3d5 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java @@ -2,13 +2,25 @@ import info.textgrid.namespaces.metadata.core._2010.ObjectType; +import com.google.common.collect.ImmutableList; public class AggregationEntry { private final ObjectType metadata; - public AggregationEntry(final ObjectType metadata) { + protected final ImmutableList<Aggregation> path; + + protected AggregationEntry(final ObjectType metadata) { + this.metadata = metadata; + path = ImmutableList.of(); + } + + protected AggregationEntry(final ObjectType metadata, + final Aggregation parent) { + path = ImmutableList.<Aggregation> builder().addAll(parent.path) + .add(parent).build(); this.metadata = metadata; + parent.add(this); } public ObjectType getMetadata() { diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java index 943bd952fc1486b0b9e144043663cc23082eddd2..b5c850c2384d7e50823a9e9cd3b9e47d34d58ca3 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java @@ -9,7 +9,7 @@ public class AggregationTreeFactory extends AggregationTreeWalker { - private final Deque<AggregationEntry> stack = Lists.newLinkedList(); + private final Deque<Aggregation> stack = Lists.newLinkedList(); private final Aggregation root; protected AggregationTreeFactory(final ObjectType root) { @@ -21,15 +21,20 @@ protected AggregationTreeFactory(final ObjectType root) { @Override protected boolean walk(final ObjectType object, final boolean again) { - // TODO Auto-generated method stub - return super.walk(object, again); + if (super.walk(object, again)) + return true; // Aggregation already handled via #walkAggregation + else { + new AggregationEntry(object, stack.peek()); + return true; + } } @Override protected void walkAggregation(final ObjectType aggregation, final boolean again) { - // TODO Auto-generated method stub + stack.push(new Aggregation(aggregation, stack.peek())); super.walkAggregation(aggregation, again); + stack.pop(); } }