コード例 #1
0
ファイル: GMS.java プロジェクト: jtoerber/JGroups
 @ManagedOperation
 public String printPreviousViews() {
   StringBuilder sb = new StringBuilder();
   for (Tuple<View, Long> tmp : prev_views)
     sb.append(new Date(tmp.getVal2())).append(": ").append(tmp.getVal1()).append("\n");
   return sb.toString();
 }
コード例 #2
0
ファイル: enumerate.java プロジェクト: barry800414/USM
 public static List<AttrPack> expand(AttrPack attr) {
   char node_type_list[] = new char[4];
   List<Integer> rimo_path = getRightMostPath(attr.getPath());
   // List<Integer> rimo_path = getRightMostPath(debug);
   // List<Tuple> cand = rightMostExpand(debug);
   List<Tuple> cand = rightMostExpand(attr.getPath());
   char[] path_label = new char[rimo_path.size() + 1];
   int[] path_index = new int[rimo_path.size()];
   for (int i = 0; i < rimo_path.size(); i++) {
     path_index[i] = rimo_path.get(i);
     path_label[i] = attr.getPath().get(path_index[i]).getLabel();
   }
   path_label[rimo_path.size()] = 0;
   List<AttrPack> next_iter = new ArrayList();
   if (attr.getPathIndex() == -1) {
     for (Tuple tup : cand) {
       int d_ = tup.getDepth();
       char l_ = tup.getLabel();
       if (l_ == path_label[d_]) {
         ArrayList<Tuple> tmp_path = new ArrayList(attr.getPath());
         tmp_path.add(new Tuple(d_, l_));
         next_iter.add(new AttrPack(tmp_path, path_index[d_]));
       }
       if (l_ > path_label[d_]) {
         ArrayList<Tuple> tmp_path = new ArrayList(attr.getPath());
         tmp_path.add(new Tuple(d_, l_));
         next_iter.add(new AttrPack(tmp_path, -1));
       }
     }
   } else {
     int prefix = attr.getPathIndex() + 1;
     Tuple prf_tup = attr.getPath().get(prefix);
     {
       ArrayList<Tuple> tmp_path = new ArrayList(attr.getPath());
       tmp_path.add(prf_tup);
       next_iter.add(new AttrPack(tmp_path, prefix));
     }
     for (Tuple tup : cand) {
       int d_ = tup.getDepth();
       char l_ = tup.getLabel();
       if (d_ > prf_tup.getDepth()) {
         continue;
       }
       if (d_ == prf_tup.getDepth() && l_ >= prf_tup.getLabel()) {
         continue;
       }
       if (l_ == path_label[d_]) {
         ArrayList<Tuple> tmp_path = new ArrayList(attr.getPath());
         tmp_path.add(new Tuple(d_, l_));
         next_iter.add(new AttrPack(tmp_path, path_index[d_]));
       }
       if (l_ > path_label[d_]) {
         ArrayList<Tuple> tmp_path = new ArrayList(attr.getPath());
         tmp_path.add(new Tuple(d_, l_));
         next_iter.add(new AttrPack(tmp_path, -1));
       }
     }
   }
   return next_iter;
 }
コード例 #3
0
  /** Suck up tuples from the source file. */
  private Tuple readNextTuple(DataInputStream dis, int slotId) throws NoSuchElementException {
    // if associated bit is not set, read forward to the next tuple, and
    // return null.
    if (!getSlot(slotId)) {
      for (int i = 0; i < td.getSize(); i++) {
        try {
          dis.readByte();
        } catch (IOException e) {
          throw new NoSuchElementException("error reading empty tuple");
        }
      }
      return null;
    }

    // read fields in the tuple
    Tuple t = new Tuple(td);
    RecordID rid = new RecordID(pid, slotId);
    t.setRecordID(rid);
    try {
      for (int j = 0; j < td.numFields(); j++) {
        Field f = td.getType(j).parse(dis);
        t.setField(j, f);
      }
    } catch (java.text.ParseException e) {
      // e.printStackTrace();
      throw new NoSuchElementException("parsing error!");
    }

    return t;
  }
コード例 #4
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Creates a new Tuple from the given positions, but sets the values in the current tuple to null.
   *
   * @param pos of type int[]
   * @return Tuple
   */
  Tuple extract(int[] pos) {
    Tuple results = new Tuple();

    for (int i : pos) results.add(elements.set(i, null));

    return results;
  }
コード例 #5
0
  /**
   * Create a DbIterator over group aggregate results.
   *
   * @return a DbIterator whose tuples are the pair (groupVal, aggregateVal) if using group, or a
   *     single (aggregateVal) if no grouping. The aggregateVal is determined by the type of
   *     aggregate specified in the constructor.
   */
  public DbIterator iterator() {
    /* TODO: write about iterator() call recalculates all the aggregates, which seems necessary given how the test case is formulated
    (merge one tuple, get iterator, expect the result to be updated). Note that recalculate is not necessary unless the source tuples
    change, but as a simplification here we implement it like this. */
    TupleDesc td;
    ArrayList<Tuple> tuples = new ArrayList<Tuple>();

    if (isGrouping()) {
      Type[] typeAr = new Type[2];
      typeAr[0] = this.gbFieldType;
      typeAr[1] = Type.INT_TYPE;
      td = new TupleDesc(typeAr);

      for (Map.Entry<Field, ArrayList<IntField>> entry : this.tupleStorage.entrySet()) {
        IntField aggregate = this.getAggregate(entry.getValue());
        Tuple tup = new Tuple(td);
        tup.setField(0, entry.getKey());
        tup.setField(1, aggregate);
        tuples.add(tup);
      }
    } else {
      Type[] typeAr = new Type[1];
      typeAr[0] = Type.INT_TYPE;
      td = new TupleDesc(typeAr);

      Tuple tup = new Tuple(td);
      tup.setField(0, this.getAggregate(this.tupleStorageNoGrouping));
      tuples.add(tup);
    }

    TupleIterator iterator = new TupleIterator(td, tuples);
    return iterator;
  }
コード例 #6
0
  @Override
  protected void doHadoopWork() throws BuildException {
    Tuple tuple = ContextManager.getCurrentTuple();
    if (tuple == null) {
      throw new BuildException(
          this.getTaskName()
              + " should be put inside task container which provides tuple to execution context");
    }

    try {
      if (tuple.getType(fieldNumber) != DataType.TUPLE
          || !(tuple.get(fieldNumber) instanceof Tuple)) {
        throw new BuildException("Tuple field " + fieldNumber + " doesn't represent a Tuple");
      }

      ContextManager.setCurrentTupleContext((Tuple) tuple.get(fieldNumber));

      try {
        for (Task task : tasks) {
          task.perform();
        }
      } finally {
        ContextManager.resetCurrentTupleContext();
      }
    } catch (ExecException e) {
      throw new BuildException("Failed to check type of tuple field " + fieldNumber, e);
    }
  }
コード例 #7
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method append appends all the values of the given Tuple instances to a copy of this instance.
   *
   * @param tuples of type Tuple
   * @return Tuple
   */
  public Tuple append(Tuple... tuples) {
    Tuple result = new Tuple(this);

    for (Tuple tuple : tuples) result.addAll(tuple);

    return result;
  }
コード例 #8
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method size returns a new Tuple instance of the given size with the given Comparable as its
   * element values.
   *
   * @param size of type int
   * @param value of type Comparable
   * @return Tuple
   */
  public static Tuple size(int size, Comparable value) {
    Tuple result = new Tuple();

    for (int i = 0; i < size; i++) result.add(value);

    return result;
  }
コード例 #9
0
ファイル: enumerate.java プロジェクト: barry800414/USM
 public String toString() {
   String str = new String();
   for (Tuple tup : this.path) {
     str += tup.toString();
   }
   str += "; " + String.valueOf(this.path_index);
   return str;
 }
コード例 #10
0
ファイル: Tuple.java プロジェクト: robweller8/sdesign_gamma
 // this constructor unserializes a string into a tuple
 public static Tuple makeTupleFromPipeData(String line) {
   StringTokenizer st = new StringTokenizer(line, separator, false);
   int size = Integer.parseInt(st.nextToken());
   Tuple t = new Tuple(size);
   int fieldNumber = 0;
   while (st.hasMoreTokens()) t.set(fieldNumber++, st.nextToken());
   return t;
 }
コード例 #11
0
ファイル: Tuple.java プロジェクト: robweller8/sdesign_gamma
 // this constructor unserializes a string into a tuple
 public static Tuple makeTupleFromFileData(Relation r, String line) {
   StringTokenizer st = new StringTokenizer(line);
   int size = r.getSize();
   Tuple t = new Tuple(size);
   int fieldNumber = 0;
   while (st.hasMoreTokens()) t.set(fieldNumber++, st.nextToken());
   return t;
 }
コード例 #12
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method get will return a new Tuple instace populated with element values from the given array
   * of positions.
   *
   * @param pos of type int[]
   * @return Tuple
   */
  public Tuple get(int[] pos) {
    if (pos == null || pos.length == 0) return new Tuple(this);

    Tuple results = new Tuple();

    for (int i : pos) results.add(elements.get(i));

    return results;
  }
コード例 #13
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Sets the values in the given positions to the values from the given Tuple.
   *
   * @param pos of type int[]
   * @param tuple of type Tuple
   */
  void set(int[] pos, Tuple tuple) {
    verifyModifiable();

    if (pos.length != tuple.size())
      throw new TupleException(
          "given tuple not same size as position array, tuple: " + tuple.print());

    int count = 0;
    for (int i : pos) elements.set(i, tuple.elements.get(count++));
  }
コード例 #14
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method is the inverse of {@link #remove(int[])}.
   *
   * @param pos of type int[]
   * @return Tuple
   */
  public Tuple leave(int[] pos) {
    verifyModifiable();

    Tuple results = remove(pos);

    List<Comparable> temp = results.elements;
    results.elements = this.elements;
    this.elements = temp;

    return results;
  }
コード例 #15
0
 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;
 }
コード例 #16
0
 protected void addMetaDataToNetwork(Network network) {
   if (networkMetadata.size() == 0) {
     return;
   }
   Tuple metadata = new Tuple();
   Set<String> keys = networkMetadata.keySet();
   for (Iterator<String> it = keys.iterator(); it.hasNext(); ) {
     String key = it.next();
     metadata.addSingle(new Single(key, networkMetadata.get(key)));
   }
   network.setMetadata(metadata);
 }
コード例 #17
0
ファイル: TableStats.java プロジェクト: tenn-cn/CS186-1
  /**
   * Create a new TableStats object, that keeps track of statistics on each column of a table
   *
   * @param tableid The table over which to compute statistics
   * @param ioCostPerPage The cost per page of IO. This doesn't differentiate between
   *     sequential-scan IO and disk seeks.
   */
  public TableStats(int tableid, int ioCostPerPage) {
    // For this function, we use the DbFile for the table in question,
    // then scan through its tuples and calculate the values that you
    // to build the histograms.

    // TODO: Fill out the rest of the constructor.
    // Feel free to change anything already written, it's only a guideline

    this.ioCostPerPage = ioCostPerPage;
    DbFile file = Database.getCatalog().getDbFile(tableid);
    tupleDesc = file.getTupleDesc();
    numPages = ((HeapFile) file).numPages();
    numTuples = 0;

    int numFields = tupleDesc.numFields();

    // TODO: what goes here?
    statistics = new ArrayList<Object>();

    for (int i = 0; i < numFields; i++) {
      if (Type.INT_TYPE.equals(tupleDesc.getFieldType(i))) {
        statistics.add(new IntStatistics(NUM_HIST_BINS));
      } else {
        statistics.add(new StringHistogram(NUM_HIST_BINS));
      }
    }

    final DbFileIterator iter = file.iterator(null);
    try {
      iter.open();

      while (iter.hasNext()) {
        Tuple t = iter.next();
        numTuples++;

        // TODO: and here?
        for (int i = 0; i < numFields; i++) {
          if (Type.INT_TYPE.equals(tupleDesc.getFieldType(i))) {
            ((IntStatistics) statistics.get(i)).addValue(((IntField) t.getField(i)).getValue());
          } else {
            ((StringHistogram) statistics.get(i))
                .addValue(((StringField) t.getField(i)).getValue());
          }
        }
      }
      iter.close();
    } catch (DbException e) {
      e.printStackTrace();
    } catch (TransactionAbortedException e) {
      e.printStackTrace();
    }
  }
コード例 #18
0
ファイル: enumerate.java プロジェクト: barry800414/USM
 public static List<Integer> getRightMostPath(List<Tuple> tup_list) {
   List<Integer> path = new ArrayList();
   int last_depth = -1;
   for (int i = 0; i < tup_list.size(); i++) {
     Tuple tup = tup_list.get(i);
     if (tup.getDepth() <= last_depth) {
       path = path.subList(0, tup.getDepth());
     }
     path.add(i);
     last_depth = tup.getDepth();
   }
   return path;
 }
コード例 #19
0
 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]);
 }
コード例 #20
0
 /**
  * Merge a new tuple into the aggregate, grouping as indicated in the constructor
  *
  * @param tup the Tuple containing an aggregate field and a group-by field
  */
 public void mergeTupleIntoGroup(Tuple tup) {
   if (isGrouping()) {
     Field gbValue = tup.getField(this.gbField);
     if (this.tupleStorage.containsKey(gbValue)) {
       this.tupleStorage.get(gbValue).add((IntField) tup.getField(this.aField));
     } else {
       this.tupleStorage.put(gbValue, new ArrayList<IntField>());
       this.tupleStorage.get(gbValue).add((IntField) tup.getField(this.aField));
     }
   } else {
     this.tupleStorageNoGrouping.add((IntField) tup.getField(this.aField));
   }
 }
コード例 #21
0
ファイル: Array.java プロジェクト: ruslansennov/javaslang
 @Override
 public Tuple2<Array<T>, Array<T>> splitAtInclusive(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   for (int i = 0; i < length(); i++) {
     final T value = get(i);
     if (predicate.test(value)) {
       if (i == length() - 1) {
         return Tuple.of(this, empty());
       } else {
         return Tuple.of(take(i + 1), drop(i + 1));
       }
     }
   }
   return Tuple.of(this, empty());
 }
コード例 #22
0
ファイル: Tuple.java プロジェクト: sgroschupf/cascading
  /**
   * Method put places the values of the given tuple into the positions specified by the fields
   * argument. The declarator Fields value declares the fields in this Tuple instance.
   *
   * @param declarator of type Fields
   * @param fields of type Fields
   * @param tuple of type Tuple
   */
  public void put(Fields declarator, Fields fields, Tuple tuple) {
    verifyModifiable();

    int[] pos = declarator.getPos(fields, size());

    for (int i = 0; i < pos.length; i++) elements.set(pos[i], tuple.get(i));
  }
コード例 #23
0
  @Test
  public void new_fieldsTest() {
    int length = 10;
    String name = "td";
    Tuple t = new Tuple(Utility.getTupleDesc(length, name));

    Iterator<Field> fs = t.fields();

    int i = 0;
    while (fs.hasNext()) {
      i++;
      fs.next();
    }

    assertEquals(length, i);
  }
コード例 #24
0
ファイル: TupleSpace.java プロジェクト: saurabhd14/tinyos-1.x
 public Tuple rdp(Tuple template) {
   for (int i = 0; i < ts.size(); i++) {
     Tuple tuple = (Tuple) ts.get(i);
     if (template.matches(tuple)) return tuple;
   }
   return null;
 }
コード例 #25
0
  /** Unit test for Tuple.getRecordId() and Tuple.setRecordId() */
  @Test
  public void modifyRecordId() {
    Tuple tup1 = new Tuple(Utility.getTupleDesc(1));
    HeapPageId pid1 = new HeapPageId(0, 0);
    RecordId rid1 = new RecordId(pid1, 0);
    tup1.setRecordId(rid1);

    try {
      assertEquals(rid1, tup1.getRecordId());
    } catch (java.lang.UnsupportedOperationException e) {
      // rethrow the exception with an explanation
      throw new UnsupportedOperationException(
          "modifyRecordId() test failed due to "
              + "RecordId.equals() not being implemented.  This is not required for Lab 1, "
              + "but should pass when you do implement the RecordId class.");
    }
  }
コード例 #26
0
 public void doAction() throws VisADException, RemoteException {
   Tuple tuple = (Tuple) ref.getData();
   float lon = (float) ((Real) tuple.getComponent(0)).getValue();
   float lat = (float) ((Real) tuple.getComponent(1)).getValue();
   RealTuple wind = (RealTuple) tuple.getComponent(2);
   float windx = (float) ((Real) wind.getComponent(0)).getValue();
   float windy = (float) ((Real) wind.getComponent(1)).getValue();
   System.out.println("wind = (" + windx + ", " + windy + ") at (" + +lat + ", " + lon + ")");
   /* a testing hack
       count--;
       if (count < 0) {
         count = 20;
         scale = 0.15f * 0.3f / scale;
         flow_control.setFlowScale(scale);
       }
   */
 }
コード例 #27
0
 /**
  * Adds the specified tuple to the page; the tuple should be updated to reflect that it is now
  * stored on this page.
  *
  * @throws DbException if the page is full (no empty slots) or tupledesc is mismatch.
  * @param t The tuple to add.
  */
 public void insertTuple(Tuple t) throws DbException {
   // some code goes here
   // not necessary for lab1
   RecordId targetrid = t.getRecordId();
   if (getNumEmptySlots() == 0 || !td.equals(t.getTupleDesc())) {
     throw new DbException("Either page is full or tuple desc doesn't match");
   }
   for (int i = 0; i < getNumTuples(); i++) {
     if (!isSlotUsed(i)) {
       markSlotUsed(i, true);
       RecordId rid = new RecordId(pid, i);
       t.setRecordId(rid);
       tuples[i] = t;
       return;
     }
   }
 }
コード例 #28
0
 /** 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);
 }
コード例 #29
0
ファイル: Array.java プロジェクト: ruslansennov/javaslang
 @Override
 public <T1, T2> Tuple2<Array<T1>, Array<T2>> unzip(
     Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) {
   Objects.requireNonNull(unzipper, "unzipper is null");
   if (isEmpty()) {
     return Tuple.of(empty(), empty());
   } else {
     final Object[] xs = new Object[length()];
     final Object[] ys = new Object[length()];
     for (int i = 0; i < length(); i++) {
       final Tuple2<? extends T1, ? extends T2> t = unzipper.apply(get(i));
       xs[i] = t._1;
       ys[i] = t._2;
     }
     return Tuple.of(wrap(xs), wrap(ys));
   }
 }
コード例 #30
0
ファイル: Tuple.java プロジェクト: robweller8/sdesign_gamma
 public static Tuple join(Tuple t1, Tuple t2, int joinkey1, int joinkey2) {
   Tuple t = new Tuple(t1.getSize() + t2.getSize() - 1);
   int fieldNumber = 0;
   for (String f1 : t1.getFields()) t.set(fieldNumber++, f1);
   for (String f2 : t2.getFields()) if (!t2.field[joinkey2].equals(f2)) t.set(fieldNumber++, f2);
   return t;
 }