/** * 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)); }
/** * 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)); }
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++; } }
/** * 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)); }
/** * 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++)); }
/** * 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; }
/** * 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)); } }
/** * 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"); } }
/** * 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; }
/** * Method addBoolean adds a new element value to this instance. * * @param value of type boolean */ public void addBoolean(boolean value) { verifyModifiable(); elements.add(value); }
/** * Method addShort adds a new element value to this instance. * * @param value of type short */ public void addShort(short value) { verifyModifiable(); elements.add(value); }
/** * 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); }
/** * 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); }
/** * Method addFloat adds a new element value to this instance. * * @param value of type float */ public void addFloat(float value) { verifyModifiable(); elements.add(value); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Method addInteger adds a new element value to this instance. * * @param value of type int */ public void addInteger(int value) { verifyModifiable(); elements.add(value); }
/** * Method addString adds a new element value to this instance. * * @param value of type String */ public void addString(String value) { verifyModifiable(); elements.add(value); }
/** * Method addDouble adds a new element value to this instance. * * @param value of type double */ public void addDouble(double value) { verifyModifiable(); elements.add(value); }
/** * Method add adds a new element value to this instance. * * @param value of type Comparable */ public void add(Comparable value) { verifyModifiable(); elements.add(value); }
/** * Method add adds a new element value to this instance. * * @param value of type Object */ public void add(Object value) { verifyModifiable(); elements.add(value); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Method addLong adds a new element value to this instance. * * @param value of type long */ public void addLong(long value) { verifyModifiable(); elements.add(value); }
/** * 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); }
/** * Method clear empties this Tuple instance. A subsequent call to {@link #size()} will return zero * ({@code 0}). */ public void clear() { verifyModifiable(); elements.clear(); }