// Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
// 
//   private CodingUtils() {}
//   
//   /**
//    * Encodes the given {@link String} in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(String data) {
//     return encodeBase2(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(byte[] data) {
//     return encodeBase2(data, 0, data.length);
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(byte[] data, int offset, int length) {
//     return StringUtils.toString(Base2.encodeBase2(data, offset, length));
//   }
// 
//   /**
//    * Encodes the given {@link String} in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(String data) {
//     return encodeBase16(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(byte[] data) {
//     return encodeBase16(data, 0, data.length);
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(byte[] data, int offset, int length) {
//     return StringUtils.toString(Base16.encodeBase16(data, offset, length));
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded {@link String}.
//    */
//   public static byte[] decodeBase16(String data) {
//     return decodeBase16(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded value.
//    */
//   public static byte[] decodeBase16(byte[] data) {
//     return decodeBase16(data, 0, data.length);
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded value.
//    */
//   public static byte[] decodeBase16(byte[] data, int offset, int length) {
//     return Base16.decodeBase16(data, offset, length);
//   }
// }
// 
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
// 
//   private Precoditions() {}
//   
//   public static void argument(boolean expression) {
//     if (!expression) {
//       throw new IllegalArgumentException();
//     }
//   }
//   
//   public static void argument(boolean expression, String message) {
//     if (!expression) {
//       throw new IllegalArgumentException(message);
//     }
//   }
// 
//   public static void argument(boolean expression, 
//       String message, Object... arguments) {
//     if (!expression) {
//       throw new IllegalArgumentException(String.format(message, arguments));
//     }
//   }
// 
//   /**
//    * Makes sure the given argument is not {@code null}.
//    */
//   public static <T> T notNull(T t) {
//     return notNull(t, null);
//   }
//   
//   /**
//    * Makes sure the given argument is not {@code null}.
//    */
//   public static <T> T notNull(T t, String message) {
//     if (t == null) {
//       if (message != null) {
//         throw new NullPointerException(message);
//       }
//       throw new NullPointerException();
//     }
//     return t;
//   }
// }
// 
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
// 
//   private static final long serialVersionUID = 6625000716332463624L;
// 
//   public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//   
//   @Override
//   public int compare(byte[] o1, byte[] o2) {
//     if (o1.length != o2.length) {
//       return o1.length - o2.length;
//     }
//     
//     for (int i = 0; i < o1.length; i++) {
//       int diff = Bytes.compareUnsigned(o1[i], o2[i]);
//       if (diff != 0) {
//         return diff;
//       }
//     }
// 
//     return 0;
//   }
// }


import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions;
/*
 * Copyright 2010-2012 Roger Kapsi
 *
 *   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.ardverk.net;



/**
 * A special purpose counter that counts {@link InetAddress}es 
 * by their network class.
 */
public class NetworkCounter implements Serializable {
  
  private static final long serialVersionUID = -7103271018736085248L;

  private final NetworkMask mask;
  
  private final Map<byte[], AtomicInteger> map 
    = new TreeMap<byte[], AtomicInteger>(
// Path: src/main/java/org/ardverk/coding/CodingUtils.java
// public class CodingUtils {
// 
//   private CodingUtils() {}
//   
//   /**
//    * Encodes the given {@link String} in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(String data) {
//     return encodeBase2(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(byte[] data) {
//     return encodeBase2(data, 0, data.length);
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-2 (binary) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase2(byte[] data, int offset, int length) {
//     return StringUtils.toString(Base2.encodeBase2(data, offset, length));
//   }
// 
//   /**
//    * Encodes the given {@link String} in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(String data) {
//     return encodeBase16(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(byte[] data) {
//     return encodeBase16(data, 0, data.length);
//   }
//   
//   /**
//    * Encodes the given byte-array in Base-16 (hex) and returns it 
//    * as a {@link String}.
//    */
//   public static String encodeBase16(byte[] data, int offset, int length) {
//     return StringUtils.toString(Base16.encodeBase16(data, offset, length));
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded {@link String}.
//    */
//   public static byte[] decodeBase16(String data) {
//     return decodeBase16(StringUtils.getBytes(data));
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded value.
//    */
//   public static byte[] decodeBase16(byte[] data) {
//     return decodeBase16(data, 0, data.length);
//   }
//   
//   /**
//    * Decodes a Base-16 (hex) encoded value.
//    */
//   public static byte[] decodeBase16(byte[] data, int offset, int length) {
//     return Base16.decodeBase16(data, offset, length);
//   }
// }
// 
// Path: src/main/java/org/ardverk/lang/Precoditions.java
// public class Precoditions {
// 
//   private Precoditions() {}
//   
//   public static void argument(boolean expression) {
//     if (!expression) {
//       throw new IllegalArgumentException();
//     }
//   }
//   
//   public static void argument(boolean expression, String message) {
//     if (!expression) {
//       throw new IllegalArgumentException(message);
//     }
//   }
// 
//   public static void argument(boolean expression, 
//       String message, Object... arguments) {
//     if (!expression) {
//       throw new IllegalArgumentException(String.format(message, arguments));
//     }
//   }
// 
//   /**
//    * Makes sure the given argument is not {@code null}.
//    */
//   public static <T> T notNull(T t) {
//     return notNull(t, null);
//   }
//   
//   /**
//    * Makes sure the given argument is not {@code null}.
//    */
//   public static <T> T notNull(T t, String message) {
//     if (t == null) {
//       if (message != null) {
//         throw new NullPointerException(message);
//       }
//       throw new NullPointerException();
//     }
//     return t;
//   }
// }
// 
// Path: src/main/java/org/ardverk/utils/ByteArrayComparator.java
// public class ByteArrayComparator implements Comparator<byte[]>, Serializable {
// 
//   private static final long serialVersionUID = 6625000716332463624L;
// 
//   public static final ByteArrayComparator COMPARATOR = new ByteArrayComparator();
//   
//   @Override
//   public int compare(byte[] o1, byte[] o2) {
//     if (o1.length != o2.length) {
//       return o1.length - o2.length;
//     }
//     
//     for (int i = 0; i < o1.length; i++) {
//       int diff = Bytes.compareUnsigned(o1[i], o2[i]);
//       if (diff != 0) {
//         return diff;
//       }
//     }
// 
//     return 0;
//   }
// }


// Path: src/main/java/org/ardverk/net/NetworkCounter.java
import org.ardverk.utils.ByteArrayComparator;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import org.ardverk.coding.CodingUtils;
import org.ardverk.lang.Precoditions;

/*
 * Copyright 2010-2012 Roger Kapsi
 *
 *   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.ardverk.net;



/**
 * A special purpose counter that counts {@link InetAddress}es 
 * by their network class.
 */
public class NetworkCounter implements Serializable {
  
  private static final long serialVersionUID = -7103271018736085248L;

  private final NetworkMask mask;
  
  private final Map<byte[], AtomicInteger> map 
    = new TreeMap<byte[], AtomicInteger>(
      ByteArrayComparator.COMPARATOR);