com.baidu.unbiz.fluentvalidator.util
类 ArrayUtil

java.lang.Object
  继承者 com.baidu.unbiz.fluentvalidator.util.ArrayUtil

public class ArrayUtil
extends Object

数组工具类

作者:
zhangxu

构造方法摘要
ArrayUtil()
           
 
方法摘要
static
<T> boolean
hasIntersection(T[] from, T[] target)
          验证数组是否有交集

Class

static
<T> boolean
isEmpty(T[] arrary)
          检查数组是否为null或空数组[]
static
<T> T[]
toWrapperIfPrimitive(Object froms)
          将数组转变成数组,如果fromsnull,则返回null
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

ArrayUtil

public ArrayUtil()
方法详细信息

isEmpty

public static <T> boolean isEmpty(T[] arrary)
检查数组是否为null或空数组[]

 ArrayUtil.isEmpty(null)              = true
 ArrayUtil.isEmpty(new int[0])        = true
 ArrayUtil.isEmpty(new int[10])       = false
 

参数:
array - 要检查的数组
返回:
如果不为空, 则返回true

hasIntersection

public static <T> boolean hasIntersection(T[] from,
                                          T[] target)
验证数组是否有交集

 Class[] from = new Class[] {};
 Class[] target = new Class[] {};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(true));

 from = new Class[] {String.class};
 target = new Class[] {};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(true));

 from = new Class[] {};
 target = new Class[] {String.class};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(false));

 from = new Class[] {String.class};
 target = new Class[] {String.class};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(true));

 from = new Class[] {String.class, Object.class};
 target = new Class[] {String.class};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(true));

 from = new Class[] {String.class};
 target = new Class[] {String.class, Object.class};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(true));

 from = new Class[] {Integer.class};
 target = new Class[] {Object.class};
 assertThat(ArrayUtil.hasIntersection(from, target), Matchers.is(false));

 

参数:
from - 基础数组
target - 目标数组,看是否存在于基础数组中
返回:
如果有交集, 则返回true

toWrapperIfPrimitive

public static <T> T[] toWrapperIfPrimitive(Object froms)
将数组转变成数组,如果fromsnull,则返回null
如果froms不为基本类型数组,则返回null

参数:
froms - 基本类型数组
返回:
包装类数组,如果fromsnull,则返回null
如果froms不为基本类型数组,则返回null


Copyright © 2015–2016 neoremind. All rights reserved.