/** Wrap a tuple in a GaggleTuple and broadcast it */
 public void broadcastTuple(Tuple tuple) {
   GaggleTuple gaggleTuple = new GaggleTuple();
   gaggleTuple.setName(tuple.getName());
   Tuple metadata = new Tuple();
   gaggleTuple.setMetadata(metadata);
   gaggleTuple.setData(tuple);
   broadcastGaggleTuple(gaggleTuple);
 }
 protected GaggleTuple createGaggleTupleForBroadcast(
     String tupleName, String[] names, Serializable[] values) {
   Tuple tuple = new Tuple();
   for (int i = 0; i < names.length; i++) {
     tuple.addSingle(new Single(names[i], values[i]));
   }
   GaggleTuple gaggleTuple = new GaggleTuple();
   gaggleTuple.setName(tupleName);
   gaggleTuple.setData(tuple);
   gaggleTuple.setSpecies(defaultSpecies);
   return gaggleTuple;
 }
  // ----------------------------------------------------------------------------------------
  // todo update method names (make sure calls in R side match)
  public void createAndBroadcastHashMap(
      String title, String attributeName, String[] names, double[] values) {

    GaggleTuple gaggleTuple = new GaggleTuple();
    gaggleTuple.setName(title);
    Tuple tuple = new Tuple(title);
    for (int i = 0; i <= names.length; i++) {
      tuple.addSingle(new Single(names[i], values[i]));
    }
    gaggleTuple.setData(tuple);
    gaggleTuple.setSpecies(defaultSpecies);

    try {
      gaggleBoss.broadcastTuple(myGaggleName, targetGoose, gaggleTuple);
    } catch (RemoteException rex) {
      System.err.println("error broadcasting hashmap from RShellGoose " + myGaggleName);
      rex.printStackTrace();
    }
  } // createAndBroadcastHashMap (double [] values)
  /**
   * Broadcasts a Cytoscape movie style tuple which assigns the value of a single attribute to the
   * nodes listed in allNames. [is this correct? -jcb]
   *
   * @param title
   * @param attributeName
   * @param allNames
   * @param allValues
   */
  public void createAndBroadcastGaggleTuple(
      String title, String attributeName, String[] allNames, String[] allValues) {

    Class valueClass = getValueType(allValues);
    GaggleTuple gaggleTuple = new GaggleTuple();
    gaggleTuple.setName(title);
    Tuple metadata = new Tuple();
    metadata.addSingle(new Single(title));
    gaggleTuple.setMetadata(metadata);
    Tuple dataTuple = new Tuple();
    dataTuple.setName(title);
    gaggleTuple.setSpecies(defaultSpecies);
    for (int i = 0; i < allNames.length; i++) {
      Serializable value;

      if (valueClass.equals(Integer.class)) {
        value = Integer.valueOf(allValues[i]);
      } else if (valueClass.equals(Double.class)) {
        value = Double.valueOf(allValues[i]);
      } else { // string
        String s = allValues[i];
        if (s.startsWith("|") && s.endsWith("|")) {
          value = s.substring(1, s.length() - 1);
        } else {
          value = allValues[i];
        }
      }

      Tuple row = new Tuple();
      row.addSingle(new Single(allNames[i]));
      row.addSingle(new Single(attributeName));
      row.addSingle(new Single(value));
      dataTuple.addSingle(new Single(row));
    }
    gaggleTuple.setData(dataTuple);
    broadcastGaggleTuple(gaggleTuple);
  }