Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

java - Flux.mergeOrdered() do not order the Flux

I have a problem with Flux.mergeOrdered() method. I have a class Person:

static class Person {
        int age;
        String name;

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }

  //getters and setters

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }
//toString()
    }

Now I try to create some Persons, put them in different Fluxes, create comparator and with Flux.mergeOrdered() method get one ordered FLux:

    Person alex = new Person(13,"Alex");
    Person misha = new Person(12,"Misha");
    Person oleg = new Person(14,"Oleg");
    Person nikita = new Person(66,"Nikita");
    Person dima = new Person(60,"Dima");
    Person kolya = new Person(68,"Kolya");

    Flux<Person> young = Flux.just(alex, misha, oleg);
    Flux<Person> old = Flux.just(nikita, dima, kolya);
    Comparator<Person> personComparator = Comparator.comparingInt(Person::getAge);

    Flux.mergeOrdered(personComparator, young, old).subscribe(System.out::println);

My output:

Person{age=13, name='Alex'} Person{age=12, name='Misha'} Person{age=14, name='Oleg'} Person{age=66, name='Nikita'} Person{age=60, name='Dima'} Person{age=68, name='Kolya'}

Why the result Flux is not Ordered?

question from:https://stackoverflow.com/questions/65938001/flux-mergeordered-do-not-order-the-flux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...