The data can be stored as follows.
1. there will be a root HashMap which has NAME as key and another
HashMap as value..
2. the second HashMap will have role as key and an array list as
value..
3. the ArrayList will have list of all the resources for that user for
that particular role.
so.. the root HashMap will look like
HashMap { [NAME1, HashMap { [ROLE1, ArrayList {RES11, RES12,...} ],
[ROLE2, ArrayList {RES21,
RES22,...} ],.....} ], [NAME2, HashMap { [ROLE1, ArrayList {RES11,
RES12,...} ], [ROLE2, ArrayList {RES21, RES22, ...
} ], .... }
eg:
SAM:ADMIN:LAP
SAM:ADMIN:PEN
SAM:USER:PC
MIKE:USER:PC
then the storage will be like
HashMap { [SAM, HashMap { [ADMIN, ArrayList {LAP, PEN}], [USER,
ArrayList {PC}] } ], [MIKE, HashMap { [USER, ArrayList {PC} ] } ] }
the following is a simple function which does the above logic..
public void store(Map userMap, String user, String role, String
resource) {
Map roleMap = (Map)userMap.get(user);
if(roleMap == null) {
roleMap = new HashMap();
userMap.put(user, roleMap);
}
List resList = (List) roleMap.get(role);
if (resList == null) {
resList = new ArrayList();
roleMap.put(role, resList);
}
if(!resList.contains(resource)){
resList.add(resource);
}
}
using this you can access all the data very easily.. i guess the memory
utilization better since there is no unnecessary or duplicate data
stored. (dont know the exact memory utilization)
LuckyBoy - 14 Sep 2006 05:04 GMT
Hi Jiji, Your solution looks fine but can you tell me what is the
userMap that you are passing to the store() method . In context of file
being read, when will this store method be called ?
Can you give a complete picture.
> The data can be stored as follows.
>
[quoted text clipped - 49 lines]
> utilization better since there is no unnecessary or duplicate data
> stored. (dont know the exact memory utilization)
LuckyBoy - 14 Sep 2006 19:12 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
LuckyBoy - 14 Sep 2006 19:13 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
LuckyBoy - 14 Sep 2006 19:13 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
LuckyBoy - 14 Sep 2006 19:13 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
LuckyBoy - 14 Sep 2006 19:13 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
LuckyBoy - 14 Sep 2006 19:14 GMT
Can anybody suggest a good DataStructure Solution to this problem ?
Parsing a delimited text file :
USER:ROLE:RESOURCE
Like input file is: (can be huge size with many records)
===================
sam:user:pc
mike:admin:laptop
sam:admin:usb drive
richard:user:pc
===================
output in some class level object(s) must be: user is to be stored only
once for n roles and n resources
sam:user:pc
:admin:usb drive
mike:admin:laptop
richard:user:pc
I got HashMap1 [ K , HashMap2 [ K, ArrayList ] ] as a solution.
Anything better ?
Gordon Beaton - 14 Sep 2006 19:22 GMT
> Can anybody suggest a good DataStructure Solution to this problem ?
Ok we got it the first time.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e