Skip to content
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

Feature/negate op in environment expressions #519

Merged

Conversation

barspi
Copy link
Contributor

@barspi barspi commented Apr 13, 2023

(this is equivalent to PR #518 done against current master)

Add support for environment expressions with a negate/NOT operator, such as ${!server.enabled:false}

Extensive test cases have been added.

Some observations:

  • The operator only makes sense for "booleanish" values. That means, the property is resolved to true/false/yes/no, or their string equivalents (upper/lowercase)).
  • All booleanish values, when negated are resolved down into "true"/"false" or true/false (depending on the retrieval through Environment.get() or SimpleConfiguration#getBoolean())
  • When using SimpleConfiguration#getBoolean() an undefined property always resolves as false (original behavior).
    Therefore, when negating an undefined property, getBoolean() will return true
  • When an undefined property is used in an expression with a default, the default is always honored (i.e. a getBoolean() on ${!__undefined__:true} will return true, and if calling Environment.get() directly, it will return the string "true")
  • A negate operator will never negate the default value. It's assumed that the intended meaning of a default is to be used literally (when the property in question couldn't be resolved)

@ar ar merged commit 019048f into jpos:next Apr 14, 2023
2 of 3 checks passed
@barspi barspi deleted the next-feature/negate-op-in-environment-expressions branch April 14, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants