@Override public AnyValue get( String key ) { for ( int i = maps.length - 1; i >= 0; i-- ) { AnyValue value = maps[i].get( key ); if ( value != NO_VALUE ) { return value; } } return NO_VALUE; }
@Override public AnyValue get( String key ) { for ( int i = 0; i < updatedKeys.length; i++ ) { if ( updatedKeys[i].equals( key ) ) { return updatedValues[i]; } } return map.get( key ); }
@Override public AnyValue get( String key ) { return mapFunction.apply( key, map.get( key ) ); }
@Override public boolean containsKey( String key ) { AnyValue value = map.get( key ); if ( value == NO_VALUE ) { return false; } else { return filter.apply( key, value ); } }
@Override public AnyValue get( String key ) { AnyValue value = map.get( key ); if ( value == NO_VALUE ) { return NO_VALUE; } else if ( filter.apply( key, value ) ) { return value; } else { return NO_VALUE; } }
private static AnyValue mapAccess( MapValue container, AnyValue index ) { return container.get( asString( index ) ); }
private static Bookmark parseSingleBookmark( MapValue params ) throws BookmarkFormatException { AnyValue bookmarkObject = params.get( BOOKMARK_KEY ); if ( bookmarkObject == Values.NO_VALUE ) { return null; } return new Bookmark( txIdFrom( bookmarkObject ) ); }
static Duration parseTransactionTimeout( MapValue meta ) throws BoltIOException { AnyValue anyValue = meta.get( TX_TIMEOUT_KEY ); if ( anyValue == Values.NO_VALUE ) { return null; } else if ( anyValue instanceof LongValue ) { return Duration.ofMillis( ((LongValue) anyValue).longValue() ); } else { throw new BoltIOException( Status.Request.Invalid, "Expecting transaction timeout value to be a Long value, but got: " + anyValue ); } }
@Override public boolean equals( VirtualValue other ) { if ( !(other instanceof MapValue) ) { return false; } MapValue that = (MapValue) other; int size = size(); if ( size != that.size() ) { return false; } Iterable<String> keys = keySet(); for ( String key : keys ) { if ( !get( key ).equals( that.get( key ) ) ) { return false; } } return true; }
public MapValue updatedWith( String key, AnyValue value ) { AnyValue current = get( key ); if ( current.equals( value ) ) { return this; } else if ( current == NO_VALUE ) { return new UpdatedMapValue( this, new String[]{key}, new AnyValue[]{value} ); } else { return new MappedMapValue( this, ( k, v ) -> { if ( k.equals( key ) ) { return value; } else { return v; } } ); } }
private static String onlyTimezone( MapValue map ) { if ( map.size() == 1 ) { String key = single( map.keySet() ); if ( "timezone".equalsIgnoreCase( key ) ) { AnyValue timezone = map.get( key ); if ( timezone instanceof TextValue ) { return ((TextValue) timezone).stringValue(); } } } return null; }
static Map<String,Object> parseTransactionMetadata( MapValue meta ) throws BoltIOException { AnyValue anyValue = meta.get( TX_META_DATA_KEY ); if ( anyValue == Values.NO_VALUE ) { return null; } else if ( anyValue instanceof MapValue ) { MapValue mapValue = (MapValue) anyValue; TransactionMetadataWriter writer = new TransactionMetadataWriter(); Map<String,Object> txMeta = new HashMap<>( mapValue.size() ); mapValue.foreach( ( key, value ) -> txMeta.put( key, writer.valueAsObject( value ) ) ); return txMeta; } else { throw new BoltIOException( Status.Request.Invalid, "Expecting transaction metadata value to be a Map value, but got: " + anyValue ); } }
private static Bookmark parseMultipleBookmarks( MapValue params ) throws BookmarkFormatException { AnyValue bookmarksObject = params.get( BOOKMARKS_KEY ); if ( bookmarksObject == Values.NO_VALUE ) { return null; } else if ( bookmarksObject instanceof ListValue ) { ListValue bookmarks = (ListValue) bookmarksObject; long maxTxId = -1; for ( AnyValue bookmark : bookmarks ) { if ( bookmark != Values.NO_VALUE ) { long txId = txIdFrom( bookmark ); if ( txId > maxTxId ) { maxTxId = txId; } } } return maxTxId == -1 ? null : new Bookmark( maxTxId ); } else { throw new BookmarkFormatException( bookmarksObject ); } }
private void assertMapValueEquals( MapValue a, MapValue b ) { assertThat( a, equalTo( b ) ); assertThat( a.size(), equalTo( b.size() ) ); assertThat( a.hashCode(), equalTo( b.hashCode() ) ); assertThat( a.keySet(), containsInAnyOrder( Iterables.asArray( String.class, b.keySet() ) ) ); assertThat( Arrays.asList( a.keys().asArray() ), containsInAnyOrder( b.keys().asArray() ) ); a.foreach( ( k, v ) -> assertThat( b.get( k ), equalTo( v ) ) ); b.foreach( ( k, v ) -> assertThat( a.get( k ), equalTo( v ) ) ); }
@Test void shouldHandleMaps() { // Given Map<String,Object> map = MapUtil.map( "a", Arrays.asList( "foo", 42 ) ); // When AnyValue anyValue = ValueUtils.of( map ); // Then assertThat( anyValue, instanceOf( MapValue.class ) ); MapValue mapValue = (MapValue) anyValue; assertThat( mapValue.get( "a" ), equalTo( VirtualValues.list( stringValue( "foo" ), intValue( 42 ) ) ) ); assertThat( mapValue.size(), equalTo( 1 ) ); }
public static BooleanValue propertyExists( String key, AnyValue container, DbAccess dbAccess ) { if ( container instanceof VirtualNodeValue ) { return dbAccess.nodeHasProperty( ((VirtualNodeValue) container).id(), dbAccess.propertyKey( key ) ) ? TRUE : FALSE; } else if ( container instanceof VirtualRelationshipValue ) { return dbAccess.relationshipHasProperty( ((VirtualRelationshipValue) container).id(), dbAccess.propertyKey( key ) ) ? TRUE : FALSE; } else if ( container instanceof MapValue ) { return ((MapValue) container).get( key ) != NO_VALUE ? TRUE : FALSE; } else { throw new CypherTypeException( format( "Expected %s to be a property container", container), null ); } }
@Test public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable { // Given List<CallableUserFunction> compiled = compile( ReflectiveUserFunctionTest.MultiFunction.class ); CallableUserFunction bananaPeople = compiled.get( 0 ); CallableUserFunction coolPeople = compiled.get( 1 ); // When Object coolOut = coolPeople.apply( new BasicContext(), new AnyValue[0] ); Object bananaOut = bananaPeople.apply( new BasicContext(), new AnyValue[0] ); // Then assertThat( coolOut , equalTo(ValueUtils.of( Arrays.asList("Bonnie", "Clyde") ) ) ); assertThat( ((MapValue) bananaOut).get("foo"), equalTo( ValueUtils.of( Arrays.asList( "bar", "baz" ) ) ) ); }
@Test public void profileStatisticConversion() { MapValue convertedMap = ExecutionPlanConverter.convert( new TestExecutionPlanDescription( "description", getProfilerStatistics(), getIdentifiers(), getArguments() ) ); assertEquals( convertedMap.get( "operatorType" ), stringValue( "description" ) ); assertEquals( convertedMap.get( "args" ), ValueUtils.asMapValue( getArguments() ) ); assertEquals( convertedMap.get( "identifiers" ), ValueUtils.asListValue( getIdentifiers() )); assertEquals( convertedMap.get( "children" ), VirtualValues.EMPTY_LIST ); assertEquals( convertedMap.get( "rows" ), longValue( 1L )); assertEquals( convertedMap.get( "dbHits" ), longValue( 2L ) ); assertEquals( convertedMap.get( "pageCacheHits" ), longValue( 3L ) ); assertEquals( convertedMap.get( "pageCacheMisses" ), longValue( 2L ) ); assertEquals( ((DoubleValue) convertedMap.get( "pageCacheHitRatio" )).doubleValue(), 3.0 / 5, 0.0001 ); assertEquals( convertedMap.size(), 9 ); }
private static void assertMapEqualsWithDelta( MapValue a, MapValue b, double delta ) { assertThat( "Map should have same size", a.size(), equalTo( b.size() ) ); a.foreach( ( key, value ) -> { //assertThat( "Missing key", b.get( key ) != Values.NO_VALUE ); AnyValue aValue = value; AnyValue bValue = b.get( key ); if ( aValue instanceof MapValue ) { assertThat( "Value mismatch", bValue instanceof MapValue ); assertMapEqualsWithDelta( (MapValue) aValue, (MapValue) bValue, delta ); } else if ( aValue instanceof DoubleValue ) { assertThat( "Value mismatch", ((DoubleValue) aValue).doubleValue(), closeTo( ((DoubleValue) bValue).doubleValue(), delta ) ); } else { assertThat( "Value mismatch", aValue, equalTo( bValue ) ); } } ); }
"operatorType", stringValue( "Join" ), "children", list( expectedChild ) ); assertThat( meta.get( "plan" ), equalTo( expectedPlan ) );