Skip to content

Commit

Permalink
Criteria. Type inside Consumer<C> should not terminate in root (R)
Browse files Browse the repository at this point in the history
```java
S none(Consumer<C> consumer) {
// ....
}
```
  • Loading branch information
asereda-gs committed Apr 13, 2019
1 parent 52ca000 commit bbd7315
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
Expand Up @@ -5,7 +5,7 @@
import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;


public class CollectionCriteria<R extends DocumentCriteria<R>, V, S extends ValueCriteria<R, V>> { public class CollectionCriteria<R extends DocumentCriteria<R>, V, S extends ValueCriteria<R, V>, C extends ValueCriteria<?, V>> {


private final CriteriaContext<R> context; private final CriteriaContext<R> context;


Expand All @@ -17,15 +17,23 @@ public S all() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


public R all(Consumer<C> consumer) {
throw new UnsupportedOperationException();
}

public S none() { public S none() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


public R none(Consumer<C> consumer) {
throw new UnsupportedOperationException();
}

public S any() { public S any() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


public R any(Consumer<S> consumer) { public R any(Consumer<C> consumer) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


Expand Down
Expand Up @@ -18,33 +18,33 @@


import org.immutables.criteria.DocumentCriteria; import org.immutables.criteria.DocumentCriteria;


import java.util.Optional; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;


/** /**
* Criteria for optional attributes. * Criteria for optional attributes.
*/ */
// TODO do we really need to extend from ObjectCriteria ? perhaps just make ValueCriteria ? public class OptionalCriteria<R extends DocumentCriteria<R>, V, S extends ValueCriteria<R, V>, C extends ValueCriteria<?, V>> {
public class OptionalCriteria<R extends DocumentCriteria<R>, V, S extends ValueCriteria<R, V>> extends ObjectCriteria<R, Optional<V>> {
private final CriteriaContext<R> context;


public OptionalCriteria(CriteriaContext<R> context) { public OptionalCriteria(CriteriaContext<R> context) {
super(context); this.context = Objects.requireNonNull(context, "context");
} }


public R isPresent() { public R isPresent() {
return create(e -> Expressions.call(Operators.IS_PRESENT, e)); return context.create(e -> Expressions.call(Operators.IS_PRESENT, e));
} }


public R isAbsent() { public R isAbsent() {
return create(e -> Expressions.call(Operators.IS_ABSENT, e)); return context.create(e -> Expressions.call(Operators.IS_ABSENT, e));
} }


public S value() { public S value() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


public R value(Consumer<S> consumer) { public R value(Consumer<C> consumer) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


Expand Down
@@ -1,6 +1,7 @@
package org.immutables.criteria; package org.immutables.criteria;


import org.immutables.criteria.constraints.DebugExpressionVisitor; import org.immutables.criteria.constraints.DebugExpressionVisitor;
import org.immutables.criteria.constraints.StringCriteria;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;


Expand Down Expand Up @@ -63,10 +64,11 @@ public void empty() {
public void collection() { public void collection() {
PersonCriteria.create() PersonCriteria.create()
.friends.any().nickName.isNotEmpty() .friends.any().nickName.isNotEmpty()
.friends.any(f -> f.nickName.isNotEmpty()) .friends.any(f -> f.nickName.isNotEmpty().nickName.isEmpty())
.aliases.none().contains("foo") .aliases.none().contains("foo")
.lastName.value().isNotEmpty() .lastName.value().isNotEmpty()
.lastName.value().hasSize(2) .lastName.value().hasSize(2)
.lastName.value(StringCriteria::isNotEmpty)
.bestFriend.nickName.startsWith("foo"); .bestFriend.nickName.startsWith("foo");
} }


Expand Down
Expand Up @@ -133,17 +133,17 @@ BooleanCriteria<R>
StringCriteria<R> StringCriteria<R>
[else if a.optionalType] [else if a.optionalType]
[if a.hasSimpleScalarElementType] [if a.hasSimpleScalarElementType]
OptionalCriteria<R, [a.wrappedElementType], [scalarElementCriteria a]> OptionalCriteria<R, [a.wrappedElementType], [scalarElementCriteria a 'R'], [scalarElementCriteria a '?']>
[else if a.hasCriteria] [else if a.hasCriteria]
OptionalCriteria<R, [a.wrappedElementType], [a.unwrappedElementType]Criteria<R>> OptionalCriteria<R, [a.wrappedElementType], [a.unwrappedElementType]Criteria<R>, [a.unwrappedElementType]Criteria.Start>
[/if] [/if]
[else if a.comparable] [else if a.comparable]
ComparableCriteria<R, [a.wrappedElementType]> ComparableCriteria<R, [a.wrappedElementType]>
[else if a.collectionType] [else if a.collectionType]
[if a.hasSimpleScalarElementType] [if a.hasSimpleScalarElementType]
CollectionCriteria<R, [a.wrappedElementType], [scalarElementCriteria a]> CollectionCriteria<R, [a.wrappedElementType], [scalarElementCriteria a 'R'], [scalarElementCriteria a '?']>
[else if a.hasCriteria] [else if a.hasCriteria]
CollectionCriteria<R, [a.wrappedElementType], [a.unwrappedElementType]Criteria<R>> CollectionCriteria<R, [a.wrappedElementType], [a.unwrappedElementType]Criteria<R>, [a.unwrappedElementType]Criteria.Start>
[else] [else]
[output.error]Can't create criteria for collection [a.name] [a.unwrappedElementType][/output.error] [output.error]Can't create criteria for collection [a.name] [a.unwrappedElementType][/output.error]
[/if] [/if]
Expand All @@ -155,15 +155,15 @@ StringCriteria<R>
[/output.trim][/template] [/output.trim][/template]


[-- Used to create criteria for T (eg. List<T>) when T is a scalar / comparable--] [-- Used to create criteria for T (eg. List<T>) when T is a scalar / comparable--]
[template scalarElementCriteria Attribute a][output.trim] [template scalarElementCriteria Attribute a String elementName][output.trim]
[if a.unwrappedElementType eq 'boolean'] [if a.unwrappedElementType eq 'boolean']
BooleanCriteria<R> BooleanCriteria<[elementName]>
[else if a.unwrappedElementType eq 'java.lang.String'] [else if a.unwrappedElementType eq 'java.lang.String']
StringCriteria<R> StringCriteria<[elementName]>
[else if a.isMaybeComparableKey] [else if a.isMaybeComparableKey]
ComparableCriteria<R, [a.wrappedElementType]> ComparableCriteria<[elementName], [a.wrappedElementType]>
[else] [else]
[output.error]unexpected type [a.name] [a.unwrappedElementType], not a simple one[/output.error] [output.error]unexpected type [a.name] [a.unwrappedElementType]<[elementName]>, not a simple one[/output.error]
[/if] [/if]
[/output.trim][/template] [/output.trim][/template]


Expand Down

0 comments on commit bbd7315

Please sign in to comment.