Пример #1
0
  /**
   * 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 = getPos(declarator, fields);

    for (int i = 0; i < pos.length; i++) internalSet(pos[i], tuple.getObject(i));
  }
Пример #2
0
  /**
   * Method setAll sets each element value of the given Tuple instance into the corresponding
   * position of this instance.
   *
   * @param tuple of type Tuple
   */
  public void setAll(Tuple tuple) {
    verifyModifiable();

    if (tuple == null) return;

    for (int i = 0; i < tuple.elements.size(); i++) internalSet(i, tuple.elements.get(i));
  }
Пример #3
0
  private void set(int[] pos, Type[] types, Tuple tuple, CoercibleType[] coercions) {
    verifyModifiable();

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

    int count = 0;

    for (int i : pos) {
      Object element = tuple.elements.get(count);

      if (types != null) {
        Type type = types[i];
        element = coercions[count].coerce(element, type);
      }

      elements.set(i, element);

      count++;
    }
  }
Пример #4
0
  /**
   * 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));
  }
Пример #5
0
  /**
   * 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++));
  }
Пример #6
0
  /**
   * 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;
  }
Пример #7
0
  /**
   * Method setAll sets each element value of the given Tuple instances into the corresponding
   * position of this instance.
   *
   * <p>All given tuple instances after the first will be offset by the length of the prior tuple
   * instances.
   *
   * @param tuples of type Tuple[]
   */
  public void setAll(Tuple... tuples) {
    verifyModifiable();

    if (tuples.length == 0) return;

    int pos = 0;
    for (int i = 0; i < tuples.length; i++) {
      Tuple tuple = tuples[i];

      if (tuple == null) // being defensive
      continue;

      for (int j = 0; j < tuple.elements.size(); j++) internalSet(pos++, tuple.elements.get(j));
    }
  }
Пример #8
0
  /**
   * Method set sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type Comparable
   */
  public void set(int index, Comparable value) {
    verifyModifiable();

    try {
      elements.set(index, value);
    } catch (IndexOutOfBoundsException exception) {
      if (elements.size() != 0)
        throw new TupleException(
            "failed to set a value beyond the end of the tuple elements array, size: "
                + size()
                + " , index: "
                + index);
      else
        throw new TupleException(
            "failed to set a value, tuple may not be initialized with values, is zero length");
    }
  }
Пример #9
0
  /**
   * Method remove removes the values specified by the given pos array and returns a new Tuple
   * containing the removed values.
   *
   * @param pos of type int[]
   * @return Tuple
   */
  public Tuple remove(int[] pos) {
    verifyModifiable();

    // calculate offsets to apply when removing values from elements
    int offset[] = new int[pos.length];

    for (int i = 0; i < pos.length; i++) {
      offset[i] = 0;

      for (int j = 0; j < i; j++) {
        if (pos[j] < pos[i]) offset[i]++;
      }
    }

    Tuple results = new Tuple();

    for (int i = 0; i < pos.length; i++) results.add(elements.remove(pos[i] - offset[i]));

    return results;
  }
Пример #10
0
  /**
   * Method addBoolean adds a new element value to this instance.
   *
   * @param value of type boolean
   */
  public void addBoolean(boolean value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #11
0
  /**
   * Method addShort adds a new element value to this instance.
   *
   * @param value of type short
   */
  public void addShort(short value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #12
0
  /**
   * Method setString sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type String
   */
  public void setString(int index, String value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #13
0
  /**
   * Method setDouble sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type double
   */
  public void setDouble(int index, double value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #14
0
  /**
   * Method addFloat adds a new element value to this instance.
   *
   * @param value of type float
   */
  public void addFloat(float value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #15
0
  /**
   * Method addAll adds all given values to this instance.
   *
   * @param values of type Comparable...
   */
  public void addAll(Comparable... values) {
    verifyModifiable();

    if (values.length == 1 && values[0] instanceof Tuple) addAll((Tuple) values[0]);
    else Collections.addAll(elements, values);
  }
Пример #16
0
  /**
   * Method setBoolean sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type boolean
   */
  public void setBoolean(int index, boolean value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #17
0
  /**
   * Method set sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type Object
   */
  public void set(int index, Object value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #18
0
  /**
   * Method addInteger adds a new element value to this instance.
   *
   * @param value of type int
   */
  public void addInteger(int value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #19
0
  /**
   * Method addString adds a new element value to this instance.
   *
   * @param value of type String
   */
  public void addString(String value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #20
0
  /**
   * Method addDouble adds a new element value to this instance.
   *
   * @param value of type double
   */
  public void addDouble(double value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #21
0
  /**
   * Method add adds a new element value to this instance.
   *
   * @param value of type Comparable
   */
  public void add(Comparable value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #22
0
  /**
   * Method add adds a new element value to this instance.
   *
   * @param value of type Object
   */
  public void add(Object value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #23
0
  /**
   * Method addAll adds all the element values of the given Tuple instance to this instance.
   *
   * @param tuple of type Tuple
   */
  public void addAll(Tuple tuple) {
    verifyModifiable();

    if (tuple != null) elements.addAll(tuple.elements);
  }
Пример #24
0
  /**
   * Method setFloat sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type float
   */
  public void setFloat(int index, float value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #25
0
  /**
   * Method setShort sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type short
   */
  public void setShort(int index, short value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #26
0
  /**
   * Method addLong adds a new element value to this instance.
   *
   * @param value of type long
   */
  public void addLong(long value) {
    verifyModifiable();

    elements.add(value);
  }
Пример #27
0
  /**
   * Method setInteger sets the given value to the given index position in this instance.
   *
   * @param index of type int
   * @param value of type int
   */
  public void setInteger(int index, int value) {
    verifyModifiable();

    internalSet(index, value);
  }
Пример #28
0
  /**
   * Method clear empties this Tuple instance. A subsequent call to {@link #size()} will return zero
   * ({@code 0}).
   */
  public void clear() {
    verifyModifiable();

    elements.clear();
  }