This is an automated email from the ASF dual-hosted git repository.
martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-components.git
The following commit(s) were added to refs/heads/master by this push:
new 3838c84 Adding string based method signature for convenience
3838c84 is described below
commit 3838c848f21d18213fcc9cef34ee505f6e51312f
Author: Martin Stockhammer <[email protected]>
AuthorDate: Sun May 30 10:27:02 2021 +0200
Adding string based method signature for convenience
---
.../archiva/components/rest/util/QueryHelper.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git
a/rest-util/src/main/java/org/apache/archiva/components/rest/util/QueryHelper.java
b/rest-util/src/main/java/org/apache/archiva/components/rest/util/QueryHelper.java
index 5ad6c67..61f98b6 100644
---
a/rest-util/src/main/java/org/apache/archiva/components/rest/util/QueryHelper.java
+++
b/rest-util/src/main/java/org/apache/archiva/components/rest/util/QueryHelper.java
@@ -90,7 +90,7 @@ public class QueryHelper<T>
* any other values.
* @param attributeName the name of the attribute
* @param keyExtractor the extractor to use for getting the attribute value
- * @param <U>
+ * @param <U> the type that is to be compared by the comparator
*/
public <U extends Comparable<? super U>> void addNullsafeFieldComparator(
String attributeName, Function<? super T, U> keyExtractor) {
orderMap.put( attributeName, Comparator.comparing( keyExtractor,
Comparator.nullsLast( Comparator.naturalOrder( ) ) ) );
@@ -136,7 +136,7 @@ public class QueryHelper<T>
{
if ( ascending )
{
- return orderBy.stream( ).map( ( String name ) ->
getAttributeComparator( name ) ).filter( Objects::nonNull )
+ return orderBy.stream( ).map( this::getAttributeComparator
).filter( Objects::nonNull )
.reduce( Comparator::thenComparing )
.orElseThrow( () -> new IllegalArgumentException( "No
attribute ordering found" ) );
}
@@ -150,6 +150,17 @@ public class QueryHelper<T>
}
/**
+ * Returns the ordering for the given attributes and the given order
string.
+ * The order is considered as ascending if the string is not equal to
'desc'
+ * @param orderBy the list of attributes to order by
+ * @param order the order string, either 'asc' for ascending or 'desc' for
descending
+ * @return the combined comparator
+ */
+ public Comparator<T> getComparator(List<String> orderBy, String order) {
+ return getComparator( orderBy, this.isAscending( order ) );
+ }
+
+ /**
* Returns a query filter for a specific attribute and query token.
* @param attributeName the attribute name to filter for.
* @param queryToken the search token.
@@ -188,10 +199,10 @@ public class QueryHelper<T>
else
{
return Arrays.stream( defaultSearchAttributes )
- .map( att -> getAttributeQueryFilter( att, s )
).reduce( Predicate::or ).get( );
+ .map( att -> getAttributeQueryFilter( att, s )
).reduce( Predicate::or ).orElseThrow( () -> new RuntimeException( "Fatal
error. No filter predicate found." ));
}
}
- ).reduce( Predicate::or ).get( );
+ ).reduce( Predicate::or ).orElseThrow( () -> new RuntimeException(
"Fatal error. No filter predicate found." ) );
}
/**