Util to use for some reason

Library self-made

It is a memorandum I don't know if it's a comment or something

Utils.java


package util;

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

public class Utils {
	
	/** --------------- Object --------------- */
	
	/**True if not null*/
	public static final Predicate<Object> nonNull = v -> v != null;
	
	/**Convert to empty string if null*/
	public static final Function<Object, String> nullToEmpty = v -> v == null ? "" : v.toString();
	
	/**Convert to 0 if null and non-numeric*/
	public static final Function<Object, Integer> nullToZero = v -> {
		try {
			return v == null ? 0 : Integer.parseInt(v.toString());
		} catch (NumberFormatException e) {
			return 0;
		}
	};
	
	/** --------------- String --------------- */
	
	/**True if neither null nor empty string*/
	public static final Predicate<String> nonEmpty = v -> v != null && !v.equals("");
	
	/**Whitespace character, null or empty string(Half-width and full-width)If not true*/
	public static final Predicate<String> nonBlank = v -> v != null && !v.equals("")
			&& Arrays.stream(v.split("")).anyMatch(x -> !x.equals(" ") && !x.equals(" "));
}

I really want you to forgive me for the date type.

Recommended Posts

Util to use for some reason
How to use binding.pry for view files
[Ruby] How to use slice for beginners
How to use an array for HashMap keys
[Rails] How to use Gem'rails-i18n' for Japanese support
How to use an array for a TreeMap key
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
PATH to use docker-slim
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to use Truth (assertion library for Java / Android)
[How to use label]
How to use identity
[For those who create portfolios] How to use font-awesome-rails
[Note] Challenge to develop Android application for business use
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use GitHub for super beginners (team development)
How to use Map
How to use SAS tokens for Azure Event hubs (Java)
[Must-see for apprentice java engineer] How to use Stream API
Use Hikari CP for pooling connections to Amazon Aurora clusters
[For those who create portfolios] How to use chart kick
How to use Font Awesome icon for ul and li
Procedures for passing RealmObject to Fragment and how to use Parceler
[Java] How to use Map
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
How to use @Builder (Lombok)
[Swift] How to use UserDefaults
How to use Swift UIScrollView
How to use Big Decimal
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use Java Map
Rbenv command to use Ruby
Ruby: How to use cookies
How to use dependent :: destroy
How to use Eclipse Debug_Shell
How to use Apache POI