From e43f81487295ba76f95ce1d1494339be2dc5d9cf Mon Sep 17 00:00:00 2001
From: Redkale <8730487+redkale@users.noreply.github.com>
Date: Wed, 18 Sep 2019 11:22:28 +0800
Subject: [PATCH] =?UTF-8?q?Utility=E5=A2=9E=E5=8A=A0containsMatch=E3=80=81?=
=?UTF-8?q?removeMatch=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 | 117 ++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java
index 7267a45d5..59bbacf02 100644
--- a/src/org/redkale/util/Utility.java
+++ b/src/org/redkale/util/Utility.java
@@ -920,6 +920,123 @@ public final class Utility {
return false;
}
+ /**
+ * 将指定的short元素是否数组中完全包含,重复元素的次数也要相同
+ * 例如:
+ * containsMatch(new short[]{1, 2, 2, 3, 3, 3}, 1, 2, 3, 3) = true
+ * containsMatch(new short[]{1, 2, 2, 3, 3, 3}, 1, 1, 2, 3, 3) = false
+ *
+ * @param array 原数组
+ * @param items short[]
+ *
+ * @return 是否完全包含
+ */
+ public static boolean containsMatch(final short[] array, final short... items) {
+ if (array == null && items == null) return true;
+ if (array == null && items.length == 0) return true;
+ if (array == null) return false;
+ if (items == null || items.length == 0) return true;
+ if (array.length == 0 && items.length == 0) return true;
+ if (array.length < items.length) return false;
+
+ short[] subs = array;
+ for (short item : items) {
+ if (!contains(subs, item)) return false;
+ short[] newsubs = new short[subs.length - 1];
+ int k = 0;
+ boolean done = false;
+ for (short v : subs) {
+ if (done) {
+ newsubs[k++] = v;
+ } else if (v == item) {
+ done = true;
+ } else {
+ newsubs[k++] = v;
+ }
+ }
+ subs = newsubs;
+ }
+ return true;
+ }
+
+ /**
+ * 将指定的int元素是否数组中完全包含,重复元素的次数也要相同
+ * 例如:
+ * containsMatch(new int[]{1, 2, 2, 3, 3, 3}, 1, 2, 3, 3) = true
+ * containsMatch(new int[]{1, 2, 2, 3, 3, 3}, 1, 1, 2, 3, 3) = false
+ *
+ * @param array 原数组
+ * @param items int[]
+ *
+ * @return 是否完全包含
+ */
+ public static boolean containsMatch(final int[] array, final int... items) {
+ if (array == null && items == null) return true;
+ if (array == null && items.length == 0) return true;
+ if (array == null) return false;
+ if (items == null || items.length == 0) return true;
+ if (array.length == 0 && items.length == 0) return true;
+ if (array.length < items.length) return false;
+
+ int[] subs = array;
+ for (int item : items) {
+ if (!contains(subs, item)) return false;
+ int[] newsubs = new int[subs.length - 1];
+ int k = 0;
+ boolean done = false;
+ for (int v : subs) {
+ if (done) {
+ newsubs[k++] = v;
+ } else if (v == item) {
+ done = true;
+ } else {
+ newsubs[k++] = v;
+ }
+ }
+ subs = newsubs;
+ }
+ return true;
+ }
+
+ /**
+ * 将指定的long元素是否数组中完全包含,重复元素的次数也要相同
+ * 例如:
+ * containsMatch(new long[]{1, 2, 2, 3, 3, 3}, 1, 2, 3, 3) = true
+ * containsMatch(new long[]{1, 2, 2, 3, 3, 3}, 1, 1, 2, 3, 3) = false
+ *
+ * @param array 原数组
+ * @param items long[]
+ *
+ * @return 是否完全包含
+ */
+ public static boolean containsMatch(final long[] array, final long... items) {
+ if (array == null && items == null) return true;
+ if (array == null && items.length == 0) return true;
+ if (array == null) return false;
+ if (items == null || items.length == 0) return true;
+ if (array.length == 0 && items.length == 0) return true;
+ if (array.length < items.length) return false;
+
+ long[] subs = array;
+ for (long item : items) {
+ if (!contains(subs, item)) return false;
+ long[] newsubs = new long[subs.length - 1];
+ int k = 0;
+ boolean done = false;
+ for (long v : subs) {
+ if (done) {
+ newsubs[k++] = v;
+ } else if (v == item) {
+ done = true;
+ } else {
+ newsubs[k++] = v;
+ }
+ }
+ subs = newsubs;
+ }
+ return true;
+ }
+
/**
* 删除掉字符串数组中包含指定的字符串
*