/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the cole Normale Suprieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.util;

/**
 * Utilitity class.
 * @author Laurent jourdren
 */
public final class NividicUtils {

  /**
   * Do nothing.
   */
  public static void nop() {
  }

  /**
   * yeild the process.
   */
  public static void yield() {

    while (true) {
      Thread.yield();
    }
  }

  /**
   * Test if two array of string are equals.
   * @param a First array of string to test
   * @param b Second array of string to test
   * @return true if the two array of string are equals, false if not
   */
  public static boolean stringsEquals(final String[] a, final String[] b) {

    if (a == null && b == null)
      return true;
    if (a == null || b == null)
      return false;

    if (a.length != b.length)
      return false;

    for (int i = 0; i < a.length; i++) {

      if (a[i] == null && b[i] != null)
        return false;
      if (!a[i].equals(b[i]))
        return false;
    }

    return true;
  }

  /**
   * Test if two array of integers are equals.
   * @param a First array of integers to test
   * @param b Second array of integer to test
   * @return true if the two array of integers are equals, false if not
   */
  public static boolean intsEquals(final int[] a, final int[] b) {

    if (a == null && b == null)
      return true;
    if (a == null || b == null)
      return false;

    if (a.length != b.length)
      return false;

    for (int i = 0; i < a.length; i++)
      if (a[i] != b[i])
        return false;

    return true;
  }

  /**
   * converts an array of double in an array of int.
   * @param array Array of double to convert
   * @return an array of int
   */
  public static int[] arrayDoubleToArrayInt(final double[] array) {

    if (array == null)
      return null;

    final int[] result = new int[array.length];
    final int n = array.length;

    for (int i = 0; i < n; i++) {
      result[i] = (int) array[i];
    }

    return result;
  }

  /**
   * converts an array of int in an array of double.
   * @param array Array of int to convert
   * @return an array of double
   */
  public static double[] arrayIntToArrayDouble(final int[] array) {

    if (array == null)
      return null;

    final double[] result = new double[array.length];
    final int n = array.length;

    for (int i = 0; i < n; i++) {
      result[i] = array[i];
    }

    return result;
  }

  //
  // Constructor
  //

  /**
   * Private constructor.
   */
  private NividicUtils() {
  }

}
@@ -713,16 +713,105 @@
 .util;%0A%0A
+import java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0A
 /**%0A * U
@@ -3125,16 +3125,1225 @@
 t;%0A  %7D%0A%0A
+  /**%0A   * Test if two stream are equals%0A   * @param a First stream to compare%0A   * @param b Second stream to compare%0A   * @return true if the two stream are equals%0A   * @throws IOException if an error occors while reading the streams%0A   */%0A  public static boolean compareFile(final InputStream a, final InputStream b)%0A      throws IOException %7B%0A%0A    if (a == null && b == null)%0A      return true;%0A    if (a == null %7C%7C b == null)%0A      return false;%0A%0A    boolean end = false;%0A    boolean result = true;%0A%0A    while (!end) %7B%0A%0A      int ca = a.read();%0A      int cb = b.read();%0A%0A      if (ca != cb) %7B%0A        result = false;%0A        end = true;%0A      %7D%0A%0A      if (ca == -1)%0A        end = true;%0A%0A    %7D%0A%0A    a.close();%0A    b.close();%0A%0A    return result;%0A  %7D%0A%0A  /**%0A   * Test if two stream are equals%0A   * @param a First filename to compare%0A   * @param b Second filename to compare%0A   * @return true if the two stream are equals%0A   * @throws IOException if an error occors while reading the streams%0A   */%0A  public static boolean compareFile(final String filenameA, final String filenameB)%0A      throws Exception %7B%0A    return compareFile(new FileInputStream(filenameA), new FileInputStream(%0A        filenameB));%0A  %7D%0A%0A
   //%0A  /

add new methods to compare streams