swim.recon.ReconFormWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-recon Show documentation
Show all versions of swim-recon Show documentation
Uploads all artifacts belonging to configuration ':swim-recon:archives'
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.recon;
import swim.codec.Output;
import swim.codec.Writer;
import swim.structure.Form;
import swim.structure.Item;
import swim.structure.Value;
final class ReconFormWriter extends Writer {
final ReconWriter- recon;
final Form
form;
final T object;
final Writer, ?> part;
ReconFormWriter(ReconWriter- recon, Form
form, T object, Writer, ?> part) {
this.recon = recon;
this.form = form;
this.object = object;
this.part = part;
}
ReconFormWriter(ReconWriter- recon, Form
form) {
this(recon, form, null, null);
}
@Override
public Writer feed(T object) {
return new ReconFormWriter(recon, form, object, null);
}
@Override
public Writer pull(Output> output) {
return write(output, this.recon, this.form, this.object, this.part);
}
static Writer write(Output> output, ReconWriter- recon,
Form
form, T object, Writer, ?> part) {
if (output == null) {
return done();
}
if (part == null) {
final Value value = form.mold(object).toValue();
part = recon.writeValue(value, output);
} else {
part = part.pull(output);
}
if (part.isDone()) {
return done(object);
} else if (part.isError()) {
return part.asError();
}
return new ReconFormWriter(recon, form, object, part);
}
static Writer write(Output output, ReconWriter- recon,
Form
form, T object) {
return write(output, recon, form, object, null);
}
}