diff --git a/api/src/main/java/org/fairdatapipeline/api/Object_component_read.java b/api/src/main/java/org/fairdatapipeline/api/Object_component_read.java index 62a7b55..ca21c2b 100644 --- a/api/src/main/java/org/fairdatapipeline/api/Object_component_read.java +++ b/api/src/main/java/org/fairdatapipeline/api/Object_component_read.java @@ -7,6 +7,8 @@ import org.fairdatapipeline.distribution.ImmutableDistribution; import org.fairdatapipeline.estimate.ImmutableEstimate; import org.fairdatapipeline.file.CleanableFileChannel; +import org.fairdatapipeline.parameters.ImmutableBoolList; +import org.fairdatapipeline.parameters.ImmutableStringList; import org.fairdatapipeline.parameters.ReadComponent; import org.fairdatapipeline.samples.ImmutableSamples; @@ -109,6 +111,45 @@ public Distribution readDistribution() { return ((ImmutableDistribution) data).getDistribution(); } + /** + * read the Bools that were stored as this component in a TOML file. + * + * @return the Bools object + */ + public List readBools() { + ReadComponent data; + try (CleanableFileChannel fileChannel = this.getFileChannel()) { + data = this.dp.coderun.parameterDataReader.read(fileChannel, this.component_name); + } catch (IOException e) { + throw (new RuntimeException("readBools() -- IOException trying to read from file.", e)); + } + if (!(data instanceof ImmutableBoolList)) { + throw (new RuntimeException( + "readBools() -- this objComponent (" + this.component_name + ") is not a BoolList")); + } + return ((ImmutableBoolList) data).getBools(); + } + + /** + * read the Strings that were stored as this component in a TOML file. + * + * @return the Strings object + */ + public List readStrings() { + ReadComponent data; + try (CleanableFileChannel fileChannel = this.getFileChannel()) { + data = this.dp.coderun.parameterDataReader.read(fileChannel, this.component_name); + } catch (IOException e) { + throw (new RuntimeException("readStrings() -- IOException trying to read from file.", e)); + } + if (!(data instanceof ImmutableStringList)) { + throw (new RuntimeException( + "readStrings() -- this objComponent (" + this.component_name + ") is not a StringList")); + } + return ((ImmutableStringList) data).getStrings(); + } + + /** * read the Samples that were stored as this component in a TOML file. * diff --git a/api/src/main/java/org/fairdatapipeline/api/Object_component_write.java b/api/src/main/java/org/fairdatapipeline/api/Object_component_write.java index 327068f..4b988d0 100644 --- a/api/src/main/java/org/fairdatapipeline/api/Object_component_write.java +++ b/api/src/main/java/org/fairdatapipeline/api/Object_component_write.java @@ -7,6 +7,8 @@ import org.fairdatapipeline.distribution.Distribution; import org.fairdatapipeline.estimate.ImmutableEstimate; import org.fairdatapipeline.file.CleanableFileChannel; +import org.fairdatapipeline.parameters.BoolList; +import org.fairdatapipeline.parameters.StringList; import org.fairdatapipeline.samples.Samples; /** @@ -96,6 +98,42 @@ public void writeDistribution(Distribution distribution) { this.been_used = true; } + /** + * write a BoolList, as this named component in the data product. + * + * @param bools the Booleans to write + */ + public void writeBools(BoolList bools) { + if (this.been_used) { + throw (new RuntimeException("obj component already written")); + } + try (CleanableFileChannel fileChannel = this.getFileChannel()) { + this.dp.coderun.parameterDataWriter.write(fileChannel, this.component_name, bools); + } catch (IOException e) { + throw (new RuntimeException( + "writeBools() -- IOException trying to write to file.", e)); + } + this.been_used = true; + } + + /** + * write a BoolList, as this named component in the data product. + * + * @param strings the Strings to write + */ + public void writeStrings(StringList strings) { + if (this.been_used) { + throw (new RuntimeException("obj component already written")); + } + try (CleanableFileChannel fileChannel = this.getFileChannel()) { + this.dp.coderun.parameterDataWriter.write(fileChannel, this.component_name, strings); + } catch (IOException e) { + throw (new RuntimeException( + "writeStrings() -- IOException trying to write to file.", e)); + } + this.been_used = true; + } + /** * write Samples, as this named component in the data product. *