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

Add Traversable isOrdered() indicator and Ordered interface #1495

Closed
danieldietrich opened this issue Aug 15, 2016 · 3 comments
Closed

Add Traversable isOrdered() indicator and Ordered interface #1495

danieldietrich opened this issue Aug 15, 2016 · 3 comments

Comments

@danieldietrich
Copy link
Contributor

This comes handy when converting a specific Traversable to an ordered collection like SortedSet or PriorityQueue. We could get rid of using instanceof.

// old code
if (this instanceof SortedSet) {
    Comparator<T> comparator = ((SortedSet<T>) this).comparator();
    ...
} else if (this instanceof PriorityQueue) {
    Comparator<T> comparator = ((PriorityQueue <T>) this).comparator();
    ...
} else if (this instanceof ...) {
    Comparator<T> comparator = ((...<T>) this).comparator();
    ...
} else {
    ...
}

// new code
if (isOrdered()) {
    Comparator<T> comparator = ((Ordered<T>) this).comparator();
    ...
} else {
   ...
}

The new Ordered interface looks like this:

interface Ordered<T> {
    Comparator<T> comparator();
}

It will be implemented by SortedSet, PriorityQueue, ... The existing comparator() methods need an @Override annotation then.

@danieldietrich danieldietrich added this to the 2.1.0 milestone Aug 15, 2016
@danieldietrich
Copy link
Contributor Author

This issue goes adhere with #1488

@danieldietrich danieldietrich modified the milestones: 2.2.0, 2.1.0 Aug 23, 2016
@danieldietrich danieldietrich modified the milestones: 2.1.0, 2.2.0 Oct 23, 2016
@danieldietrich
Copy link
Contributor Author

See also #1635

ruslansennov added a commit to ruslansennov/vavr that referenced this issue Nov 26, 2016
danieldietrich added a commit that referenced this issue Nov 28, 2016
@ruslansennov
Copy link
Member

Closed by #1711

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

2 participants