Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public LinkedHashMap<String, Boolean> addKeysValue(LinkedList<String> keys, Object value) throws IOException {
  2. int keyIndex = keys.size()-1;
  3. HashMap<String, Object> nestedMap = new HashMap<>();
  4. HashMap<String, Object> finalMap = new HashMap<>();
  5. nestedMap.put(keys.get(keyIndex), value);
  6. keyIndex--;
  7. boolean firstLoop = true;
  8. while (keyIndex > 0) {
  9. if (firstLoop) {
  10. firstLoop = false;
  11. finalMap = new HashMap<>();
  12. finalMap.put(keys.get(keyIndex), nestedMap);
  13. } else {
  14. HashMap<String, Object> tempMap = new HashMap<>();
  15. tempMap.put(keys.get(keyIndex), finalMap);
  16. finalMap = tempMap;
  17. }
  18. keyIndex--;
  19. }
  20. synchronized (HASHMAP_LOCK_OBJECT){
  21. DATA.put(keys.get(0), finalMap);
  22. }
  23. dumpOnModification(DATA);
  24. return null;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement