public int compareTo(Participant<M, S> o) {

    if (this.coefficient != null
        && o.getCoefficient() != null
        && this.coefficient instanceof Comparable) {
      int coefComparison = ((Comparable) this.coefficient).compareTo(o.getCoefficient());
      if (coefComparison != 0) {
        return coefComparison;
      }
    }

    if (o instanceof CompartmentalisedParticipant) {
      CompartmentalisedParticipant co = (CompartmentalisedParticipant) o;
      if (this.compartment != null
          && co.getCompartment() != null
          && this.compartment instanceof Comparable) {
        int compComparison = ((Comparable) this.compartment).compareTo(co.getCompartment());
        if (compComparison != 0) {
          return compComparison;
        }
      }
    }

    if (this.molecule != null && o.getMolecule() != null && this.molecule instanceof Comparable) {
      return ((Comparable) this.molecule).compareTo(o.getMolecule());
    }

    return 0;
  }
  public boolean equals(CompartmentalisedParticipant<M, S, C> other) {

    if (this.molecule != other.getMolecule()
        && (this.molecule == null || !this.molecule.equals(other.getMolecule()))) {
      return false;
    }
    if (this.coefficient != other.getCoefficient()
        && (this.coefficient == null || !this.coefficient.equals(other.getCoefficient()))) {
      return false;
    }
    if (this.compartment != other.getCompartment()
        && (this.compartment == null || !this.compartment.equals(other.getCompartment()))) {
      return false;
    }
    return true;
  }