Boolean to and from String

A published Boolean field must be translated to an internal String type field. The business service foundation provides three ValueObject methods to assist you with this transformation. Because these methods are in the ValueObject class, they are available from all value objects. The methods are:

Method

Usage

transformBooleanYN(Boolean)

Returns a string of Y for passed value of true. Returns N for passed value of false. Returns null string for null Boolean.

transformBoolean01(Boolean)

Returns a string of 1 for passed value of true. Returns 0 for passed value of false. Returns null string for null Boolean.

transformToBoolean(String)

Returns a Boolean value that takes a string. A string of 1,Y,y returns true. A string of 0,N,n returns false. A null or incorrect string returns null.

This code sample shows the structure for each of the methods:

-----------------String to Boolean---------------------
//Use ValueObject (tools provided method) transformToBoolean.
//Tools method will account for both Y,y,N,n,0,1 values, null values 
//set Boolean to null
public void setIsSomething(String isSomething){ 
   this.isSomething= transformToBoolean(isSomething);
}
------------------Boolean to String----------------------              
//E1 needs to be researched to determine what values are valid for
//true and false values
//Use ValueObject (tools provided methods) transformBooleanYN or 
//transform Boolean01.
//Tools method will provide proper Boolean value for either Y/N or 
//0/1, null will result in null String
public void setIsSomething(Boolean isSomething){
   this.isSomething = transformBooleanYN(isSomething);
}
                 OR
public void setIsSomething(Boolean isSomething){
   this.isSomething = transformBoolean01(isSomething);