Skip to content

Implement IComparer #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
twiglet opened this issue Jul 12, 2011 · 1 comment
Open

Implement IComparer #19

twiglet opened this issue Jul 12, 2011 · 1 comment

Comments

@twiglet
Copy link
Owner

twiglet commented Jul 12, 2011

Comparator
Interface IComparer from C# is not translated correctly. The generated Java class looks as follows:
public class PostProfileComparer extends IComparer
{
public int Compare( PostProfile x, PostProfile y) throws Exception {
return y.getScore().Compare(x.getScore());
}

}
but interface IComparer is not defined, and also method Compare is not defined on type int (the result type of method getScore()).

We haven't yet implemented the IComparer class. I will look into that.
When we do then y.GetScore() should be automatically cast to an
Integer before we call the Compare method.

@twiglet
Copy link
Owner Author

twiglet commented Jul 14, 2011

Or alternatively use the < > == comparison on the ints directly. Simply returning y.getScore() - x.getScore() would be a simple solution,
Unfortunately this is not safe regarding int overflows.  I have translated it to
  return y.getScore() == x.getScore() ? 0 : (y.getScore() > x.getScore() ? 1 : -1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant