Skip to content

Commit

Permalink
Add constructor to allow Entity creation w/o Metamorph
Browse files Browse the repository at this point in the history
Keep old constructor for compatibility; use Supplier since the
receiver might not be set when the Entity object is created
  • Loading branch information
fsteeg committed May 8, 2020
1 parent d55e8c1 commit 95b24fe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions metamorph/src/main/java/org/metafacture/metamorph/Entity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013, 2014 Deutsche Nationalbibliothek
* Copyright 2013, 2020 Deutsche Nationalbibliothek and others
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

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

private final Metamorph metamorph;
private final Supplier<StreamReceiver> receiver;

private NamedValueSource nameSource;
private String currentName;

public Entity(final Metamorph metamorph) {
this.metamorph = metamorph;
this.receiver = () -> metamorph.getStreamReceiver();
}

public Entity(final StreamReceiver receiver) {
this.receiver = () -> receiver;
}

public void setNameSource(final NamedValueSource source) {
Expand All @@ -60,7 +65,7 @@ protected void emit() {
final Entity parent = (Entity) namedValueReceiver;
parent.receive(null, null, this, getRecordCount(), getEntityCount());
} else {
write(metamorph.getStreamReceiver());
write(receiver.get());
}
}

Expand Down

0 comments on commit 95b24fe

Please sign in to comment.