| 1 |
/* |
|---|
| 2 |
* Copyright(c) 2006-2007 the Spark project. |
|---|
| 3 |
* |
|---|
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 5 |
* you may not use this file except in compliance with the License. |
|---|
| 6 |
* You may obtain a copy of the License at |
|---|
| 7 |
* |
|---|
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 9 |
* |
|---|
| 10 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|---|
| 13 |
* either express or implied. See the License for the specific language |
|---|
| 14 |
* governing permissions and limitations under the License. |
|---|
| 15 |
*/ |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
package org.libspark.utils |
|---|
| 19 |
{ |
|---|
| 20 |
|
|---|
| 21 |
/** |
|---|
| 22 |
* Boolean のためのユーティリティクラスです |
|---|
| 23 |
*/ |
|---|
| 24 |
public class BooleanUtil |
|---|
| 25 |
{ |
|---|
| 26 |
/** |
|---|
| 27 |
* true 判定が n 個以上であるかを判定します |
|---|
| 28 |
* @param n 比較対象となる数 |
|---|
| 29 |
* @param ...params |
|---|
| 30 |
* @return |
|---|
| 31 |
*/ |
|---|
| 32 |
public static function more(n:uint, ...params):Boolean |
|---|
| 33 |
{ |
|---|
| 34 |
var len:uint = params.length; |
|---|
| 35 |
var count:uint = 0; |
|---|
| 36 |
for (var i:uint = 0; i < len;i++ ) { |
|---|
| 37 |
if (params[i]) { |
|---|
| 38 |
count++; |
|---|
| 39 |
if (count == n) return true; |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
return false; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
/** |
|---|
| 46 |
* true 判定が n 個かどうかを判定します |
|---|
| 47 |
* @param n 比較対象となる数 |
|---|
| 48 |
* @param ...params |
|---|
| 49 |
* @return |
|---|
| 50 |
*/ |
|---|
| 51 |
public static function equal(n:uint, ...params):Boolean |
|---|
| 52 |
{ |
|---|
| 53 |
var len:uint = params.length; |
|---|
| 54 |
var count:uint = 0; |
|---|
| 55 |
for (var i:uint = 0; i < len;i++ ) { |
|---|
| 56 |
if (params[i]) count++; |
|---|
| 57 |
} |
|---|
| 58 |
if (count == n) return true; |
|---|
| 59 |
return false; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
/** |
|---|
| 63 |
* true 判定が n 個未満であるかを判定します |
|---|
| 64 |
* @param n 比較対象となる数 |
|---|
| 65 |
* @param ...params |
|---|
| 66 |
* @return |
|---|
| 67 |
*/ |
|---|
| 68 |
public static function fewer(n:uint, ...params):Boolean |
|---|
| 69 |
{ |
|---|
| 70 |
var len:uint = params.length; |
|---|
| 71 |
var count:uint = 0; |
|---|
| 72 |
for (var i:uint = 0; i < len;i++ ) { |
|---|
| 73 |
if (params[i]) { |
|---|
| 74 |
count++; |
|---|
| 75 |
if (count == n) return false; |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
if (count < n) return true; |
|---|
| 79 |
return false; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
} |
|---|