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

Optimize compareTo in Router to guarantee consistent behaviour. #3302

Closed
chickenlj opened this issue Jan 22, 2019 · 2 comments
Closed

Optimize compareTo in Router to guarantee consistent behaviour. #3302

chickenlj opened this issue Jan 22, 2019 · 2 comments
Milestone

Comments

@chickenlj
Copy link
Contributor

router1.compareTo(router2);
and
router2.compareTo(router1);

should always give the same order.

@chickenlj chickenlj added this to the 2.7.1 milestone Jan 22, 2019
@chickenlj
Copy link
Contributor Author

compareTo in Router interface

@Override
    default int compareTo(Router o) {
        if (o == null) {
            throw new IllegalArgumentException();
        }
        if (this.getPriority() == o.getPriority()) {
            if (o.getUrl() == null) {
                return 1;
            }
            if (getUrl() == null) {
                return -1;
            }
            return getUrl().toFullString().compareTo(o.getUrl().toFullString());
        } else {
            return getPriority() > o.getPriority() ? 1 : -1;
        }
    }

compareTo in ScriptRouter

 @Override
    public int compareTo(Router o) {
        if (o == null || o.getClass() != ScriptRouter.class) {
            return 1;
        }
        ScriptRouter c = (ScriptRouter) o;
        return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
    }

@lexburner
Copy link
Contributor

I will fix this.

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

No branches or pull requests

2 participants