001/* 002 * Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.util; 017 018import com.mybatisflex.core.query.CloneSupport; 019 020import java.util.Objects; 021 022public class ObjectUtil { 023 024 private ObjectUtil() { 025 } 026 027 public static Object cloneObject(Object value) { 028 // ROLE.ROLE_ID.ge(USER.USER_ID) 029 if (value instanceof CloneSupport) { 030 return ((CloneSupport<?>) value).clone(); 031 } 032 return value; 033 } 034 035 public static <T extends CloneSupport<T>> T clone(T value) { 036 if (value != null) { 037 return value.clone(); 038 } 039 return null; 040 } 041 042 public static <T> T requireNonNullElse(T t1, T t2) { 043 return t1 == null ? t2 : t1; 044 } 045 046 public static boolean areNotNull(Object... objs) { 047 for (Object obj : objs) { 048 if (obj == null) { 049 return false; 050 } 051 } 052 return true; 053 } 054 055 public static boolean areNull(Object... objs) { 056 for (Object obj : objs) { 057 if (obj != null) { 058 return false; 059 } 060 } 061 return true; 062 } 063 064 public static boolean equalsAny(Object a, Object... others) { 065 if (others == null || others.length == 0) { 066 throw new IllegalArgumentException("others must not be null or empty."); 067 } 068 for (Object other : others) { 069 if (Objects.equals(a, other)) { 070 return true; 071 } 072 } 073 return false; 074 } 075 076}