package com.github.devnied.emvnfccard.utils;

import org.apache.commons.lang3.StringUtils;

import com.github.devnied.emvnfccard.R;
import com.github.devnied.emvnfccard.enums.EMVCardTypeEnum;

/**
 * Utils class for card
 * 
 * @author Millau Julien
 * 
 */
public final class CardUtils {

	/**
	 * Method used to format card number
	 * 
	 * @param pCardNumber
	 *            card number to display
	 * @param pType
	 *            card type
	 * 
	 * @return the card number formated
	 */
	public static String formatCardNumber(final String pCardNumber, final EMVCardTypeEnum pType) {
		String ret = StringUtils.EMPTY;
		if (StringUtils.isNotBlank(pCardNumber)) {
			// format amex
			if (pType != null && pType == EMVCardTypeEnum.AMERICAN_EXPRESS) {
				ret = StringUtils.deleteWhitespace(pCardNumber).replaceFirst("\\d{4}", "$0 ").replaceFirst("\\d{6}", "$0 ")
						.replaceFirst("\\d{5}", "$0").trim();
			} else {
				ret = StringUtils.deleteWhitespace(pCardNumber).replaceAll("\\d{4}", "$0 ").trim();
			}
		}
		return ret;
	}

	/**
	 * Method used to get the resource Id for card type
	 * 
	 * @param pEnum
	 *            card enum
	 * @return resource id
	 */
	public static int getResourceIdCardType(final EMVCardTypeEnum pEnum) {
		int ret = 0;
		switch (pEnum) {
		case AMERICAN_EXPRESS:
			ret = R.drawable.amex;
			break;
		case MASTER_CARD1:
		case MASTER_CARD2:
			ret = R.drawable.mastercard;
			break;
		case VISA:
			ret = R.drawable.visa;
			break;
		default:
			break;

		}
		return ret;
	}

	/**
	 * Private constructor
	 */
	private CardUtils() {
	}

}

@@ -1004,20 +1004,63 @@
 );%0A%09%09%09%7D%0A
+%09%09%7D else %7B%0A%09%09%09ret = %220000 0000 0000 0000%22;%0A
 %09%09%7D%0A
-
 %09%09return
@@ -1290,16 +1290,40 @@
 et = 0;%0A
+%09%09if (pEnum != null) %7B%0A%09
 %09%09switch
@@ -1333,16 +1333,17 @@
 Enum) %7B%0A
+%09
 %09%09case A
@@ -1359,16 +1359,17 @@
 XPRESS:%0A
+%09
 %09%09%09ret =
@@ -1385,31 +1385,33 @@
 le.amex;%0A%09%09%09
+%09
 break;%0A
+%09
 %09%09case MASTE
@@ -1419,16 +1419,17 @@
 _CARD1:%0A
+%09
 %09%09case M
@@ -1440,24 +1440,25 @@
 R_CARD2:%0A%09%09%09
+%09
 ret = R.draw
@@ -1474,16 +1474,17 @@
 ercard;%0A
+%09
 %09%09%09break
@@ -1487,16 +1487,17 @@
 reak;%0A%09%09
+%09
 case VIS
@@ -1499,16 +1499,17 @@
 e VISA:%0A
+%09
 %09%09%09ret =
@@ -1526,16 +1526,17 @@
 e.visa;%0A
+%09
 %09%09%09break
@@ -1539,16 +1539,17 @@
 reak;%0A%09%09
+%09
 default:
@@ -1549,16 +1549,17 @@
 efault:%0A
+%09
 %09%09%09break
@@ -1561,16 +1561,21 @@
 break;%0A%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09re

Fix NPE error