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

Java7 backport #1

Merged
merged 6 commits into from
Jan 20, 2017
Merged

Java7 backport #1

merged 6 commits into from
Jan 20, 2017

Conversation

fpeter8
Copy link

@fpeter8 fpeter8 commented Jan 18, 2017

This pull request is the java 7 backport of the original library. There should be no functionality change at all.

During review please be on the lookout for

  • code formatting differences
  • heavy and unnecessary use of the Guava library (if writing the loops by hand would be more compact / readable)
  • wrong imports

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8a4c343 on java7-backport into ** on master**.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8a4c343 on java7-backport into ** on master**.

IntStream.range(0, arr.length())
.mapToObj(arr::get)
.forEach(possibleValues::add);
Set<Object> possibleValues = Sets.newHashSet(arr);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fpeter8 I think this is wrong

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... okay maybe not, it implements the Iterable in newer versions, but I'm not sure which version does the project use

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an iterable, but I'll make it more explicit


@Override
default void accept(final URI t) {
public final void accept(final URI t) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably shouldn't be final

CombinedSchema.oneOf(asList(BooleanSchema.INSTANCE));
CombinedSchema.allOf(Lists.<Schema>newArrayList(BooleanSchema.INSTANCE));
CombinedSchema.anyOf(Lists.<Schema>newArrayList(BooleanSchema.INSTANCE));
CombinedSchema.oneOf(Lists.<Schema>newArrayList(BooleanSchema.INSTANCE));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this change?

Copy link
Author

@fpeter8 fpeter8 Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java7 needs explicit type declarations, so the staticly imported method wasn't good. I just prefer Lists to Arrays, so I used that.

.patternProperty("^string.*", new StringSchema())
.addPropertySchema("boolProp", BooleanSchema.INSTANCE)
.addRequiredProperty("boolProp");
Supplier<ObjectSchema.Builder> newBuilder = new Supplier<ObjectSchema.Builder>() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Callable existed in 7)

@Override
public ValidationException apply(ValidationException exc) {
ValidationException exception = exc.prepend(copyOfI);
failureCollector.accept(exception);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifPresent -> should be called only if "exception" isn't null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole transform block of Optional runs only if the exception isn't null. I know it's counter-intuitive, if you want I can move it.

* @return all messages
*/
public List<String> getAllMessages() {
if (causingExceptions.isEmpty()) {
return Collections.singletonList(getMessage());
} else {
return getAllMessages(causingExceptions).stream().collect(Collectors.toList());
return Lists.newArrayList(Iterables.concat(getAllMessages(causingExceptions)));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concat?

@@ -64,13 +64,14 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.4.RC0</version>
<version>8.2.0.v20160908</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version 9 uses Java8

return new Consumer<T>() {
@Override
public void accept(T t) {
this.accept(t);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinite recursion IMO

nbali
nbali previously requested changes Jan 18, 2017
Copy link

@nbali nbali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

......

@fpeter8 fpeter8 requested a review from nbali January 19, 2017 14:12
@fpeter8 fpeter8 removed their assignment Jan 19, 2017
@coveralls
Copy link

coveralls commented Jan 19, 2017

Coverage Status

Changes Unknown when pulling e3029d0 on java7-backport into ** on master**.

return Optional.absent();
}

private static final class RValAddConsumer extends Consumer<ValidationException> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use just a list instead of this custom consumer

.orElseThrow(
() -> new ValidationException(this, String.format("%s is not a valid enum value",
subject), "enum"));
FluentIterable.from(possibleValues)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    boolean match = false;
    for(Object val: possibleValues) {
        if(ObjectComparator.deepEquals(val, subject)) {
            match = true;
            break;
        }
    }
    if(!match) {
        throw new ValidationException(EnumSchema.this,
                String.format("%s is not a valid enum value", subject), "enum");
    }

It's oldschool, but easier to understand

.flatMap(cause -> getAllMessages(cause.getCausingExceptions()).stream())
.collect(Collectors.toList()));
List<String> messages = Lists.newArrayList();
FluentIterable.from(causes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for(ValidationException cause: causes) {
if(cause.getCausingExceptions().isEmpty()) {
messages.add(cause.getMessage());
} else {
messages.addAll(getAllMessages(cause.getCausingExceptions()));
}
}

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0115567 on java7-backport into ** on master**.

1 similar comment
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 0115567 on java7-backport into ** on master**.

@coveralls
Copy link

coveralls commented Jan 19, 2017

Coverage Status

Changes Unknown when pulling b431bcd on java7-backport into ** on master**.

@coveralls
Copy link

coveralls commented Jan 19, 2017

Coverage Status

Changes Unknown when pulling 5fdd6f3 on java7-backport into ** on master**.

@coveralls
Copy link

coveralls commented Jan 19, 2017

Coverage Status

Changes Unknown when pulling e737557 on java7-backport into ** on master**.

@fpeter8 fpeter8 merged commit 8c22c93 into master Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants