Package de.FeatureModellingTool.PLModelChecker

Source Code of de.FeatureModellingTool.PLModelChecker.AtomSet

package de.FeatureModellingTool.PLModelChecker;

import java.util.*;

import de.FeatureModellingTool.FeatureModel.ConstraintModel;
import de.FeatureModellingTool.FeatureModel.Feature;
import de.FeatureModellingTool.FeatureModel.FeatureModel;
import de.FeatureModellingTool.FeatureModel.FeatureRelation;

public class AtomSet
 
  public AtomSet(FeatureModel featureModel,  ConstraintModel  constraintModel){
    Map  allFeatures  =  featureModel.getAllFeature();
    Iterator  e  =  allFeatures.keySet().iterator();
    allAtomedFeatures  =  new LinkedHashMap<Feature, AtomedFeature>();
    while(e.hasNext()){
      Feature  f  =  (Feature)allFeatures.get(e.next());
      AtomedFeature  x  =  new AtomedFeature(f);
      allAtomedFeatures.put(f, x);
    }
       
    Map include        =  featureModel.getAllFeatureRelation(FeatureRelation.DECOMPOSE);
    Map dimensionValue    =  featureModel.getAllFeatureRelation(FeatureRelation.ATTRIBUTE);
    Map require        =  featureModel.getAllFeatureRelation(FeatureRelation.REQUIRE);

   
//    ����include��ϵ������ԭ�Ӽ�
//      allAtomedFeatures��ʾ��feature������Ӧ��ԭ�Ӽ�
    if(include  !=  null){
      e  =  include.keySet().iterator();
     
    //  System.out.println(include);
    //  if  (!e.hasNext())  System.out.println("!!!!!!!!!!");
     
      while(e.hasNext()){
        FeatureRelation    r  =  (FeatureRelation)include.get(e.next());
        Feature startFeature  =  r.getStartFeature();
        Feature endFeature    =  r.getEndFeature();
       
      //  System.out.print(endFeature.getName()+" "+startFeature.getName());
      /*  if(featureModel.getParentFeature(endFeature.getID())!=null)
          System.out.println(" "+featureModel.getParentFeature(endFeature.getID()).getName());
        else
          System.out.println(" null");*/
        if  (endFeature.getVariability().equals(de.FeatureModellingTool.FeatureModel.Variability.Mandatory)
            &&
            featureModel.getParentFeature(endFeature.getID())  ==  startFeature){
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1
              &&
              allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else{
            int  m  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            Iterator  i  =  allAtomedFeatures.keySet().iterator();
            while(i.hasNext()){
              AtomedFeature  cur  =  allAtomedFeatures.get(i.next());
              if(cur.getAtomSetNum()  ==  n)
                cur.setAtomSetNum(m);
            }
           
          }
         
        }//end if
        else{
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          if  (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
        }//end else
      }//end while
    }
   
//    ����dimensionValue��ϵ������ԭ�Ӽ�
    if(dimensionValue  !=  null){
      e  =  dimensionValue.keySet().iterator();
      while(e.hasNext()){
        FeatureRelation    r  =  (FeatureRelation)dimensionValue.get(e.next());
        Feature startFeature  =  r.getStartFeature();
        Feature endFeature    =  r.getEndFeature();
       
      /*  System.out.print(endFeature.getName()+" "+startFeature.getName());
        if(featureModel.getParentFeature(endFeature.getID())!=null)
          System.out.println(" "+featureModel.getParentFeature(endFeature.getID()).getName());
        else
          System.out.println(" null");*/
        if  (endFeature.getVariability().equals(de.FeatureModellingTool.FeatureModel.Variability.Mandatory)
            &&
            featureModel.getParentFeature(endFeature.getID())  ==  startFeature){
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1
              &&
              allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else{
            int  m  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            Iterator  i  =  allAtomedFeatures.keySet().iterator();
            while(i.hasNext()){
              AtomedFeature  cur  =  allAtomedFeatures.get(i.next());
              if(cur.getAtomSetNum()  ==  n)
                cur.setAtomSetNum(m);
            }
           
          }
         
        }//end if
        else{
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          if  (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
        }//end else
      }//end while 
   
//    ����require��ϵ������ԭ�Ӽ�
    if(require  !=  null){
      e  =  require.keySet().iterator();
      while(e.hasNext()){
        FeatureRelation    r  =  (FeatureRelation)require.get(e.next());
        Feature startFeature  =  r.getStartFeature();
        Feature endFeature    =  r.getEndFeature();
       
      /*  System.out.print(endFeature.getName()+" "+startFeature.getName());
        if(featureModel.getParentFeature(endFeature.getID())!=null)
          System.out.println(" "+featureModel.getParentFeature(endFeature.getID()).getName());
        else
          System.out.println(" null");*/
        if  (startFeature.getVariability().equals(de.FeatureModellingTool.FeatureModel.Variability.Mandatory)
            &&
            featureModel.getParentFeature(endFeature.getID())  ==  startFeature){
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1
              &&
              allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          else if    (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
          else{
            int  m  =  allAtomedFeatures.get(startFeature).getAtomSetNum();
            int  n  =  allAtomedFeatures.get(endFeature).getAtomSetNum();
            Iterator  i  =  allAtomedFeatures.keySet().iterator();
            while(i.hasNext()){
              AtomedFeature  cur  =  allAtomedFeatures.get(i.next());
              if(cur.getAtomSetNum()  ==  n)
                cur.setAtomSetNum(m);
            }
           
          }
         
        }//end if
        else{
          if  (allAtomedFeatures.get(startFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(startFeature).setAtomSetNum(n);
          }
          if  (allAtomedFeatures.get(endFeature).getAtomSetNum() == -1){
            int  n  =  AtomedFeature.increaseSet();
            allAtomedFeatures.get(endFeature).setAtomSetNum(n);
          }
        }//end else
      }//end while
    }
   
//    ����û�о�����ϵ����������Щ�������Զ�ռһ��ԭ�Ӽ�
    e  =  allAtomedFeatures.keySet().iterator();
    while(e.hasNext()){
      Feature      f  =  (Feature)e.next();
      AtomedFeature  a  =  allAtomedFeatures.get(f);
      if(a.atomSetNum  ==  -1){
        int  n  =  AtomedFeature.increaseSet();
        a.setAtomSetNum(n);
      }
    }
   
  //  System.out.println("TESTING ALLATOMEDFEATURES");
  //  test();

  }
 
  public  void computeRoots(FeatureModel featureModel){
    roots  =  new  TreeSet<Feature>();
    Map  allFeatures  =  featureModel.getAllFeature();
    Iterator  e  =  allFeatures.keySet().iterator();
    while(e.hasNext()){
      String  featureId  =  ((Feature)allFeatures.get(e.next())).getID();
      Feature root  =  featureModel.getRootFeature(featureId)
      while(root  !=  featureModel.getRootFeature(root.getID()))
        root  =  featureModel.getRootFeature(root.getID());
       
      roots.add(root);
    }
   
  //  System.out.println("TESTING COMPUTEROOTS");
  //  test();
  }
 
  public  Set<Feature>  getRoots(){
    return  this.roots;
  }
 
  public  Map<Feature,  AtomedFeature>  getAllAtomedFeatures(){
    return  this.allAtomedFeatures;
  }
 
/*  public  void  test(){
    if(allAtomedFeatures  ==  null)  return;
    StringBuffer buffer = new StringBuffer();
    Iterator  e  =  allAtomedFeatures.keySet().iterator();
    while  (e.hasNext()){
      AtomedFeature  a  =  allAtomedFeatures.get(e.next());
      String  name  =  a.getFeature().getName();
      int  atomedSetNum  =  a.atomSetNum;
      buffer.append(name);
      buffer.append('\t');
      buffer.append(atomedSetNum);
      buffer.append('\n');
    }
   
    if  (roots  !=  null){
      buffer.append("roots:\n");
      e  =  roots.iterator();
      while(e.hasNext()){
        buffer.append(((Feature)e.next()).getName());
        buffer.append('\n');
      }
    }
   
    System.out.println(buffer.toString());
  }*/
 
  private  LinkedHashMap<Feature,  AtomedFeature>  allAtomedFeatures  =  null;
  private  TreeSet<Feature>  roots  =  null;
}
 
TOP

Related Classes of de.FeatureModellingTool.PLModelChecker.AtomSet

TOP
Copyright © 2018 www.massapi.com. 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.