Skip to content

Commit

Permalink
made new Strings and Bools available in obj_comp_read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
B0SKAMP committed Feb 29, 2024
1 parent b3a4c07 commit 76fc7c7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Boolean> 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<String> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 76fc7c7

Please sign in to comment.