-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResponseProcessor State-setting and Tests #178
ResponseProcessor State-setting and Tests #178
Conversation
… `Provenancable` through provenance and back to check whether the produce the same object. Wrote a `structuralEquals` method on `ConfigurationData` to support it.
…anged the logic in `FieldResponseProcessor.postConfig` to properly handle all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the if/else in FieldResponseProcessor could be simplified a bit, otherwise it looks fine.
* and provenance representations are the same using {@link ConfigurationData#structuralEquals(List, List, String, String)}. | ||
* @param itm The object whose equality is to be tested | ||
*/ | ||
public static <P extends ObjectProvenance, C extends Configurable & Provenancable<P>> void testConfigurableRoundtrip(C itm) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type bound could be P extends ConfiguredObjectProvenance
. Not sure if that limits its functionality any.
@@ -76,6 +81,27 @@ public static ImmutableFeatureMap mkFeatureMap(String... features) { | |||
return ex; | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two blank lines between this function and the surrounding ones, but we usually have one.
defaultValues = defaultValues == null ? Collections.nCopies(fieldNames.size(), defaultValue) : defaultValues; | ||
} else if (fieldNames != null) { // multiple fields | ||
if (defaultValues != null && defaultValues.size() == fieldNames.size()) { // check first for multiple defaults | ||
// this is the default case, nothing needs to be done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we flip this around to get rid of the empty if branch? Maybe start with defaultValues == null && defaultValue == null
to catch the else case, and then have the defaultValue != null
one, then defaultValues != null && defaultValues.size() != fieldNames.size()
to throw PropertyException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the empty branch is awkward, but I think this is actually a fair bit more readable. An earlier version without it had bugs that were almost impossible to identify by inspection. However, I'll write documentation for this method and its partner in BinaryResponseProcessor
that explains the logic at play.
`BinaryResponseProcessor` to be more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a minor point on the docs.
@@ -75,34 +75,42 @@ | |||
@ConfigurableName | |||
private String configName; | |||
|
|||
/** | |||
* We support specifying field names and default values both singly through {@link #fieldName} and {@link #positiveResponse} | |||
* and in a list through {@link #fieldNames} and {@link #positiveResponses}. Canonically all internal logic is driven by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird javadoc comment as it's more for our benefit as developers rather than anyone who uses this class, so it probably should be a regular comment at the start of this method then it doesn't show up in the docs.
@@ -60,35 +60,41 @@ | |||
@ConfigurableName | |||
private String configName; | |||
|
|||
/** | |||
* We support specifying field names and default values both singly through {@link #fieldName} and {@link #defaultValue} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before. At minimum this should not that the method should not be called by user code as the default postConfig javadoc says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Fixes an issue with multi-field
ResponseProcessor
instances where the end state of the produced object, when written back out into a configured/provenanced form and re-instantiated wouldn't be processed correctly by thepostConfig
call. Also added a test for roundtripping any type that is bothConfigurable
andProvenanceable
through their respective forms to ensure that the end results are structurally equal according to theConfigurationData#structuralEquals
method in OLCUT, and tests for this behavior inBinaryResponseProcessor
andFieldResponseProcessor
.This change depends on OLCUT v5.2.0, and thus requires updating Tribuo to depend on that OLCUT version.