-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Changes Unknown when pulling 8a4c343 on java7-backport into ** on master**. |
1 similar comment
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); |
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.
@fpeter8 I think this is wrong
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.
... okay maybe not, it implements the Iterable in newer versions, but I'm not sure which version does the project use
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.
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) { |
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.
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)); |
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.
any particular reason for this change?
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.
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>() { |
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.
(Callable existed in 7)
@Override | ||
public ValidationException apply(ValidationException exc) { | ||
ValidationException exception = exc.prepend(copyOfI); | ||
failureCollector.accept(exception); |
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.
ifPresent -> should be called only if "exception" isn't null
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.
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))); |
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.
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> |
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.
why?
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.
version 9 uses Java8
return new Consumer<T>() { | ||
@Override | ||
public void accept(T t) { | ||
this.accept(t); |
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.
infinite recursion IMO
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.
......
Changes Unknown when pulling e3029d0 on java7-backport into ** on master**. |
return Optional.absent(); | ||
} | ||
|
||
private static final class RValAddConsumer extends Consumer<ValidationException> { |
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.
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) |
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.
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) |
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.
for(ValidationException cause: causes) {
if(cause.getCausingExceptions().isEmpty()) {
messages.add(cause.getMessage());
} else {
messages.addAll(getAllMessages(cause.getCausingExceptions()));
}
}
Changes Unknown when pulling 0115567 on java7-backport into ** on master**. |
1 similar comment
Changes Unknown when pulling 0115567 on java7-backport into ** on master**. |
Changes Unknown when pulling b431bcd on java7-backport into ** on master**. |
Changes Unknown when pulling 5fdd6f3 on java7-backport into ** on master**. |
5fdd6f3
to
e737557
Compare
Changes Unknown when pulling e737557 on java7-backport into ** on master**. |
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