Skip to content

Commit 95b24fe

Browse files
committed
Add constructor to allow Entity creation w/o Metamorph
Keep old constructor for compatibility; use Supplier since the receiver might not be set when the Entity object is created
1 parent d55e8c1 commit 95b24fe

File tree

1 file changed

+9
-4
lines changed
  • metamorph/src/main/java/org/metafacture/metamorph

1 file changed

+9
-4
lines changed

metamorph/src/main/java/org/metafacture/metamorph/Entity.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013, 2014 Deutsche Nationalbibliothek
2+
* Copyright 2013, 2020 Deutsche Nationalbibliothek and others
33
*
44
* Licensed under the Apache License, Version 2.0 the "License";
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.HashSet;
2020
import java.util.List;
2121
import java.util.Set;
22+
import java.util.function.Supplier;
2223

2324
import org.metafacture.commons.StringUtil;
2425
import org.metafacture.flowcontrol.StreamBuffer;
@@ -38,13 +39,17 @@ public final class Entity extends AbstractFlushingCollect {
3839
private final Set<NamedValueSource> sourcesLeft = new HashSet<NamedValueSource>();
3940
private final StreamBuffer buffer = new StreamBuffer();
4041

41-
private final Metamorph metamorph;
42+
private final Supplier<StreamReceiver> receiver;
4243

4344
private NamedValueSource nameSource;
4445
private String currentName;
4546

4647
public Entity(final Metamorph metamorph) {
47-
this.metamorph = metamorph;
48+
this.receiver = () -> metamorph.getStreamReceiver();
49+
}
50+
51+
public Entity(final StreamReceiver receiver) {
52+
this.receiver = () -> receiver;
4853
}
4954

5055
public void setNameSource(final NamedValueSource source) {
@@ -60,7 +65,7 @@ protected void emit() {
6065
final Entity parent = (Entity) namedValueReceiver;
6166
parent.receive(null, null, this, getRecordCount(), getEntityCount());
6267
} else {
63-
write(metamorph.getStreamReceiver());
68+
write(receiver.get());
6469
}
6570
}
6671

0 commit comments

Comments
 (0)