0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

なんだかんだ使うUtil

Posted at

##ライブラリ自作

備忘録です
コメントとか適当なのであしからず

Utils.java
package util;

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.Arrays;

public class Utils {
	
	/** --------------- Object --------------- */
	
	/** nullでなけれは真 */
	public static final Predicate<Object> nonNull = v -> v != null;
	
	/** nullなら空文字に変換 */
	public static final Function<Object, String> nullToEmpty = v -> v == null ? "" : v.toString();
	
	/** nullと数値でないものなら0に変換 */
	public static final Function<Object, Integer> nullToZero = v -> {
		try {
			return v == null ? 0 : Integer.parseInt(v.toString());
		} catch (NumberFormatException e) {
			return 0;
		}
	};
	
	/** --------------- String --------------- */
	
	/** nullでも空文字でもなければ真 */
	public static final Predicate<String> nonEmpty = v -> v != null && !v.equals("");
	
	/** nullでも空文字でも空白文字(半角全角)でもなければ真 */
	public static final Predicate<String> nonBlank = v -> v != null && !v.equals("")
			&& Arrays.stream(v.split("")).anyMatch(x -> !x.equals(" ") && !x.equals(" "));
}

日付型とかはもうほんと勘弁してほしいだいっきらい

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?