title: Porting a comparator from C# to Java
body: <p>I am trying to convert these small math calls to Java from C# and just wanted to make sure that they operate the same way.  I added one additional call as it is not supported in Java.</p>
  
  <p><strong>Here is code in C#</strong></p>
  
  <pre><code>public override int CompareTo(object a)
  {
  EquationGenome Gene1 = this;
  EquationGenome Gene2 = (EquationGenome)a;
  return Math.Sign(Gene2.CurrentFitness  -  Gene1.CurrentFitness);
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Java:</strong></p>
  
  <p>Notice the Math.Sign is not being called.</p>
  
  <pre><code>/**
  * Compare to.
  */
  public int compareTo(final Object a) {
  
      final EquationGenome gene1 = this;
      final EquationGenome gene2 = (EquationGenome) a;
      return (int) ((-1.0) * (gene2.currentFitness - gene1.currentFitness));
  }
  </code></pre>
  
  <p>And here is one to replicate C#'s 'next' with two int parameters in Java:</p>
  
  <pre><code>public static final int nextInt(final Random r, final int min, final int max) {
  
      final int diff = max - min;
      final int n = r.nextInt(diff);
      return n + min;
  
  }
  </code></pre>
  
  <p>Are these methods equivalent from C# to Java?</p>