-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds logic to wrap string values in quotes in query (#13)
Signed-off-by: Sean Sundberg <[email protected]>
- Loading branch information
Showing
2 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/ibm/openpages/support/util/query/QueryValueFormatters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.ibm.openpages.support.util.query; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class QueryValueFormatters { | ||
public static String formatListValue(Object inValue) { | ||
final Collection<?> value = (inValue instanceof Collection<?>) ? (Collection<?>) inValue : Collections.singletonList(inValue); | ||
|
||
final String valueList = value | ||
.stream() | ||
.map(QueryValueFormatters::formatSimpleValue) | ||
.collect(Collectors.joining(",")); | ||
|
||
return "[" + valueList + "]"; | ||
} | ||
|
||
public static String formatSimpleValue(Object current) { | ||
return (current instanceof Number) ? current.toString() : "'" + current.toString() + "'" | ||
} | ||
} |