package com.aldebaran.qimessaging;

import java.lang.reflect.Field;

/*
 * QiMessaging Tuple implementation.
 * Created to avoid Objects list, Tuple ensures type safety in QiMessaging calls.
 * Warning : Maximum size is limited to 8 elements.
 */
public abstract class Tuple
{

  @SuppressWarnings("unchecked")
  public <T> T get(int index) throws IndexOutOfBoundsException, ClassCastException, IllegalArgumentException, IllegalAccessException
  {
    Field[] fields = this.getClass().getFields();

    if (index < fields.length)
    {
      java.lang.Object t = fields[index].get(this);
      return (T) t;
    }

    throw new IndexOutOfBoundsException("No " + index + " index in " + fields.length + " elements tuple");
  }

  public <T> void set(int index, T value) throws IllegalArgumentException, IllegalAccessException
  {
    Field[] fields = this.getClass().getFields();
    if (index < fields.length)
      fields[index].set(this, (T) value);
  }

  public final int size()
  {
    return this.getClass().getFields().length;
  }

  public final String toString()
  {
    Field[] fields = this.getClass().getFields();
    int index = 0;

    String ret = "(";
    while (index < fields.length)
    {
      java.lang.Object t;
      try
      {
        t = fields[index].get(this);
      } catch (Exception e)
      {
        return "()";
      }

      ret += t.toString();
      if (index + 1 != fields.length)
        ret += ", ";

      index++;
    }

    ret += ")";
    return ret;

  }
}

@@ -64,17 +64,18 @@
 eld;%0A%0A/*
+*
 %0A
-
  * QiMes
@@ -237,16 +237,36 @@
 ements.%0A
+ * @author proullon%0A
  */%0Apubl
@@ -292,16 +292,1226 @@
 uple%0A%7B%0A%0A
+  /**%0A   * Tuple factory.%0A   * @param objs is a variadic list of tuple member%0A   * @return an implemented tuple behind Tuple interface.%0A   */%0A  @SuppressWarnings(%7B %22rawtypes%22, %22unchecked%22 %7D)%0A  public static Tuple makeTuple(java.lang.Object ... objs)%0A  %7B%0A    switch (objs.length)%0A    %7B%0A    case 1:%0A      return new Tuple1(objs%5B0%5D);%0A    case 2:%0A      return new Tuple2(objs%5B0%5D, objs%5B1%5D);%0A    case 3:%0A      return new Tuple3(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D);%0A    case 4:%0A      return new Tuple4(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D, objs%5B3%5D);%0A    case 5:%0A      return new Tuple5(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D, objs%5B3%5D, objs%5B4%5D);%0A    case 6:%0A      return new Tuple6(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D, objs%5B3%5D, objs%5B4%5D, objs%5B5%5D);%0A    case 7:%0A      return new Tuple7(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D, objs%5B3%5D, objs%5B4%5D, objs%5B5%5D, objs%5B6%5D);%0A    case 8:%0A      return new Tuple8(objs%5B0%5D, objs%5B1%5D, objs%5B2%5D, objs%5B3%5D, objs%5B4%5D, objs%5B5%5D, objs%5B6%5D, objs%5B7%5D);%0A    %7D%0A%0A    return null;%0A  %7D%0A%0A  /**%0A   * Tuple getter.%0A   * @param index%0A   * @return%0A   * @throws IndexOutOfBoundsException if index is unknown%0A   * @throws ClassCastException if given parameter does not fit in tuple element%0A   * @throws IllegalArgumentException%0A   * @throws IllegalAccessException%0A   */%0A
   @Suppr
@@ -1943,32 +1943,173 @@
 s tuple%22);%0A  %7D%0A%0A
+  /**%0A   * Tuple setter.%0A   * @param index%0A   * @param value%0A   * @throws IllegalArgumentException%0A   * @throws IllegalAccessException%0A   */%0A
   public %3CT%3E voi
@@ -2318,24 +2318,105 @@
 alue);%0A  %7D%0A%0A
+  /**%0A   * Return the number of elements in tuple.%0A   * @return tuple size%0A   */%0A
   public fin
@@ -2485,16 +2485,64 @@
 h;%0A  %7D%0A%0A
+  /**%0A   * Fancy representation of tuple.%0A   */%0A
   public

Add tuple factory and fix tuple doc.