InternalRecord extends InternalMapAccessorWithDefaultValue implements Record { @Override public Value get( String key ) { int fieldIndex = queryKeys.indexOf( key ); if ( fieldIndex == -1 ) { return Values.NULL; } else { return values[fieldIndex]; } } InternalRecord( List<String> keys, Value[] values );  InternalRecord( QueryKeys queryKeys, Value[] values ); @Override List<String> keys(); @Override List<Value> values(); @Override List<Pair<String, Value>> fields(); @Override int index( String key ); @Override boolean containsKey( String key ); @Override Value get( String key ); @Override Value get( int index ); @Override int size(); @Override Map<String, Object> asMap(); @Override Map<String,T> asMap( Function<Value,T> mapper ); @Override String toString(); @Override boolean equals( Object other ); @Override int hashCode();  }
@Test void accessingUnknownKeyShouldBeNull() { InternalRecord record = createRecord(); assertThat( record.get( "k1" ), equalTo( value( 0 ) ) ); assertThat( record.get( "k2" ), equalTo( value( 1 ) ) ); assertThat( record.get( "k3" ), equalTo( NullValue.NULL ) ); }
@Test void accessingOutOfBoundsShouldBeNull() { InternalRecord record = createRecord(); assertThat( record.get( 0 ), equalTo( value( 0 ) ) ); assertThat( record.get( 1 ), equalTo( value( 1 ) ) ); assertThat( record.get( 2 ), equalTo( NullValue.NULL ) ); assertThat( record.get( -37 ), equalTo( NullValue.NULL ) ); }
@Test void testMapExtraction() { InternalRecord record = createRecord(); Function<Value,Integer> addOne = value -> value.asInt() + 1; Map<String,Integer> map = Extract.map( record, addOne ); assertThat( map.keySet(), contains( "k1", "k2" ) ); assertThat( map.get( "k1" ), equalTo( 1 ) ); assertThat( map.get( "k2" ), equalTo( 2 ) ); }