@Test public void testCopy() throws CopyNotSupportedException { GenericRecord record = new GenericData.Record(new Schema.Parser().parse(AVRO_SCHEMA)); record.put("name", "foo"); record.put("favorite_number", 68); record.put("favorite_colors", Arrays.asList("blue", "black", "red")); CopyableGenericRecord copyableGenericRecord = new CopyableGenericRecord(record); GenericRecord copy = copyableGenericRecord.copy(); Assert.assertEquals(record, copy); copy.put("name", "bar"); Assert.assertNotEquals(record, copy); }
@Override public GenericRecord copy() throws CopyNotSupportedException { if (!(this.record instanceof GenericData.Record)) { throw new CopyNotSupportedException( "The record to make copy is not an instance of " + GenericData.Record.class.getName()); } return new GenericData.Record((GenericData.Record) this.record, true); }
CopyableGenericRecord implements Copyable<GenericRecord> { @Override public GenericRecord copy() throws CopyNotSupportedException { if (!(this.record instanceof GenericData.Record)) { throw new CopyNotSupportedException( "The record to make copy is not an instance of " + GenericData.Record.class.getName()); } return new GenericData.Record((GenericData.Record) this.record, true); } }
CopyableGenericRecord implements Copyable<GenericRecord> { @Override public GenericRecord copy() throws CopyNotSupportedException { if (!(this.record instanceof GenericData.Record)) { throw new CopyNotSupportedException( "The record to make copy is not an instance of " + GenericData.Record.class.getName()); } return new GenericData.Record((GenericData.Record) this.record, true); } CopyableGenericRecord(GenericRecord record); }
CopyableGenericRecord implements Copyable<GenericRecord> { @Override public GenericRecord copy() throws CopyNotSupportedException { if (!(this.record instanceof GenericData.Record)) { throw new CopyNotSupportedException( "The record to make copy is not an instance of " + GenericData.Record.class.getName()); } return new GenericData.Record((GenericData.Record) this.record, true); } CopyableGenericRecord(GenericRecord record); @Override GenericRecord copy(); }
CopyableGenericRecord implements Copyable<GenericRecord> { @Override public GenericRecord copy() throws CopyNotSupportedException { if (!(this.record instanceof GenericData.Record)) { throw new CopyNotSupportedException( "The record to make copy is not an instance of " + GenericData.Record.class.getName()); } return new GenericData.Record((GenericData.Record) this.record, true); } CopyableGenericRecord(GenericRecord record); @Override GenericRecord copy();  }