Beispiel #1
0
  /**
   * Évalue la cohésion interne d'une interface.
   *
   * @param itf L'interface à évaluer
   * @return Un double entre 0.0 et 100.0
   */
  public double internalCohesion(final Interface itf) {
    double result = 0.0;

    Set<Function> itfFcts = itf.getFunctions();
    Set<GlobalVariable> itfVars = itf.getGlobalVariables();
    Set<ComplexType> itfTypes = itf.getComplexTypes();
    int nbEntities = itfFcts.size() + itfVars.size() + itfTypes.size();

    if (nbEntities > 1) {
      if (itfFcts.size() > 0) {
        int n = 0;

        if (itfFcts.size() > 1) {
          result += cohesionFcts(itfFcts);
          ++n;
        }

        if (itfVars.size() > 0) {
          result += cohesionFctsVars(itfFcts, itfVars);
          ++n;
        }

        if (itfTypes.size() > 0) {
          result += cohesionFctsTypes(itfFcts, itfTypes);
          ++n;
        }

        result /= n;
      } else if (itfVars.size() > 0 && itfTypes.size() > 0) {
        result += cohesionVarsTypes(itfVars, itfTypes);
      }
    } else if (nbEntities > 0) {
      result = 100.0;
    }

    return result;
  }
Beispiel #2
0
  /**
   * Évalue la cohésion entre 2 interfaces d'un composant.
   *
   * @return Un double entre 0.0 et 100.0
   */
  public double interfacesCohesion(Interface itf1, Interface itf2) {
    double result = 0.0;

    Set<Function> functions1 = itf1.getFunctions();
    Set<Function> functions2 = itf2.getFunctions();

    Set<GlobalVariable> variables1 = itf1.getGlobalVariables();
    Set<GlobalVariable> variables2 = itf2.getGlobalVariables();

    Set<ComplexType> types1 = itf1.getComplexTypes();
    Set<ComplexType> types2 = itf2.getComplexTypes();

    int nbPairs = 0;

    for (Function fct1 : functions1) {
      for (Function fct2 : functions2) {
        result += cohesion(fct1, fct2);
        ++nbPairs;
      }

      for (GlobalVariable var2 : variables2) {
        result += cohesion(fct1, var2);
        ++nbPairs;
      }

      for (ComplexType t2 : types2) {
        result += cohesion(fct1, t2);
        ++nbPairs;
      }
    }

    for (Function fct2 : functions2) {
      for (GlobalVariable var1 : variables1) {
        result += cohesion(fct2, var1);
        ++nbPairs;
      }

      for (ComplexType t1 : types1) {
        result += cohesion(fct2, t1);
        ++nbPairs;
      }
    }

    if (nbPairs > 0) {
      result /= nbPairs;
    }

    return result;
  }