private Set<IEmbeddableCartridge> getDependants(EmbeddableCartridgeRelations relation) {
   Set<IEmbeddableCartridge> dependants = dependantsByCartridge.get(relation.getRequired());
   if (dependants == null) {
     dependantsByCartridge.put(
         relation.getRequired(), dependants = new HashSet<IEmbeddableCartridge>());
   }
   return dependants;
 }
 private void addRequiredApplication(
     EmbeddableCartridgeDiff diff, EmbeddableCartridgeRelations relation)
     throws OpenShiftException {
   if (relation.getRequiredApplication() != null
       && !domain.hasApplicationByCartridge(relation.getRequiredApplication())) {
     diff.addApplicationAddition(relation.getRequiredApplication());
   }
 }
  private void initDependencyMaps(EmbeddableCartridgeRelations... dependencies) {
    this.dependenciesByCartridge =
        new HashMap<IEmbeddableCartridge, EmbeddableCartridgeRelations>();

    this.dependantsByCartridge = new HashMap<IEmbeddableCartridge, Set<IEmbeddableCartridge>>();
    for (EmbeddableCartridgeRelations dependency : dependencies) {
      dependenciesByCartridge.put(dependency.getSubject(), dependency);
      Set<IEmbeddableCartridge> dependants = getDependants(dependency);
      dependants.add(dependency.getSubject());
    }
  }
 private void add(
     IEmbeddableCartridge cartridge,
     Set<IEmbeddableCartridge> currentCartridges,
     EmbeddableCartridgeDiff diff)
     throws OpenShiftException {
   EmbeddableCartridgeRelations relation = dependenciesByCartridge.get(cartridge);
   if (relation == null) {
     return;
   }
   removeConflicting(currentCartridges, diff, relation);
   addRequired(currentCartridges, diff, relation.getRequired());
   addRequiredApplication(diff, relation);
 }
 protected void createDependants(
     Collection<IEmbeddableCartridge> allEmbeddableCartridges,
     EmbeddableCartridgeRelations dependency) {
   Set<IEmbeddableCartridge> dependants =
       dependantsByCartridge.get(dependency.getRequired(allEmbeddableCartridges));
   if (dependants == null) {
     IEmbeddableCartridge dependantCartridge = dependency.getRequired(allEmbeddableCartridges);
     if (dependantCartridge != null) {
       dependantsByCartridge.put(
           dependantCartridge, dependants = new HashSet<IEmbeddableCartridge>());
     }
   }
   if (dependants != null) {
     dependants.add(dependency.getSubject(allEmbeddableCartridges));
   }
 }
 private void add(
     IEmbeddableCartridge cartridge,
     Set<IEmbeddableCartridge> currentCartridges,
     EmbeddableCartridgeDiff diff,
     Collection<IEmbeddableCartridge> allEmbeddableCartridges,
     Collection<IStandaloneCartridge> allStandaloneCartridges,
     Collection<IApplication> allApplications)
     throws OpenShiftException {
   EmbeddableCartridgeRelations relation = dependenciesByCartridge.get(cartridge);
   if (relation == null) {
     return;
   }
   removeConflicting(currentCartridges, diff, relation, allEmbeddableCartridges);
   addRequired(
       currentCartridges,
       diff,
       relation.getRequired(allEmbeddableCartridges),
       allEmbeddableCartridges);
   addRequiredApplication(diff, relation, allStandaloneCartridges, allApplications);
 }
 private void addRequiredApplication(
     EmbeddableCartridgeDiff diff,
     EmbeddableCartridgeRelations relation,
     Collection<IStandaloneCartridge> allStandaloneCartridges,
     Collection<IApplication> allApplications)
     throws OpenShiftException {
   IStandaloneCartridge requiredCartridge =
       relation.getRequiredApplication(allStandaloneCartridges);
   if (requiredCartridge != null
       && !containsApplicationByCartridge(requiredCartridge, allApplications)) {
     diff.addApplicationAddition(requiredCartridge);
   }
 }
 private void removeConflicting(
     Set<IEmbeddableCartridge> currentCartridges,
     EmbeddableCartridgeDiff cartridgeDiff,
     EmbeddableCartridgeRelations relation)
     throws OpenShiftException {
   IEmbeddableCartridge conflictingCartridge = relation.getConflicting();
   if (conflictingCartridge != null) {
     remove(conflictingCartridge, currentCartridges, cartridgeDiff);
     if (currentCartridges.contains(conflictingCartridge)) {
       cartridgeDiff.addRemoval(conflictingCartridge);
     }
   }
 }
 protected void createDependency(
     Collection<IEmbeddableCartridge> allEmbeddableCartridges,
     EmbeddableCartridgeRelations dependency) {
   IEmbeddableCartridge requiringCartridge = dependency.getSubject(allEmbeddableCartridges);
   dependenciesByCartridge.put(requiringCartridge, dependency);
 }