mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Utility to use text for numbers from 0 to 20.
This commit is contained in:
parent
8b2c3e75e1
commit
012ea4e02d
1 changed files with 33 additions and 1 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import mage.Constants;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
|
@ -43,13 +44,16 @@ import mage.game.permanent.token.Token;
|
|||
import mage.util.functions.CopyFunction;
|
||||
import mage.util.functions.CopyTokenFunction;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class CardUtil {
|
||||
|
||||
static String numberStrings[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
|
||||
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", "twenty"};
|
||||
|
||||
/**
|
||||
* Checks whether two cards share card types.
|
||||
*
|
||||
|
@ -317,4 +321,32 @@ public class CardUtil {
|
|||
|
||||
return permanent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer number to string
|
||||
* Numbers > 20 will be returned as digits
|
||||
*
|
||||
*/
|
||||
public static String numberToText(int number) {
|
||||
if (number >= 0 && number < 21) {
|
||||
return numberStrings[number];
|
||||
}
|
||||
return Integer.toString(number);
|
||||
}
|
||||
|
||||
public static String numberToText(String number) {
|
||||
if (checkNumeric(number)) {
|
||||
return numberToText(Integer.parseInt(number));
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
public static boolean checkNumeric(String s) {
|
||||
for(int i = 0; i < s.length(); i++) {
|
||||
if(!Character.isDigit(s.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue