/*
* @(#)ReportMappingCode.java 1.0
*
* Description:
*
* Created by MyJavaCafe team.
*
* Modification History:
* Date Version Developer Description
* ---------- ------ --------------- -----------------
* 04-02-2014 1.0 MyJavaCafe Initial version
*
*/
package com.pro;
import java.util.HashMap;
import java.util.Map;
/**
* This class use for getting the mapping report number based on the map name
*/
public class ReportMappingCode {
/**
* Assign mapping number for each map name
*/
public static final Map REPORT_TYPE = new HashMap() {
{
put(Constants.oneRpt, "1");
put(Constants.twoRpt, "2");
put(Constants.threeRpt, "3");
put(Constants.fourRpt, "4");
}
};
/**
* Retrieving the mapping report number based on the map name using Map
*/
private static String workMethod(String reportName) {
System.out.println("ReportMappingCode..workMethod()...Start");
String forwardMapping = null;
if (reportName != null) {
if (REPORT_TYPE.containsKey(reportName)) {
forwardMapping = (String) REPORT_TYPE.get(reportName);
System.out.println("Given Mapping Name "+reportName+", Forward Maping number: "+forwardMapping);
}else{
System.err.println("Given Mapping Name not available. Please retry.");
}
}else{
System.err.println("Given Mapping Name Null. Please retry.");
}
System.out.println("ReportMappingCode..workMethod()...End");
return forwardMapping;
}
/**
* Retrieving the mapping report number based on the map name using IF/ElSE
*/
private static String workMethoOld(String reportName) {
System.out.println("ReportMappingCode..workMethodOld()...Start");
String forwardMapping = null;
if (reportName != null) {
if (reportName.equals(Constants.oneRpt)) {
forwardMapping = "1";
System.out.println("Given Mapping Name "+reportName+", Forward Maping number: "+forwardMapping);
}
else if (reportName.equals(Constants.twoRpt)) {
forwardMapping = "2";
System.out.println("Given Mapping Name "+reportName+", Forward Maping number: "+forwardMapping);
}
else if (reportName.equals(Constants.threeRpt)) {
forwardMapping = "3";
System.out.println("Given Mapping Name "+reportName+", Forward Maping number: "+forwardMapping);
}
else if (reportName.equals(Constants.fourRpt)) {
forwardMapping = "4";
System.out.println("Given Mapping Name "+reportName+", Forward Maping number: "+forwardMapping);
}else{
System.err.println("Given Mapping Name not available. Please retry.");
}
}else{
System.err.println("Given Mapping Name Null. Please retry.");
}
System.out.println("ReportMappingCode..workMethodOld()...End");
return forwardMapping;
}
public static void main(String[] args) {
final String mappingName = Constants.oneRpt;//"";//null;
workMethoOld(mappingName);
workMethod(mappingName);
}
}
/**
* This class use for Constants
*/
class Constants{
public final static String oneRpt = "oneRpt";
public final static String twoRpt = "twoRpt";
public final static String threeRpt = "threeRpt";
public final static String fourRpt = "fourRpt";
}
Scenario 1: If you pass the mapping value in main method:
mappingName = Constants.oneRpt;
Output:
ReportMappingCode..workMethodOld()...Start
Given Mapping Name oneRpt, Forward Maping number: 1
ReportMappingCode..workMethodOld()...End
ReportMappingCode..workMethod()...Start
Given Mapping Name oneRpt, Forward Maping number: 1
ReportMappingCode..workMethod()...End
Scenario 2:
If you pass the mapping value in main method:
mappingName = “”;
Output:
ReportMappingCode..workMethodOld()...Start
Given Mapping Name not available. Please retry.
ReportMappingCode..workMethodOld()...End
ReportMappingCode..workMethod()...Start
Given Mapping Name not available. Please retry.
ReportMappingCode..workMethod()...End
Scenario 3:
If you pass the mapping value in main method:
mappingName = null;
Output:
ReportMappingCode..workMethodOld()...Start
Given Mapping Name Null. Please retry.
ReportMappingCode..workMethodOld()...End
ReportMappingCode..workMethod()...Start
Given Mapping Name Null. Please retry.
ReportMappingCode..workMethod()...End
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.