Skip to content
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

Primitive Comparator.comparing(keyExtractor), like standrad Comparator #313

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

barakugav
Copy link
Contributor

@vigna
Copy link
Owner

vigna commented Jan 15, 2024

Mmmmhh no this will generate a copy of all functions in each generated file.

@barakugav
Copy link
Contributor Author

barakugav commented Jan 15, 2024

That is the intention.

java.util.Comparator define 5 'comparing' static functions:

static <T, U extends Comparable<U>> Comparator<T> comparing(Function<T, U> keyExtractor);
static <T, U> Comparator<T> comparing(Function<T, U> keyExtractor, Comparator<U> keyComparator);
static <T> Comparator<T> comparingInt(ToIntFunction<T> keyExtractor);
static <T> Comparator<T> comparingLong(ToLongFunction<T> keyExtractor);
static <T> Comparator<T> comparingDouble(ToDoubleFunction<T> keyExtractor);

These methods create a comparator that extract comparable/obj/int/long/double from the T instances and compare them.

I want to provide 5 such functions for each primitive comparator:

IntComparator comparingObj(Int2ObjFunction<Comparable> keyExtractor);
IntComparator comparingObj(Int2ObjFunction<U> keyExtractor, Comparator<U> keyComparator);
IntComparator comparingInt(Int2IntFunction keyExtractor);
IntComparator comparingLong(Int2LongFunction keyExtractor);
IntComparator comparingDouble(Int2DoubleFunction keyExtractor);
ShortComparator comparingObj(Short2ObjFunction<Comparable> keyExtractor);
ShortComparator comparingObj(Short2ObjFunction<U> keyExtractor, Comparator<U> keyComparator);
ShortComparator comparingInt(Short2IntFunction keyExtractor);
...

@barakugav
Copy link
Contributor Author

@vigna what you think?

@vigna
Copy link
Owner

vigna commented Jan 20, 2024

It seems Ok, but I'm in the middle of a deadline and unfortunately I don't have any bandwidth left. I'll be able to check this in a couple of weeks...

@vigna
Copy link
Owner

vigna commented Feb 7, 2024

Ok, but is it necessary to name it comparingObj? Can't it just be named comparing? Or some ambiguity arises?

@vigna
Copy link
Owner

vigna commented Feb 7, 2024

And, it would be nice to have a few unit tests covering the code.

@barakugav
Copy link
Contributor Author

@vigna Renamed comparingObj to comparing and added a few tests

@vigna vigna merged commit 49a738d into vigna:master Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants