Help us understand the problem. What is going on with this article?

StringUtils.isBlank作ってみた

つくってみました

StringUtils.java
package practice;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * Utils
 * 
 * @author me
 *
 */
public class Practice {

    /** String list */
    private static final List<String> INTEGER_LIST = Arrays.asList(null, "", " ", "0", "1", "2");

    /**
     * main
     * 
     * @param args
     */
    public static void main(String[] args) {
        try {
            run(INTEGER_LIST);
        } catch (NumberFormatException e) {
            echo.accept("・ω・v");
        }
    }

    /**
     * run
     * 
     * @param list <E> The element type of this list.
     * @throws NumberFormatException if conversion to numeric number is impossible.
     */
    private static void run(List<String> list) throws NumberFormatException {
        echo.accept(list.stream().filter(notBlank).map(Integer::parseInt)
                .collect(Collectors.summingInt(Integer::intValue)));
    }

    /** not null */
    static Predicate<String> notNull = v -> Optional.ofNullable(v).isPresent();
    /** not space */
    static Predicate<String> notSpace = v -> !v.equals(" ");
    /** StringUtils.isBlank */
    static Predicate<String> notBlank = v -> notNull.test(v) && !v.isEmpty()
            && Arrays.asList(v.split("")).stream().anyMatch(notSpace);
    /** out */
    static Consumer<Object> echo = v -> System.out.println(v);

}

結果

3

結論

なんだかんだ自作できてもライブラリ追加した方が早くね問題
けど数行で終わるならいちいち使わなくてもいいですよね
ぶっちゃけもうjava既存のでなんでも解決できそうな気分になってます
最近apache.common.lang全然見ない...

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした