/*
 * Copyright (c) 2012-2018 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package io.moquette.persistence;

import io.moquette.broker.ISubscriptionsRepository;
import io.moquette.broker.subscriptions.Subscription;

import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

public class MemorySubscriptionsRepository implements ISubscriptionsRepository {

    private final Set<Subscription> subscriptions = new ConcurrentSkipListSet<>((o1, o2) -> {
        int compare = o1.getClientId().compareTo(o2.getClientId());
        if (compare != 0) {
            return compare;
        }
        return o1.getTopicFilter().toString().compareTo(o2.getTopicFilter().toString());
    });

    @Override
    public Set<Subscription> listAllSubscriptions() {
        return Collections.unmodifiableSet(subscriptions);
    }

    @Override
    public void addNewSubscription(Subscription subscription) {
        subscriptions.add(subscription);
    }

    @Override
    public void removeSubscription(String topic, String clientID) {
        subscriptions.stream()
            .filter(s -> s.getTopicFilter().toString().equals(topic) && s.getClientId().equals(clientID))
            .findFirst()
            .ifPresent(subscriptions::remove);
    }
}

@@ -1002,250 +1002,8 @@
 t%3C%3E(
-(o1, o2) -%3E %7B%0A        int compare = o1.getClientId().compareTo(o2.getClientId());%0A        if (compare != 0) %7B%0A            return compare;%0A        %7D%0A        return o1.getTopicFilter().toString().compareTo(o2.getTopicFilter().toString());%0A    %7D
 );%0A%0A

Remove explicit Comparator for already Comparable class (#596)