/** 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;
 }
 public String[] getTupleValues() {
   if (gaggleTuple == null) {
     System.out.println("The R Goose has not received a Tuple broadcast.");
     return new String[0];
   }
   List<String> values = new ArrayList<String>();
   for (int i = 0; i < gaggleTuple.getData().getSingleList().size(); i++) {
     Tuple tuple = (Tuple) gaggleTuple.getData().getSingleAt(i).getValue();
     String str = (String) tuple.getSingleAt(2).getValue();
     values.add(str);
   }
   return values.toArray(new String[0]);
 }
 public String getTupleTitle() {
   if (gaggleTuple == null) {
     System.out.println("The R Goose has not received a Tuple broadcast.");
     return "";
   }
   return gaggleTuple.getName();
 }
 public String getTupleAttributeName() {
   if (gaggleTuple == null) {
     System.out.println("The R Goose has not received a Tuple broadcast.");
     return "";
   }
   return (String) gaggleTuple.getMetadata().getSingleAt(0).getValue();
 }
 public Tuple getTuple() {
   if (gaggleTuple == null) {
     System.out.println("The R Goose has not received a Tuple broadcast.");
     return null;
   }
   return gaggleTuple.getData();
 }
 public void broadcastGaggleTuple(GaggleTuple gaggleTuple) {
   gaggleTuple.setSpecies(defaultSpecies);
   try {
     gaggleBoss.broadcastTuple(myGaggleName, targetGoose, gaggleTuple);
   } catch (RemoteException e) {
     System.err.println("error broadcasting network from RShellGoose " + myGaggleName);
     e.printStackTrace();
   }
 }
  // ----------------------------------------------------------------------------------------
  // 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);
  }
 // ----------------------------------------------------------------------------------------
 public void handleTuple(String source, GaggleTuple gaggleTuple) {
   System.out.println("tuple ready, " + gaggleTuple.getName());
   this.gaggleTuple = gaggleTuple;
   defaultSpecies = gaggleTuple.getSpecies();
 }