I am using a class where I am taking input as the file name and the file location. I have a pre defined file names, so I will match the predefined file names with the file name that I received and then store the values accordingly. Please look at the code below
//Set of storage maps and tables
public class storage
{
//Storage set
public static Set<Integer> tiger = new HashSet<Integer>();
//Storage set
public static Set<Integer> lion = new HashSet<Integer>();
//This is the table used for storing the browser customer count
public static Table<String,String,Integer> elephant = HashBasedTable.create();
//Storage map
public static Map<String, String> monkey = new HashMap<String, String>();
public static void storeDataDirector(String fileLocation,String fileName) throws Exception
{
if (fileName = monkey)
**update the "monkey map"**
}
This is my problem, also I have lot of maps and tables to be used so I wouldn’t be able to use multiple if conditions and then check and update the same.
What I would like to know is the below
As I have said earlier, The file name that I am sending to the program which is “String filename” has the same name of the “Map monkey” but the former is a String and the latter is the map. I would like to know if I will be able to use the string variable as a reference to the map instance as both of them have the same name . This will highly avoid the if conditions that I am using in the program and thus I would like to possible solution for this … Anything related to type caseting ort
The idea is to relate them in a Map, and use the file name as a key for example
If you need a generic solution, you could solve this by implementing an abstraction of your store structure, by implementing an interface similar to this one:
so you will have an implementation for each case (Set, Map, Table …) and will relate it in a map using the file name as key.
When you wanna update some store you perform a
getover the map using the file name as key, and invokingupdatemethod implemented with the record (that could be anString, complexObject) and so on. When you need to read something from there you could use thelistmethod.