PactRecord implements Value { public void addField(Value value) { final int num = this.numFields; setNumFields(num + 1); internallySetField(num, value); } PactRecord();  PactRecord(Value value);  PactRecord(Value val1, Value val2);  PactRecord(int numFields); int getNumFields(); void setNumFields(final int numFields); void makeSpace(int numFields); @SuppressWarnings("unchecked") T getField(final int fieldNum, final Class<T> type); @SuppressWarnings("unchecked") T getField(int fieldNum, T target); boolean getFieldInto(int fieldNum, Value target); boolean getFieldsInto(int[] positions, Value[] targets); void getFieldsIntoCheckingNull(int[] positions, Value[] targets); void setField(int fieldNum, Value value); void addField(Value value); final boolean isNull(int fieldNum); void setNull(int field); void setNull(long mask); void setNull(long[] mask); void clear(); void concatenate(PactRecord record); void unionFields(PactRecord other); void copyToIfModified(PactRecord target); void copyTo(PactRecord target); PactRecord createCopy(); final boolean equalsFields(int[] positions, Value[] searchValues, Value[] deserializationHolders); void updateBinaryRepresenation(); @Override void write(DataOutput out); @Override void read(DataInput in); long serialize(DataOutputView target); void deserialize(DataInputView source);  }
@Test public void testAddField() { try { PactRecord record = new PactRecord(); assertTrue(record.getNumFields() == 0); record.addField(this.origVal1); assertTrue(record.getNumFields() == 1); assertTrue(origVal1.getValue().equals(record.getField(0, PactString.class).getValue())); record = new PactRecord(); for (int i = 0; i < 100; i++) { PactInteger orig = new PactInteger(this.rand.nextInt()); record.addField(orig); PactInteger rec = record.getField(i, PactInteger.class); assertTrue(record.getNumFields() == i + 1); assertTrue(orig.getValue() == rec.getValue()); } record = new PactRecord(this.origVal1, this.origVal2); record.addField(this.origVal3); assertTrue(record.getNumFields() == 3); PactString recVal1 = record.getField(0, PactString.class); PactDouble recVal2 = record.getField(1, PactDouble.class); PactInteger recVal3 = record.getField(2, PactInteger.class); assertTrue("The value of the first field has changed", recVal1.equals(this.origVal1)); assertTrue("The value of the second field changed", recVal2.equals(this.origVal2)); assertTrue("The value of the third field has changed", recVal3.equals(this.origVal3)); } catch (Throwable t) { Assert.fail("Test failed due to an exception: " + t.getMessage()); } }