From 9094f76de2d57e3246f7dd1e2554bb30333ee1bd Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 30 Mar 2018 19:53:20 +0800 Subject: [PATCH] =?UTF-8?q?Utility=E5=A2=9E=E5=8A=A0contains=E7=B3=BB?= =?UTF-8?q?=E5=88=97=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/util/Utility.java | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index bd1ee4c71..a8a8670a9 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -566,6 +566,56 @@ public final class Utility { return false; } + /** + * 判断指定值是否包含指定的数组中,包含返回true + * + * @param values 集合 + * @param value 单值 + * + * @return boolean + */ + public static boolean contains(int[] values, int value) { + if (values == null) return false; + for (int v : values) { + if (v == value) return true; + } + return false; + } + + /** + * 判断指定值是否包含指定的数组中,包含返回true + * + * @param values 集合 + * @param value 单值 + * + * @return boolean + */ + public static boolean contains(long[] values, long value) { + if (values == null) return false; + for (long v : values) { + if (v == value) return true; + } + return false; + } + + /** + * 判断指定值是否包含指定的数组中,包含返回true + * + * @param 泛型 + * @param values 集合 + * @param value 单值 + * + * @return boolean + */ + public static boolean contains(T[] values, T value) { + if (values == null) return false; + for (T v : values) { + if (v == null && value == null) return true; + if (v != null && v.equals(value)) return true; + } + return false; + } + /** * 删除掉字符串数组中包含指定的字符串 *