Package com.ikanow.infinit.e.data_model.store.config.source.StructuredAnalysisConfigPojo

Examples of com.ikanow.infinit.e.data_model.store.config.source.StructuredAnalysisConfigPojo.EntitySpecPojo


    ArrayList<EntitySpecPojo> newEntityEntries = null;
   
    if (null != s.getEntities()) { 
      Iterator<EntitySpecPojo> entSpecIt = s.getEntities().iterator();
      while (entSpecIt.hasNext()) {
        EntitySpecPojo entS = entSpecIt.next();
        if ((null != entS.getIterateOver()) && (entS.getIterateOver().contains(".")))
        {
          // For associations only: included here so it doesn't get forgotten in cut-and-pastes...
          //if (assocS.getIterateOver().contains(",") || assocS.getIterateOver().contains("/")) {
          //  continue;
          //}
          if (null == nestedEntityMap) { // (do need this map)
            nestedEntityMap = new HashMap<String, EntitySpecPojo>();
          }
          if (null == newEntityEntries) {
            newEntityEntries = new ArrayList<EntitySpecPojo>(10);           
          }
          EntitySpecPojo prevLevelSpec = null;         
          String iterateOver = entS.getIterateOver() + "."; // (end with "." to make life easier)
          entS.setIterateOver(null); // (this is now the end of the chain)
          entSpecIt.remove(); // (so remove from the list)
         
          boolean bChainBroken = false;
          for (int nCurrDot = iterateOver.indexOf('.'), nLastDot = -1;
              nCurrDot >= 0;
            nLastDot = nCurrDot, nCurrDot = iterateOver.indexOf('.', nCurrDot + 1))
          {           
            String currLevel = iterateOver.substring(0, nCurrDot); // (eg a, a.b, a.b.c)
            String lastComp_currLevel = iterateOver.substring(nLastDot + 1, nCurrDot); // (eg a, b, c)
           
            EntitySpecPojo currLevelSpec = null;
            if (!bChainBroken) {
              currLevelSpec = nestedEntityMap.get(currLevel);
            }
            if (null == currLevelSpec) {
              bChainBroken = true; // (no point in doing any more lookups)
              currLevelSpec = new EntitySpecPojo();
              nestedEntityMap.put(currLevel, currLevelSpec);
              currLevelSpec.setIterateOver(lastComp_currLevel);
              if (null != prevLevelSpec) { // add myself to the next level
                if (null == prevLevelSpec.getEntities()) {
                  prevLevelSpec.setEntities(new ArrayList<EntitySpecPojo>(5));
                }
                prevLevelSpec.getEntities().add(currLevelSpec);               
              }
              else { // I am the first level, add myself to entity list
                newEntityEntries.add(currLevelSpec); // (this is now the head of the chain)                         
              }
              prevLevelSpec = currLevelSpec;
            }//TESTED
            else { // We're already have this level, so carry on:
              prevLevelSpec = currLevelSpec; //(in case this was the last level...)
              continue;
            }//TESTED
           
          } //(end loop over expansion levels)

          // Add entS (ie the spec with the content) to the end of the chain
         
          if (null != prevLevelSpec) { // (probably an internal logic error if not)
            if (null == prevLevelSpec.getEntities()) {
              prevLevelSpec.setEntities(new ArrayList<EntitySpecPojo>(5));
            }
            prevLevelSpec.getEntities().add(entS);
          }//TESTED         
         
        }//(end found entity with expandable iterateOver)
        else if (null != entS.getIterateOver()) { // Non-nested case, simpler
          // For associations only: included here so it doesn't get forgotten in cut-and-pastes...
          //if (assocS.getIterateOver().contains(",") || assocS.getIterateOver().contains("/")) {
          //  continue;
          //}
          if (null == nestedEntityMap) { // (do need this map)
            nestedEntityMap = new HashMap<String, EntitySpecPojo>();
          }         
          //(and logic is different enough that it makes most sense to do separately rather than grovel to save a few lines)
         
          EntitySpecPojo currSpec = nestedEntityMap.get(entS.getIterateOver());
          if (null != currSpec) {
            entSpecIt.remove();
            if (null == currSpec.getEntities()) {
              currSpec.setEntities(new ArrayList<EntitySpecPojo>(5));
            }
            entS.setIterateOver(null);
            currSpec.getEntities().add(entS);           
          }
          else {
            nestedEntityMap.put(entS.getIterateOver(), entS);
          }
        }//TESTED
      }// (end loop over entities)
     
      if (null != newEntityEntries) {
        s.getEntities().addAll(newEntityEntries);
      }     
     
    }//(end if entities)
       
    // Identical code for associations:
    // Just going to cut and replace and rename a few variables
    //HashMap<String, AssociationSpecPojo> nestedAssociationMap = null;
   
    HashMap<String, AssociationSpecPojo> nestedAssocMap = null;
    ArrayList<AssociationSpecPojo> newAssocEntries = null;
   
    if (null != s.getAssociations()) { 
      Iterator<AssociationSpecPojo> assocSpecIt = s.getAssociations().iterator();
      while (assocSpecIt.hasNext()) {
        AssociationSpecPojo assocS = assocSpecIt.next();
        if ((null != assocS.getIterateOver()) && (assocS.getIterateOver().contains(".")))
        {
          // For associations only: included here so it doesn't get forgotten in cut-and-pastes...
          if (assocS.getIterateOver().contains(",") || assocS.getIterateOver().contains("/")) {
            continue;
          }//TESTED
          if (null == nestedAssocMap) { // (do need this map)
            nestedAssocMap = new HashMap<String, AssociationSpecPojo>();
          }
          if (null == newAssocEntries) {
            newAssocEntries = new ArrayList<AssociationSpecPojo>(10);           
          }
          AssociationSpecPojo prevLevelSpec = null;         
          String iterateOver = assocS.getIterateOver() + "."; // (end with "." to make life easier)
          assocS.setIterateOver(null); // (this is now the end of the chain)
          assocSpecIt.remove(); // (so remove from the list)
         
          boolean bChainBroken = false;
          for (int nCurrDot = iterateOver.indexOf('.'), nLastDot = -1;
              nCurrDot >= 0;
            nLastDot = nCurrDot, nCurrDot = iterateOver.indexOf('.', nCurrDot + 1))
          {           
            String currLevel = iterateOver.substring(0, nCurrDot); // (eg a, a.b, a.b.c)
            String lastComp_currLevel = iterateOver.substring(nLastDot + 1, nCurrDot); // (eg a, b, c)
           
            AssociationSpecPojo currLevelSpec = null;
            if (!bChainBroken) {
              currLevelSpec = nestedAssocMap.get(currLevel);
            }
            if (null == currLevelSpec) {
              bChainBroken = true; // (no point in doing any more lookups)
              currLevelSpec = new AssociationSpecPojo();
              nestedAssocMap.put(currLevel, currLevelSpec);
              currLevelSpec.setIterateOver(lastComp_currLevel);
              if (null != prevLevelSpec) { // add myself to the next level
                if (null == prevLevelSpec.getAssociations()) {
                  prevLevelSpec.setAssociations(new ArrayList<AssociationSpecPojo>(5));
                }
                prevLevelSpec.getAssociations().add(currLevelSpec);               
              }
              else { // I am the first level, add myself to entity list
                newAssocEntries.add(currLevelSpec); // (this is now the head of the chain)                         
              }
              prevLevelSpec = currLevelSpec;
            }//TESTED
            else { // We're already have this level, so carry on:
              prevLevelSpec = currLevelSpec; //(in case this was the last level...)
              continue;
            }//TESTED
           
          } //(end loop over expansion levels)

          // Add entS (ie the spec with the content) to the end of the chain
         
          if (null != prevLevelSpec) { // (probably an internal logic error if not)
            if (null == prevLevelSpec.getAssociations()) {
              prevLevelSpec.setAssociations(new ArrayList<AssociationSpecPojo>(5));
            }
            prevLevelSpec.getAssociations().add(assocS);
          }//TESTED         
         
        }//(end found entity with expandable iterateOver)
        else if (null != assocS.getIterateOver()) { // Non-nested case, simpler
          // For associations only: included here so it doesn't get forgotten in cut-and-pastes...
          if (assocS.getIterateOver().contains(",") || assocS.getIterateOver().contains("/")) {
            continue;
          }//TESTED
          if (null == nestedAssocMap) { // (do need this map)
            nestedAssocMap = new HashMap<String, AssociationSpecPojo>();
          }         
          //(and logic is different enough that it makes most sense to do separately rather than grovel to save a few lines)
         
          AssociationSpecPojo currSpec = nestedAssocMap.get(assocS.getIterateOver());
          if (null != currSpec) {
            assocSpecIt.remove();
            if (null == currSpec.getAssociations()) {
              currSpec.setAssociations(new ArrayList<AssociationSpecPojo>(5));
            }
            assocS.setIterateOver(null);
            currSpec.getAssociations().add(assocS);           
          }
          else {
            nestedAssocMap.put(assocS.getIterateOver(), assocS);
          }
        }//TESTED
View Full Code Here


   
    // Test entity expansion:
   
    StructuredAnalysisConfigPojo s = new StructuredAnalysisConfigPojo();
    s.setEntities(new ArrayList<EntitySpecPojo>(20));
    EntitySpecPojo e = null;
    e = new EntitySpecPojo();
    //a1
    e.setIterateOver("a");
    e.setDisambiguated_name("a.test1");
    s.getEntities().add(e);
    //a2
    e = new EntitySpecPojo();
    e.setIterateOver("a");
    e.setDisambiguated_name("a.test2");
    s.getEntities().add(e);
    //x1
    e = new EntitySpecPojo();
    e.setIterateOver("x");
    e.setDisambiguated_name("x.test1");
    s.getEntities().add(e);
    //a.b1
    e = new EntitySpecPojo();
    e.setIterateOver("a.b");
    e.setDisambiguated_name("a.b.test1");
    s.getEntities().add(e);
    //a.b.c.d1
    e = new EntitySpecPojo();
    e.setIterateOver("a.b.c.d");
    e.setDisambiguated_name("a.b.c.d.test1");
    s.getEntities().add(e);
    //a.b2
    e = new EntitySpecPojo();
    e.setIterateOver("a.b");
    e.setDisambiguated_name("a.b.test2");
    s.getEntities().add(e);
    //p.q1
    e = new EntitySpecPojo();
    e.setIterateOver("p.q");
    e.setDisambiguated_name("p.q.test1");
    s.getEntities().add(e);
    // null case
    e = new EntitySpecPojo();
    e.setDisambiguated_name("(null iterator)");
    s.getEntities().add(e);
   
    expandIterationLoops(s);
   
    System.out.println("TEST1: ENTITY ITERATION EXPANSION: ");
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.config.source.StructuredAnalysisConfigPojo.EntitySpecPojo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.