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

Validate config entry type #870

Merged
merged 3 commits into from Mar 17, 2018
Merged

Validate config entry type #870

merged 3 commits into from Mar 17, 2018

Conversation

@aramperes
Copy link
Member

@aramperes aramperes commented Mar 17, 2018

Adds a predicate for value class type.

Fixes #869

aramperes added 2 commits Mar 17, 2018
Replaced numerical predicates to Number (in order to support Double, Float, etc.)
@aramperes aramperes requested a review from mastercoms Mar 17, 2018
/**
* Checks if the value is a valid port number.
*/
static final Predicate<Integer> PORT = POSITIVE.and((number) -> number < 49151);
static final Predicate<Integer> PORT = typeCheck(Integer.class)
.and(POSITIVE).and((number) -> number < 49151);

This comment has been minimized.

@Pr0methean

Pr0methean Mar 17, 2018
Contributor

Should be <= 49151: the first dynamic port is 49152.

* @return the predicate
*/
static <T> Predicate<T> typeCheck(Class<T> expected) {
return expected::isInstance;

This comment has been minimized.

@Pr0methean

Pr0methean Mar 17, 2018
Contributor

Inline this into lines 405-585, e.g. DISABLE_GENERATION("world.disable-generation", false, Boolean::isInstance)

This comment has been minimized.

@aramperes

aramperes Mar 17, 2018
Author Member

Wouldn't work in predicate chains, e.g. Validators.typeCheck(Integer.class).and(Validators.ABSOLUTE)

I'll replace it for single validators, i.e. String.class::isInstance

@mastercoms mastercoms merged commit f9b046a into dev Mar 17, 2018
2 checks passed
2 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details
@mastercoms mastercoms deleted the validate-config-types branch Mar 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants