Last active
August 29, 2015 14:20
-
-
Save danhyun/318a15ec52a535739ff0 to your computer and use it in GitHub Desktop.
jdk8 refactor
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
// before | |
private String getExpandValuesFromSet (Set<String> valueSet, Boolean surroundValueWithQuotes) { | |
StringBuilder expansionValuesString = new StringBuilder(" ("); | |
Iterator<String> valueIterator = valueSet.iterator(); | |
if (valueIterator.hasNext()) { | |
String value = valueIterator.next(); | |
if (surroundValueWithQuotes) { | |
expansionValuesString.append("'" + value + "'"); | |
} else { | |
expansionValuesString.append(value); | |
} | |
while (valueIterator.hasNext()) { | |
String nextValue = valueIterator.next(); | |
expansionValuesString.append(","); | |
if (surroundValueWithQuotes) { | |
expansionValuesString.append("'" + nextValue + "'"); | |
} else { | |
expansionValuesString.append(nextValue); | |
} | |
} | |
} | |
expansionValuesString.append(")"); | |
return expansionValuesString.toString(); | |
} | |
// after | |
private StringJoiner getExpandValuesFromSet (Set<String> valueSet, Boolean surroundValueWithQuotes) { | |
StringJoiner clause = new StringJoiner(", ", " (", ") "); | |
Function<String, String> surrounder = | |
getQuoteSurrounder(surroundValueWithQuotes); | |
valueSet.stream() | |
.map(cleaner) | |
.map(surrounder) | |
.forEach(clause::add); | |
return clause; | |
} | |
private Function<String, String> getQuoteSurrounder(boolean surround) { | |
return surround ? | |
s -> "'" + s + "'" : | |
Function.identity(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment