/**
   * Compares tow MapDomain objects with each other.
   *
   * @param domain MapDomain from the Schema, which should be compared.
   * @param gDomain MapDomain form the SchemaGraph, which should be compared.
   */
  private final void compareDomain(
      de.uni_koblenz.jgralab.schema.MapDomain domain, MapDomain gDomain) {

    // KEY DOMAIN
    HasKeyDomain hasKeyDomain = gDomain.getFirstHasKeyDomainIncidence(OUTGOING);
    assertTrue("There is no key Domain defined.", hasKeyDomain != null);
    Vertex vertex = hasKeyDomain.getThat();
    assertTrue("That should be an instance of Domain.", vertex instanceof Domain);
    assertFalse(
        "There is more than one key Domain.",
        hasKeyDomain.getNextHasKeyDomainIncidence(OUTGOING) != null);
    Domain gKeyDomain = (Domain) vertex;

    // Compares the QualifiedName of the key domain
    assertEquals(
        "Both key Domain objects should have the same QualifiedName.",
        domain.getKeyDomain().getQualifiedName(),
        gKeyDomain.get_qualifiedName());

    // VALUE DOMAIN
    HasValueDomain hasValueDomain = gDomain.getFirstHasValueDomainIncidence(OUTGOING);
    assertTrue("There is no value Domain defined.", hasValueDomain != null);
    vertex = hasValueDomain.getThat();
    assertTrue("That should be an instance of Domain.", vertex instanceof Domain);
    assertFalse(
        "There is more than one value Domain.",
        hasValueDomain.getNextHasValueDomainIncidence(OUTGOING) != null);
    Domain gValueDomain = (Domain) vertex;

    // Compares the QualifiedName
    assertEquals(
        "Both value Domain objects should have an equal QualifiedName.",
        domain.getValueDomain().getQualifiedName(),
        gValueDomain.get_qualifiedName());
  }
  /**
   * Compares all Domain objects of two Package objects.
   *
   * @param xPackage Package from the Schema, of which all Domain objects are compared.
   * @param gPackage Package from the SchemaGraph, of which all Domain objects are compared.
   */
  private final void compareAllDomains(
      de.uni_koblenz.jgralab.schema.Package xPackage, Package gPackage) {
    // Gets all Domains (clone of the map) of a Schema
    Map<String, de.uni_koblenz.jgralab.schema.Domain> domains =
        new HashMap<String, de.uni_koblenz.jgralab.schema.Domain>(xPackage.getDomains());

    // Loop over all ContainsDomain edges
    for (ContainsDomain containsDomain : gPackage.getContainsDomainIncidences(OUTGOING)) {
      // Checking if the reference is right
      Domain gDomain = retrieveDomain(containsDomain);

      // Gets the simpleName for querying a the right domain
      String simpleName = schema.getDomain(gDomain.get_qualifiedName()).getSimpleName();

      // Gets, removes and compares at the same time both Domain objects.
      de.uni_koblenz.jgralab.schema.Domain domain = domains.remove(simpleName);
      assertFalse(
          "There is corresponding Domain of name \"" + simpleName + "\" in the Schema.",
          domain == null);

      compareDomain(domain, gDomain);
    }

    clearBasicDomains(domains);

    // After all this, the Domain map should be empty
    assertTrue("There are more Domains in the Schema then in the SchemaGraph.", domains.isEmpty());
  }
  /**
   * Compares two CollectionDomain objects with each other.
   *
   * @param domain CollectionDomain from the Schema, which should be compared.
   * @param gDomain CollectionDomain from the SchemaGraph, which should be compared.
   */
  private final void compareDomain(
      de.uni_koblenz.jgralab.schema.CollectionDomain domain, CollectionDomain gDomain) {

    // BASE DOMAIN
    HasBaseDomain hasBaseDomain = gDomain.getFirstHasBaseDomainIncidence(OUTGOING);
    assertTrue("There should be a base Domain.", hasBaseDomain != null);
    Vertex vertex = hasBaseDomain.getThat();
    assertTrue("That should be an instance of Domain.", vertex instanceof Domain);
    assertFalse(
        "There is more than one base Domain.",
        hasBaseDomain.getNextHasBaseDomainIncidence(OUTGOING) != null);
    Domain gBaseDomain = (Domain) vertex;

    // Compares the QualifiedName
    assertEquals(
        "Both base Domain objects should have an equal QualifiedName.",
        domain.getBaseDomain().getQualifiedName(),
        gBaseDomain.get_qualifiedName());
  }
  /**
   * Compares two RecordDomain objects with each other.
   *
   * @param domain RecordDomain from Schema, which should be compared.
   * @param gDomain RecordDomain from SchemaGraph, which should be compared.
   */
  private final void compareDomain(
      de.uni_koblenz.jgralab.schema.RecordDomain domain, RecordDomain gDomain) {

    // Clones a map of Components

    Collection<RecordComponent> tempComponents = domain.getComponents();
    Map<String, de.uni_koblenz.jgralab.schema.Domain> components =
        new HashMap<String, de.uni_koblenz.jgralab.schema.Domain>(tempComponents.size());
    for (RecordComponent component : tempComponents) {
      components.put(component.getName(), component.getDomain());
    }
    for (HasRecordDomainComponent hasRecordDomainComponent :
        gDomain.getHasRecordDomainComponentIncidences(OUTGOING)) {

      assertTrue(
          "Omega should be an instance of Domain.",
          hasRecordDomainComponent.getOmega() instanceof Domain);
      // Gets the Domain
      Domain domainComponent = hasRecordDomainComponent.getOmega();

      // Get and removes the Domain and compares.
      // The comparison of the Component name is missed out, because
      // it is
      // implicitly done.

      de.uni_koblenz.jgralab.schema.Domain currentDomain =
          components.remove(hasRecordDomainComponent.get_name());
      assertFalse(
          "In the Schema there no Domain called: \"" + hasRecordDomainComponent.get_name() + "\"",
          currentDomain == null);

      assertEquals(
          "Both DomainComponents don't have an equal name.",
          currentDomain.getQualifiedName(),
          domainComponent.get_qualifiedName());
    }

    // The map should be empty or there are some components left over
    assertTrue("There are more Components in Schema then in SchemaGraph", components.isEmpty());
  }