Skip to content

Optimize compareTo in Router to guarantee consistent behaviour. #3302

Closed

Description

@chickenlj

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

should always give the same order.

Activity

  1. added this to the 2.7.1 milestone on Jan 22, 2019
  2. chickenlj commented on Jan 22, 2019

    @chickenlj
    ContributorAuthor

    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);
        }
  3. lexburner commented on Feb 25, 2019

    @lexburner
    Contributor

    I will fix this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions