Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ObjectWrapper {
- String objectId;
- String parenId;
- // getters + setters
- }
- main() {
- ArrayList<ObjectItSelf> objectList = new ArrayList<ObjectItSelf>();
- // Key is id of parent and value is list of its children
- HashMap<String,List<ObjecWraper>> parentMap = new HashMap<String,List<ObjectWrapper>>();
- // Each objectWrapper will be used for creating new ObjectItself object.
- // Every object has one parent and objects can have several children or none
- for(ObjectWrapper objectWraper : objectWraperList) {
- ObjectItSelf object = new ObjectItSelf();
- String parentId = objectWraper.getParentId();
- // We get new ID from sequence of database
- int newId = daoImpl.getNewId();
- object.setId(newId);
- objectList.add(object);
- // If there is parentId in map just add child to arraylist if no add parentId to map
- if(parentsMap.containsKey(parentId)){
- parentsMap.get(parentId).add(objectWraper );
- } else {
- List<ObjectWrapper > newChildList = new ArrayList<ObjectWrapper>();
- newChildList.add(objectWraper );
- parentsMap.put(parentId, newChildList);
- }
- }
- /* Here is problem. objectChildren objects have new ID which was generated from
- * sequence. But parent IDS was set from old object and in time when object were
- * created I could not now what would be the new id of parent. So lets saz that parent
- * had ID 1 then the new ID is 2. Problem is I am looking for object with new id(2) but
- * id in map is still 1
- */
- for(ObjectItSelf object : objectList) {
- List<ObjectItSelf > objectChildren= parentsMap.get(object .getId());
- ExtraRelationShipObject[] relationShipArray = new ExtraRelationShipObject[100]
- // for each object get its data and turn it into ExtraRelationShipObject
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement