package org.mifosng.platform.api.data;

import java.io.Serializable;

public class CurrencyData implements Serializable {

	private String code;
	private String name;
	private int decimalPlaces;
	private String displaySymbol;
	private String nameCode;

	public CurrencyData() {
		//
	}

	public CurrencyData(final String code, final String name, final int decimalPlaces, String displaySymbol, String nameCode) {
		this.code = code;
		this.name = name;
		this.decimalPlaces = decimalPlaces;
		this.displaySymbol = displaySymbol;
		this.nameCode = nameCode;
	}
	
	@Override
	public boolean equals(Object obj) {
		CurrencyData currencyData = (CurrencyData) obj;
		return currencyData.code.equals(this.code);
	}
	
	@Override
	public int hashCode() {
		return this.code.hashCode();
	}
	
	public String getDisplayLabel() {
		
		StringBuilder builder = new StringBuilder(this.name).append(' ');
		
		if (this.displaySymbol != null && !"".equalsIgnoreCase(displaySymbol.trim())) {
			builder.append('(').append(this.displaySymbol).append(')');
		} else {
			builder.append('[').append(this.code).append(']');
		}
		
		return builder.toString();
	}

	public String getName() {
		return this.name;
	}

	public String getCode() {
		return this.code;
	}

	public int getDecimalPlaces() {
		return this.decimalPlaces;
	}

	public void setCode(final String code) {
		this.code = code;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public void setDecimalPlaces(final int decimalPlaces) {
		this.decimalPlaces = decimalPlaces;
	}

	public String getDisplaySymbol() {
		return displaySymbol;
	}

	public void setDisplaySymbol(String displaySymbol) {
		this.displaySymbol = displaySymbol;
	}

	public String getNameCode() {
		return nameCode;
	}

	public void setNameCode(String nameCode) {
		this.nameCode = nameCode;
	}
}
@@ -121,24 +121,30 @@
 %7B%0A%0A%09private 
+final 
 String code;
@@ -145,32 +145,38 @@
  code;%0A%09private 
+final 
 String name;%0A%09pr
@@ -181,16 +181,22 @@
 private 
+final 
 int deci
@@ -211,24 +211,30 @@
 s;%0A%09private 
+final 
 String displ
@@ -252,16 +252,22 @@
 private 
+final 
 String n
@@ -279,41 +279,43 @@
 de;%0A
-%0A
 %09p
-ublic CurrencyData() %7B%0A%09%09//%0A%09%7D
+rivate final String displayLabel;
 %0A%0A%09p
@@ -581,16 +581,62 @@
 meCode;%0A
+%09%09this.displayLabel = generateDisplayLabel();%0A
 %09%7D%0A%09%0A%09@O
@@ -855,21 +855,22 @@
 %0A%09%7D%0A%09%0A%09p
-ublic
+rivate
  String 
@@ -867,25 +867,30 @@
 te String ge
-t
+nerate
 DisplayLabel
@@ -1236,19 +1236,19 @@
 ring get
-Nam
+Cod
 e() %7B%0A%09%09
@@ -1254,24 +1254,19 @@
 %09return 
-this.nam
+cod
 e;%0A%09%7D%0A%0A%09
@@ -1274,35 +1274,35 @@
 ublic String get
-Cod
+Nam
 e() %7B%0A%09%09return t
@@ -1300,24 +1300,19 @@
 %09return 
-this.cod
+nam
 e;%0A%09%7D%0A%0A%09
@@ -1356,547 +1356,201 @@
 urn 
-this.decimalPlaces;%0A%09%7D%0A%0A%09public void setCode(final String code) %7B%0A%09%09this.code = code;%0A%09%7D%0A%0A%09public void setName(final String name) %7B%0A%09%09this.name = name;%0A%09%7D%0A%0A%09public void setDecimalPlaces(final int decimalPlaces) %7B%0A%09%09this.decimalPlaces = decimalPlaces;%0A%09%7D%0A%0A%09public String getDisplaySymbol() %7B%0A%09%09return displaySymbol;%0A%09%7D%0A%0A%09public void setDisplaySymbol(String displaySymbol) %7B%0A%09%09this.displaySymbol = displaySymbol;%0A%09%7D%0A%0A%09public String getNameCode() %7B%0A%09%09return nameCode;%0A%09%7D%0A%0A%09public void setNameCode(String nameCode) %7B%0A%09%09this.nameCode = nameCode
+decimalPlaces;%0A%09%7D%0A%0A%09public String getDisplaySymbol() %7B%0A%09%09return displaySymbol;%0A%09%7D%0A%0A%09public String getNameCode() %7B%0A%09%09return nameCode;%0A%09%7D%0A%0A%09public String getDisplayLabel() %7B%0A%09%09return displayLabel
 ;%0A%09%7D

make displayLabel a field on currency data rather than a getter so json deserialization works correctly.