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
StringUtils.defaultString(arg) | |
.chars() | |
.collect(CharSummaryStatistics::new, | |
CharSummaryStatistics::accept, | |
CharSummaryStatistics::combine); |
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
public class CharSummaryStatistics { | |
private long totalDigits = 0; | |
private long totalUppercaseChars = 0; | |
private long totalLowercaseChars = 0; | |
private long totalInvalidChars = 0; | |
public CharSummaryStatistics() { | |
} |
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
var totalDigits = 0; | |
var totalUppercaseChars = 0; | |
var totalLowercaseChars = 0; | |
var totalInvalidChars = 0; | |
for (final char current : string.toCharArray()) { | |
if (Character.isDigit(current)) { | |
totalDigits += 1; | |
} else if (Character.isUpperCase(current)) { | |
totalUppercaseChars += 1; | |
} else if (Character.isLowerCase(current)) { |
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
final var totalDigits = string.chars() | |
.filter(Character::isDigit) | |
.count(); | |
final var totalUppercaseChars = string.chars() | |
.filter(Character::isUpperCase) | |
.count(); | |
final var totalLowercaseChars = string.chars() | |
.filter(Character::isLowerCase) |
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
final Set<Integer> uniqueNumbers = List.of(1, 2, 2, 3, 4, 5, 5).stream().collect(Collectors.toSet()); |
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
private Iterable<Object[]> convert(Iterable<Object[]> data) { | |
List<Object[]> parameters = new ArrayList<>(); | |
for (Object[] args : data) { | |
Object[] params = new Object[args.length]; | |
for (int i = 0; i < args.length; i++) { | |
Object param; | |
Class<?> parameterClazz = method.getMethod() | |
.getParameterTypes()[i]; | |
if (parameterClazz.equals(String.class)) { | |
param = buildString(args[i]); |
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
private Iterable<Object[]> convert(final Iterable<Object[]> data) { | |
List<Object[]> parameters = new ArrayList<>(); | |
for (Object[] args : data) { | |
Object[] params = new Object[args.length]; | |
for (int i = 0; i < args.length; i++) { | |
final Class<?> parameterClazz = method.getMethod() | |
.getParameterTypes()[i]; | |
params[i] = convertParameter(args[i], parameterClazz); | |
} | |
parameters.add(params); |
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
private final Map<Class<?>, ParameterConverter<Object, ?>> convertersByClass = new ImmutableMap.Builder<Class<?>, ParameterConverter<Object, ?>>() | |
.put(String.class, this::buildString) | |
.put(Integer.TYPE, this::buildPrimitiveInt) | |
.put(Integer.class, this::buildInteger) | |
.put(Long.TYPE, this::buildPrimitiveLong) | |
.put(Long.class, this::buildLong) | |
.put(Boolean.TYPE, this::buildPrimitiveBoolean) | |
.put(Boolean.class, this::buildBoolean) | |
.put(Short.TYPE, this::buildPrimitiveShort) | |
.put(Short.class, this::buildShort) |
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
@FunctionalInterface | |
public interface ParameterConverter<T, R> { | |
R convert(T t); | |
} |
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
public class ListOfPairsJava9 { | |
public static void main(String[] args) { | |
final Map<String, List<String>> values = new HashMap<>(); | |
values.put("a", Arrays.asList("1", "2", "3")); | |
values.put("b", Arrays.asList("4", "5", "6")); | |
values.put("c", Collections.singletonList("7")); | |
final List<Map.Entry<String, String>> result = values | |
.entrySet() |
NewerOlder