package org.forpdi.planning.attribute.types.enums;

import java.text.NumberFormat;
import java.util.Locale;

import org.forpdi.planning.attribute.AttributeInstance;

import com.ibm.icu.text.DecimalFormat;

public enum FormatValue {

	PERCENTAGE(1, "porcentagem"), NUMERIC(2, "numérico"), MONETARY(3, "monetário"), HOURS(4, "horas"), DAYS(5,
			"dias"), MOTHS(6, "meses");

	public static FormatValue forAttributeInstance(AttributeInstance attr) {
		if (attr == null) {
			return FormatValue.NUMERIC;
		} else {
			switch (attr.getValue()) {
			case "Porcentagem":
				return FormatValue.PERCENTAGE;
			case "Numérico":
				return FormatValue.NUMERIC;
			case "Monetário(R$)":
				return FormatValue.MONETARY;
			case "Horas":
				return FormatValue.HOURS;
			case "Dias":
				return FormatValue.DAYS;
			case "Meses":
				return FormatValue.MOTHS;
			default:
				return FormatValue.NUMERIC;
			}
		}
	}

	private int value;
	private String name;
	Locale ptBr = new Locale("pt", "BR");
	NumberFormat moedaFormat = NumberFormat.getCurrencyInstance(ptBr);
	DecimalFormat decimalFormatDbl = new DecimalFormat("#,##0.00");
	DecimalFormat decimalFormatInt = new DecimalFormat("#,##0");

	private FormatValue(int value, String name) {
		this.value = value;
		this.name = name;
	}

	public int getValue() {
		return value;
	}

	public String getName() {
		return name;
	}

	public String format(String value) {
		if (value != null) {
			switch (this.value) {
			case 1:
				return decimalFormatDbl.format(Double.valueOf(value)) + "%";
			case 2:
				return decimalFormatDbl.format(Double.valueOf(value));
			case 3:
				return moedaFormat.format(Double.valueOf(value));
			case 4:
				return decimalFormatInt.format(Double.valueOf(value)) + " hrs";
			case 5:
				if (Double.valueOf(value) > 1) {
					return decimalFormatInt.format(Double.valueOf(value)) + " dias";
				} else {
					return decimalFormatInt.format(Double.valueOf(value)) + " dia";
				}
			case 6:
				return decimalFormatInt.format(Double.valueOf(value)) + " meses";
			default:
				return "valor inválido";
			}
		} else {
			return new String("");
		}
	}
}

@@ -1351,32 +1351,34 @@
 eturn name;%0A%09%7D%0A%0A
+%09%0A
 %09public String f
@@ -1422,16 +1422,84 @@
 null) %7B%0A
+%09%09%09Double valor = value.length() == 0 ? 0.0d:Double.valueOf(value);%0A
 %09%09%09switc
@@ -1561,37 +1561,22 @@
 .format(
-Double.valueOf(value)
+ valor
 ) + %22%25%22;
@@ -1622,37 +1622,21 @@
 .format(
-Double.valueOf(value)
+valor
 );%0A%09%09%09ca
@@ -1671,37 +1671,21 @@
 .format(
-Double.valueOf(value)
+valor
 );%0A%09%09%09ca
@@ -1725,37 +1725,21 @@
 .format(
-Double.valueOf(value)
+valor
 ) + %22 hr
@@ -1761,37 +1761,21 @@
 %09%09%09%09if (
-Double.valueOf(value)
+valor
  %3E 1) %7B%0A
@@ -1810,37 +1810,21 @@
 .format(
-Double.valueOf(value)
+valor
 ) + %22 di
@@ -1877,37 +1877,21 @@
 .format(
-Double.valueOf(value)
+valor
 ) + %22 di
@@ -1946,37 +1946,21 @@
 .format(
-Double.valueOf(value)
+valor
 ) + %22 me

Update FormatValue.java