/*
 * Copyright 2014 Giannis Dzegoutanis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.bitcoinj.params;

import org.bitcoinj.core.NetworkParameters;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;

import java.util.Collection;
import java.util.Set;

/**
 * Utility class that holds all the registered NetworkParameters types used for address auto discovery.
 * By default only MainNetParams and TestNet3Params are used. If you want to use RegTestParams or
 * UnitTestParams use the register and unregister the TestNet3Params as they don't have their own address
 * version/type code.
 */
public class Networks {
    /** Registered networks */
    private static Set<NetworkParameters> networks = ImmutableSet.<NetworkParameters>of(TestNet3Params.get(), MainNetParams.get());

    public static Set<NetworkParameters> get() {
        return networks;
    }

    public static void register(NetworkParameters network) {
        register(Lists.newArrayList(network));
    }

    public static void register(Collection<? extends NetworkParameters> networks) {
        ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
        builder.addAll(Networks.networks);
        builder.addAll(networks);
        Networks.networks = builder.build();
    }

    public static void unregister(NetworkParameters network) {
        if (networks.contains(network)) {
            ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
            for (NetworkParameters parameters : networks) {
                if (parameters.equals(network))
                    continue;
                builder.add(parameters);
            }
            networks = builder.build();
        }
    }
}

@@ -861,16 +861,23 @@
 istered 
+%7B@link 
 NetworkP
@@ -885,16 +885,17 @@
 rameters
+%7D
  types u
@@ -945,16 +945,23 @@
 lt only 
+%7B@link 
 MainNetP
@@ -965,21 +965,29 @@
 etParams
+%7D
  and 
+%7B@link 
 TestNet3
@@ -992,16 +992,17 @@
 t3Params
+%7D
  are use
@@ -1023,16 +1023,23 @@
  to use 
+%7B@link 
 RegTestP
@@ -1047,14 +1047,22 @@
 rams
- or%0A *
+%7D%0A * or %7B@link
  Uni
@@ -1072,23 +1072,27 @@
 stParams
+%7D
  use 
-th
+%7B@cod
 e regist
@@ -1093,21 +1093,34 @@
 register
+%7D
  and 
+then %7B@code 
 unregist
@@ -1121,21 +1121,29 @@
 register
+%7D
  the 
+%7B@code 
 TestNet3
@@ -1148,16 +1148,17 @@
 t3Params
+%7D
  as they
@@ -1163,16 +1163,19 @@
 ey don't
+%0A *
  have th
@@ -1186,37 +1186,154 @@
 own 
-address%0A * version/type code.
+Base58 version/type code (although for %7B@link org.bitcoinj.core.SegwitAddress%7D the human readable%0A * parts for RegTest and TestNet are different.)
 %0A */
@@ -1610,118 +1610,430 @@
     
-public static void register(NetworkParameters network) %7B%0A        register(Lists.newArrayList(network));%0A    %7D%0A
+/**%0A     * Register a single network type by adding it to the %7B@code Set%7D.%0A     *%0A     * @param network Network to register/add.%0A     */%0A    public static void register(NetworkParameters network) %7B%0A        register(Lists.newArrayList(network));%0A    %7D%0A%0A    /**%0A     * Register a collection of additional network types by adding them%0A     * to the %7B@code Set%7D.%0A     *%0A     * @param networks Networks to register/add.%0A     */
 %0A   
@@ -2320,24 +2320,138 @@
 d();%0A    %7D%0A%0A
+    /**%0A     * Unregister a network type.%0A     *%0A     * @param network Network type to unregister/remove.%0A     */%0A
     public s

Improve JavaDocs.