ShoppingCrawler/processor/src/main/java/com/myoa/engineering/crawl/ppomppu/processor/util/ObjectUtil.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 == &gt; false e == null == &gt; 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 == &gt; false e == null == &gt; 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 = &gt; false args == object, object = &gt; false args == null, null, object = &gt; true args
* == null = &gt; true args == null, null = &gt; 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 = &gt; true args == object, object = &gt; true args == null, null, object = &gt; false args
* == null = &gt; false args == null, null = &gt; 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 = &gt; false args == object, object = &gt; false args == null, null, object = &gt; false args
* == null = &gt; true args == null, null = &gt; 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 = &gt; true e == emptyCollection = &gt; true e == hasElement = &gt; 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();
}
}