122 lines
3.7 KiB
Java
122 lines
3.7 KiB
Java
/*
|
|
* Copyright (c) 2019 LINE Corporation. All rights reserved.
|
|
* LINE Corporation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
|
*/
|
|
|
|
package com.myoa.engineering.crawl.ppomppu.processor.util;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
|
|
/**
|
|
* NumberUtils
|
|
*
|
|
* @author Shin Woo-jin (lp12254@linecorp.com)
|
|
* @since 2019-10-28
|
|
*/
|
|
public final class ObjectUtil {
|
|
|
|
private ObjectUtil() {
|
|
}
|
|
|
|
/**
|
|
* Check if given object is null.
|
|
* <code>
|
|
* e == object == > false e == null == > true
|
|
* </code>
|
|
*
|
|
* @param e Target object
|
|
* @param <E> Unfixed specific type. If you want restrict specific interface, Copy and extend qualifier.
|
|
* @return Is null given object?
|
|
*/
|
|
public static <E> boolean isNullObject(final E e) {
|
|
return e == null;
|
|
}
|
|
|
|
/**
|
|
* Check if given object is not null.
|
|
* <code>
|
|
* e == object == > false e == null == > true
|
|
* </code>
|
|
*
|
|
* @param e Target object
|
|
* @param <E> Unfixed specific type. If you want restrict specific interface, Copy and extend qualifier.
|
|
* @return Is not null given object?
|
|
*/
|
|
public static <E> boolean isNotEmpty(final E e) {
|
|
return !isNullObject(e);
|
|
}
|
|
|
|
/**
|
|
* Check if there are any null object in given objects.
|
|
* <code>
|
|
* args == object = > false args == object, object = > false args == null, null, object = > true args
|
|
* == null = > true args == null, null = > true
|
|
* </code>
|
|
*
|
|
* @param args Want to check objects that have null.
|
|
* @return Is there objects array has null?
|
|
*/
|
|
public static boolean hasNullObject(Object... args) {
|
|
return Arrays.stream(args).anyMatch(ObjectUtil::isNullObject);
|
|
}
|
|
|
|
/**
|
|
* Check given objects are not empty.
|
|
* <code>
|
|
* args == object = > true args == object, object = > true args == null, null, object = > false args
|
|
* == null = > false args == null, null = > false
|
|
* </code>
|
|
*
|
|
* @param args Want to check objects that have null.
|
|
* @return Is there objects array has null?
|
|
*/
|
|
public static boolean hasAllObject(Object... args) {
|
|
return Arrays.stream(args).noneMatch(ObjectUtil::isNullObject);
|
|
}
|
|
|
|
/**
|
|
* Check if there are all null object in given objects.
|
|
* <code>
|
|
* args == object = > false args == object, object = > false args == null, null, object = > false args
|
|
* == null = > true args == null, null = > true
|
|
* </code>
|
|
*
|
|
* @param args Want to check objects that have null.
|
|
* @return Is there null all of given objects?
|
|
*/
|
|
public static boolean hasAllNullObjects(final Object... args) {
|
|
return Arrays.stream(args).allMatch(ObjectUtil::isNullObject);
|
|
}
|
|
|
|
/**
|
|
* Check if given collection object is null or empty collecton.
|
|
* <code>
|
|
* e == null = > true e == emptyCollection = > true e == hasElement = > false
|
|
* </code>
|
|
*
|
|
* @param e e is must be Collection object
|
|
* @param <E> E is must be extended Collection Class
|
|
* @return boolean. given collection is null or empty?
|
|
*/
|
|
public static <E extends Collection<?>> boolean isNullOrEmptyCollection(final E e) {
|
|
return e == null || e.isEmpty();
|
|
}
|
|
|
|
/**
|
|
* Get collection's size. Even it pointed null
|
|
*
|
|
* @param e e is must be Collection object
|
|
* @param <E> E is must be extended Collection Class
|
|
* @return integer value. given collection's size.
|
|
*/
|
|
public static <E extends Collection<?>> int getCollectionSize(final E e) {
|
|
if (isNullOrEmptyCollection(e)) {
|
|
return 0;
|
|
}
|
|
|
|
return e.size();
|
|
}
|
|
|
|
}
|