Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. public class ObjectWrapper {
  2.  
  3.     String objectId;
  4.     String parenId;
  5.     // getters + setters
  6. }
  7.  
  8.  
  9. main() {
  10.    
  11.     ArrayList<ObjectItSelf> objectList = new ArrayList<ObjectItSelf>();
  12.     // Key is id of parent and value is list of its children   
  13.     HashMap<String,List<ObjecWraper>> parentMap = new HashMap<String,List<ObjectWrapper>>();
  14.     // Each objectWrapper will be used for creating new ObjectItself object.    
  15.     // Every object has one parent and objects can have several children or none   
  16.     for(ObjectWrapper objectWraper : objectWraperList) {
  17.     ObjectItSelf object = new ObjectItSelf();
  18.     String parentId = objectWraper.getParentId();
  19.     // We get new ID from sequence of database
  20.     int newId = daoImpl.getNewId();
  21.     object.setId(newId);
  22.     objectList.add(object);
  23.     // If there is parentId in map just add child to arraylist if no add parentId to map
  24.     if(parentsMap.containsKey(parentId)){
  25.         parentsMap.get(parentId).add(objectWraper );
  26.     } else {
  27.         List<ObjectWrapper > newChildList = new ArrayList<ObjectWrapper>();
  28.         newChildList.add(objectWraper );
  29.         parentsMap.put(parentId, newChildList);
  30.     }                  
  31.      } 
  32.      /* Here is problem. objectChildren objects have new ID which was generated from
  33.       * sequence. But parent IDS was set from old object and in time when object were
  34.       * created I could not now what would be the new id of parent. So lets saz that parent
  35.       * had ID 1 then the new ID is 2. Problem is I am looking for object with new id(2) but
  36.       * id in map is still 1   
  37.       */
  38.      for(ObjectItSelf object : objectList) {
  39.     List<ObjectItSelf > objectChildren= parentsMap.get(object .getId());
  40.     ExtraRelationShipObject[] relationShipArray = new ExtraRelationShipObject[100]
  41.     // for each object get its data and turn it into ExtraRelationShipObject
  42.      }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement