package com.netflix.exhibitor.core.config;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.netflix.exhibitor.core.activity.ActivityLog;
import com.netflix.exhibitor.core.state.ServerList;
import java.util.List;
import java.util.Set;

class RollingHostNamesBuilder
{
    private final List<String>      rollingHostNames;

    RollingHostNamesBuilder(InstanceConfig rootConfig, InstanceConfig rollingConfig, ActivityLog log)
    {
        ServerList  rootServers = new ServerList(rootConfig.getString(StringConfigs.SERVERS_SPEC));
        ServerList  rollingServers = new ServerList(rollingConfig.getString(StringConfigs.SERVERS_SPEC));

        Set<String>     newServers = Sets.difference(Sets.newHashSet(rollingServers.getHostnames()), Sets.newHashSet(rootServers.getHostnames()));
        Set<String>     unchangedServers = Sets.intersection(Sets.newHashSet(rollingServers.getHostnames()), Sets.newHashSet(rootServers.getHostnames()));

        if ( newServers.size() > 1 )
        {
            log.add(ActivityLog.Type.INFO, "Warning - adding more than 1 new server can cause issues. The ensemble may not achieve quorum.");
        }

        ImmutableList.Builder<String> builder = ImmutableList.builder();
        builder.addAll(newServers); // new servers need to be started first as the others will try to communicate with them. You may have issues if there is more than 1 new server
        builder.addAll(unchangedServers);   // the servers that are staying in the cluster can be restarted next.
        rollingHostNames = builder.build(); // servers coming out of the cluster can be restarted all at once at the end
    }

    List<String> getRollingHostNames()
    {
        return rollingHostNames;
    }
}

@@ -733,36 +733,36 @@
 ference(Sets.new
-Hash
+Tree
 Set(rollingServe
@@ -781,36 +781,36 @@
 mes()), Sets.new
-Hash
+Tree
 Set(rootServers.
@@ -892,28 +892,28 @@
 ion(Sets.new
-Hash
+Tree
 Set(rollingS
@@ -948,12 +948,12 @@
 .new
-Hash
+Tree
 Set(

Use alpha sort