Skip to content
Snippets Groups Projects
Commit 42fa4469 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Basic tree factory

parent b0e9a9fe
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,25 @@ ...@@ -2,10 +2,25 @@
import info.textgrid.namespaces.metadata.core._2010.ObjectType; import info.textgrid.namespaces.metadata.core._2010.ObjectType;
import java.util.List;
import com.google.common.collect.Lists;
public class Aggregation extends AggregationEntry { public class Aggregation extends AggregationEntry {
private final List<AggregationEntry> children = Lists.newArrayList();
public Aggregation(final ObjectType metadata) { public Aggregation(final ObjectType metadata) {
super(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;
}
} }
...@@ -2,13 +2,25 @@ ...@@ -2,13 +2,25 @@
import info.textgrid.namespaces.metadata.core._2010.ObjectType; import info.textgrid.namespaces.metadata.core._2010.ObjectType;
import com.google.common.collect.ImmutableList;
public class AggregationEntry { public class AggregationEntry {
private final ObjectType metadata; 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; this.metadata = metadata;
parent.add(this);
} }
public ObjectType getMetadata() { public ObjectType getMetadata() {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
public class AggregationTreeFactory extends AggregationTreeWalker { public class AggregationTreeFactory extends AggregationTreeWalker {
private final Deque<AggregationEntry> stack = Lists.newLinkedList(); private final Deque<Aggregation> stack = Lists.newLinkedList();
private final Aggregation root; private final Aggregation root;
protected AggregationTreeFactory(final ObjectType root) { protected AggregationTreeFactory(final ObjectType root) {
...@@ -21,15 +21,20 @@ protected AggregationTreeFactory(final ObjectType root) { ...@@ -21,15 +21,20 @@ protected AggregationTreeFactory(final ObjectType root) {
@Override @Override
protected boolean walk(final ObjectType object, final boolean again) { protected boolean walk(final ObjectType object, final boolean again) {
// TODO Auto-generated method stub if (super.walk(object, again))
return super.walk(object, again); return true; // Aggregation already handled via #walkAggregation
else {
new AggregationEntry(object, stack.peek());
return true;
}
} }
@Override @Override
protected void walkAggregation(final ObjectType aggregation, protected void walkAggregation(final ObjectType aggregation,
final boolean again) { final boolean again) {
// TODO Auto-generated method stub stack.push(new Aggregation(aggregation, stack.peek()));
super.walkAggregation(aggregation, again); super.walkAggregation(aggregation, again);
stack.pop();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment