Package de.FeatureModellingTool.ModelChecker

Source Code of de.FeatureModellingTool.ModelChecker.FeatureCheckInfoModel

/*
* @(#) FeatureCheckInfoModel.java
* Author: DUKUN
* Date: 2003-10-27
* Version: 0.1
* Description:
*
*/
package de.FeatureModellingTool.ModelChecker;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

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

/**
* @author dukun
* Description:
*/
public class FeatureCheckInfoModel {
  private HashMap featuresInfo = new HashMap();
  private HashMap reqRelations = new HashMap();
  private HashSet seedFeatures = new HashSet();
  private HashSet implictRelations = new HashSet();
 
  /**
   * @return
   * Desciption:
   */
  public HashSet getImplictRelations() {
    return implictRelations;
  }

  /**
   * @return
   * Desciption:
   */
  public HashSet getSeedFeatures() {
    return seedFeatures;
  }

  /**
   * @return
   * Desciption:
   */
  public HashMap getFeaturesInfo() {
    return featuresInfo;
  }

  /**
   * @return
   * Desciption:
   */
  public HashMap getReqRelations() {
    return reqRelations;
  }

  public boolean isFeatureInAtomicSet(Feature f, AtomicFeatureSet as) {
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(f);
    if(fchkInfo != null)
      return fchkInfo.getAtomicSet()==as;
     
    return as==null;
 
 
  public boolean isFeatureInDependentSet(Feature f, DependentFeatureSet ds) {
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(f);
    if(fchkInfo != null)
      return fchkInfo.getDependentSet()==ds;
   
    return ds==null;   
  }
 
  public boolean isFeatureNotInAnyAtmoicSet(Feature f) {
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(f);
    return fchkInfo==null || fchkInfo.getAtomicSet()==null;
  }
 
  public boolean isFeatureNotInAnyDependentSet(Feature f) {
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(f);
    return fchkInfo==null || fchkInfo.getDependentSet()==null;
  }
 
  public FeatureCheckInfo getFeatureCheckInfo(Feature f) {
    return (FeatureCheckInfo)featuresInfo.get(f);
  }
 
  public void addFeatureToAtomicSet(Feature f, AtomicFeatureSet as) {
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(f);
    if(fchkInfo == null) {
      fchkInfo = new FeatureCheckInfo();
      fchkInfo.setFeature(f);
      featuresInfo.put(f, fchkInfo);
    }
    as.addFeature(f);
    fchkInfo.setAtomicSet(as);
    Collection rs = f.getStartWithRelation(FeatureRelation.DECOMPOSE);
    if(rs != null) {
        Iterator iter = rs.iterator();
      while(iter.hasNext()) {
        Feature sf = ((FeatureRelation)iter.next()).getEndFeature();
        if(sf.getVariability() == Variability.Mandatory) {
          addFeatureToAtomicSet(sf, as);
        } else {
          FeatureRelation fr = new FeatureRelationImplementation(FeatureRelation.REQUIRE, sf, f);
          implictRelations.add(fr);   
        }
      }
    }
    rs = f.getStartWithRelation(FeatureRelation.ATTRIBUTE);
    if(rs != null) {
      Iterator iter = rs.iterator();
      while(iter.hasNext()) {
        Feature sf = ((FeatureRelation)iter.next()).getEndFeature();
        FeatureRelation fr = new FeatureRelationImplementation(FeatureRelation.REQUIRE, sf, f);
        implictRelations.add(fr);
      }
    }
  }
 
  /**
   * @param f
   * @return
   * Desciption:
   */
  public boolean isSeedFeature(Feature f) {
    // TODO Auto-generated method stub
    if(seedFeatures.contains(f))
      return true;
    else 
      return false;
  }
 
  public void addRequireRelationBetweenAtomicSet(FeatureRelation fr) {
    Feature start = fr.getStartFeature();
    Feature end = fr.getEndFeature();
    AtomicFeatureSet startAS = ((FeatureCheckInfo)featuresInfo.get(start)).getAtomicSet();
    AtomicFeatureSet endAS = ((FeatureCheckInfo)featuresInfo.get(end)).getAtomicSet();
    HashSet reqSet = (HashSet)reqRelations.get(startAS);
    if(reqSet == null)
      reqSet = new HashSet();
    reqSet.add(endAS);
    reqRelations.put(startAS, reqSet);
  }
 
  public void addSeedFeature(Feature f) {
    seedFeatures.add(f);
  }

  /**
   * @param f
   * @return
   * Desciption:
   */
  public Feature getRootOfFeature(Feature f) throws ModelInvalidateException {
    // TODO Auto-generated method stub
    Set pfSet = f.getEndWithRelation(FeatureRelation.DECOMPOSE);
    if(pfSet==null || pfSet.size()<=0)
      return f;
   
    if(pfSet.size() > 1) {
      throw new ModelInvalidateException(ModelInvalidateException.FeatureHasMoreParents);
    }
   
    Feature pf = ((FeatureRelation)pfSet.iterator().next()).getStartFeature();
    return getRootOfFeature(pf);
  }

  /**
   * @param sf
   * @return
   * Desciption:
   */
  public void genDependentSetOfFeature(Feature sf) {
    // TODO Auto-generated method stub
    HashSet features = new HashSet();
    FeatureCheckInfo fchkInfo = (FeatureCheckInfo)featuresInfo.get(sf);
    features = fchkInfo.getAtomicSet().getFeatures();
    HashSet reqSet = (HashSet)reqRelations.get(fchkInfo.getAtomicSet());
   
    if(reqSet != null) {
      Iterator iter = reqSet.iterator();
      while(iter.hasNext()) {
        AtomicFeatureSet as = (AtomicFeatureSet)iter.next();
        features.addAll(as.getFeatures());
      }
    }
    DependentFeatureSet ds = new DependentFeatureSet();
    ds.setSource(sf);
    ds.setFeatures(features);
    fchkInfo.setDependentSet(ds);
  }
 

}
TOP

Related Classes of de.FeatureModellingTool.ModelChecker.FeatureCheckInfoModel

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.