class ProxyConfigurationMigrator implements PreConfigurationUpdateModule {

    protected ProxyConfigurations convertPreferences(Map<String, String> preferences)
    {
        ProxyConfigurations proxyConfigs = new ProxyConfigurations();

        List<String> exclusions = new ArrayList<>();
        if (preferences.get("ProxyExclusionPatterns") != null)
        {
            // split exclusions on one or more spaces, comma and one or more spaces, or comma
            exclusions = Arrays.asList(preferences.get("ProxyExclusionPatterns").trim().split(" +|, +|,"));
        }

        if (Boolean.parseBoolean(preferences.get("SystemProxiesEnabled")))
        {
            // System proxy with exclusions
            proxyConfigs.setSelectedConfigurationType(ConfigurationType.SYSTEM);
            proxyConfigs.getSystemProxyConfiguration().getExclusionPatterns().addAll(exclusions);
        }
        else if (preferences.get("ProxyConfigUrl") != null)
        {
            // Url proxy with url
            proxyConfigs.setSelectedConfigurationType(ConfigurationType.URL);
            proxyConfigs.getUrlProxyConfiguration().setProxyUrl(preferences.get("ProxyConfigUrl"));
        }
        else if (preferences.get("ProxyPort") != null)
        {
            // Manual proxy with host, port, and exclusions
            proxyConfigs.setSelectedConfigurationType(ConfigurationType.MANUAL);
            proxyConfigs.getManualProxyConfiguration()
            .setHost(preferences.get("ProxyHost") != null ? preferences.get("ProxyHost") : "");
            proxyConfigs.getManualProxyConfiguration().setPort(Integer.parseInt(preferences.get("ProxyPort")));
            proxyConfigs.getManualProxyConfiguration().getExclusionPatterns().addAll(exclusions);
        }
        else
        {
            // No proxy
            proxyConfigs.setSelectedConfigurationType(ConfigurationType.NONE);
        }
        return proxyConfigs;
    }

}