瀏覽代碼

boolean工具

wangwei 5 年之前
父節點
當前提交
972dd4d810
共有 1 個文件被更改,包括 54 次插入0 次删除
  1. 54 0
      src/main/java/cn/com/qmth/examcloud/commons/util/BooleanUtil.java

+ 54 - 0
src/main/java/cn/com/qmth/examcloud/commons/util/BooleanUtil.java

@@ -0,0 +1,54 @@
+package cn.com.qmth.examcloud.commons.util;
+
+import org.apache.commons.lang3.BooleanUtils;
+
+/**
+ * boolean 工具
+ *
+ * @author WANGWEI
+ * @date 2019年10月21日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class BooleanUtil {
+
+	/**
+	 * 统计true的数量
+	 *
+	 * @author WANGWEI
+	 * @param values
+	 * @return
+	 */
+	public static int countTrue(boolean... values) {
+		if (null == values) {
+			return 0;
+		}
+		int count = 0;
+		for (boolean b : values) {
+			if (BooleanUtils.isTrue(b)) {
+				count++;
+			}
+		}
+		return count;
+	}
+
+	/**
+	 * 统计false的数量
+	 *
+	 * @author WANGWEI
+	 * @param values
+	 * @return
+	 */
+	public static int countFalse(boolean... values) {
+		if (null == values) {
+			return 0;
+		}
+		int count = 0;
+		for (boolean b : values) {
+			if (BooleanUtils.isFalse(b)) {
+				count++;
+			}
+		}
+		return count;
+	}
+
+}