// NOTE: This assumes anyValue is an instance of AnyValue public static AnyValue MaterializeAnyValueResult(EmbeddedProxySPI proxySpi, object anyValue) { if (anyValue is VirtualNodeValue) { if (anyValue is NodeValue) { return(( AnyValue )anyValue); } return(ValueUtils.fromNodeProxy(proxySpi.NewNodeProxy((( VirtualNodeValue )anyValue).id()))); } if (anyValue is VirtualRelationshipValue) { if (anyValue is RelationshipValue) { return(( AnyValue )anyValue); } return(ValueUtils.fromRelationshipProxy(proxySpi.NewRelationshipProxy((( VirtualRelationshipValue )anyValue).id()))); } // If it is a list or map, run it through a ValueMapper that will create proxy objects for entities if needed. // This will first do a dry run and return as it is if no conversion is needed. // If in the future we will always create proxy objects directly whenever we create values we can skip this // Doing this conversion lazily instead, by wrapping with TransformedListValue or TransformedMapValue is probably not a // good idea because of the complexities involved (see TOMBSTONE in VirtualValues about why TransformedListValue was killed). // NOTE: There is also a case where a ListValue can be storable (ArrayValueListValue) where no conversion is needed if ((anyValue is ListValue && !(( ListValue )anyValue).storable()) || anyValue is MapValue) { return(CompiledMaterializeValueMapper.MapAnyValue(proxySpi, ( AnyValue )anyValue)); } return(( AnyValue )anyValue); }
private TxStateTransactionDataSnapshot Snapshot() { EmbeddedProxySPI spi = mock(typeof(EmbeddedProxySPI)); when(spi.NewNodeProxy(anyLong())).thenAnswer(invocation => new NodeProxy(spi, invocation.getArgument(0))); when(spi.NewRelationshipProxy(anyLong())).thenAnswer(invocation => new RelationshipProxy(spi, invocation.getArgument(0))); when(spi.NewRelationshipProxy(anyLong(), anyLong(), anyInt(), anyLong())).thenAnswer(invocation => new RelationshipProxy(spi, invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2), invocation.getArgument(3))); return(new TxStateTransactionDataSnapshot(_state, spi, _ops, _transaction)); }
public static NodeValue MaterializeNodeValue(EmbeddedProxySPI proxySpi, object anyValue) { // Null check has to be done outside by the generated code if (anyValue is NodeValue) { return(( NodeValue )anyValue); } else if (anyValue is VirtualNodeValue) { return(ValueUtils.fromNodeProxy(proxySpi.NewNodeProxy((( VirtualNodeValue )anyValue).id()))); } else if (anyValue is Node) { return(ValueUtils.fromNodeProxy(( Node )anyValue)); } //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException("Do not know how to materialize node value from type " + anyValue.GetType().FullName); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { EmbeddedProxySPI manager = mock(typeof(EmbeddedProxySPI)); when(manager.NewNodeProxy(anyLong())).thenAnswer(invocationOnMock => { long id = invocationOnMock.getArgument(0); NodeProxy mock = mock(typeof(NodeProxy)); when(mock.Id).thenReturn(id); return(mock); }); when(manager.NewRelationshipProxy(anyLong())).thenAnswer(invocationOnMock => { long id = invocationOnMock.getArgument(0); RelationshipProxy mock = mock(typeof(RelationshipProxy)); when(mock.Id).thenReturn(id); return(mock); }); _converter = new ParameterConverter(manager); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToReferToIdsBeyondMaxInt() public virtual void ShouldBeAbleToReferToIdsBeyondMaxInt() { // GIVEN EmbeddedProxySPI actions = mock(typeof(EmbeddedProxySPI)); when(actions.NewNodeProxy(anyLong())).then(invocation => NodeWithId(invocation.getArgument(0))); when(actions.GetRelationshipTypeById(anyInt())).then(invocation => new NamedToken("whatever", invocation.getArgument(0))); long[] ids = new long[] { 1437589437, 2047587483, 2147496246L, 2147342921, 3276473721L, 4762746373L, 57587348738L, 59892898932L }; int[] types = new int[] { 0, 10, 101, 3024, 20123, 45008 }; // WHEN/THEN for (int i = 0; i < ids.Length - 2; i++) { long id = ids[i]; long nodeId1 = ids[i + 1]; long nodeId2 = ids[i + 2]; int type = types[i]; VerifyIds(actions, id, nodeId1, type, nodeId2); VerifyIds(actions, id, nodeId2, type, nodeId1); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings({"unchecked", "WeakerAccess"}) public static org.neo4j.values.AnyValue materializeAnyResult(org.neo4j.kernel.impl.core.EmbeddedProxySPI proxySpi, Object anyValue) public static AnyValue MaterializeAnyResult(EmbeddedProxySPI proxySpi, object anyValue) { if (anyValue == null || anyValue == NO_VALUE) { return(NO_VALUE); } else if (anyValue is AnyValue) { return(MaterializeAnyValueResult(proxySpi, anyValue)); } else if (anyValue is System.Collections.IList) { return(VirtualValues.fromList((IList <AnyValue>)(((System.Collections.IList)anyValue).Select(v => MaterializeAnyResult(proxySpi, v)).ToList()))); } else if (anyValue is System.Collections.IDictionary) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<String,?> incoming = (java.util.Map<String,?>) anyValue; IDictionary <string, ?> incoming = (IDictionary <string, ?>)anyValue; MapValueBuilder builder = new MapValueBuilder(incoming.Count); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.Map.Entry<String,?> entry : incoming.entrySet()) foreach (KeyValuePair <string, ?> entry in incoming.SetOfKeyValuePairs()) { builder.Add(entry.Key, MaterializeAnyResult(proxySpi, entry.Value)); } return(builder.Build()); } else if (anyValue is PrimitiveNodeStream) { return(VirtualValues.fromList((( PrimitiveNodeStream )anyValue).LongStream().mapToObj(id => (AnyValue)ValueUtils.fromNodeProxy(proxySpi.NewNodeProxy(id))).collect(Collectors.toList()))); } else if (anyValue is PrimitiveRelationshipStream) { return(VirtualValues.fromList((( PrimitiveRelationshipStream )anyValue).LongStream().mapToObj(id => (AnyValue)ValueUtils.fromRelationshipProxy(proxySpi.NewRelationshipProxy(id))).collect(Collectors.toList()))); } else if (anyValue is LongStream) { long[] array = (( LongStream )anyValue).toArray(); return(Values.longArray(array)); } else if (anyValue is DoubleStream) { double[] array = (( DoubleStream )anyValue).toArray(); return(Values.doubleArray(array)); } else if (anyValue is IntStream) { // IntStream is only used for list of primitive booleans return(VirtualValues.fromList((( IntStream )anyValue).mapToObj(i => Values.booleanValue(i != 0)).collect(Collectors.toList()))); } else if (anyValue.GetType().IsArray) { Type componentType = anyValue.GetType().GetElementType(); int length = Array.getLength(anyValue); if (componentType.IsPrimitive) { object copy = Array.CreateInstance(componentType, length); //noinspection SuspiciousSystemArraycopy Array.Copy(anyValue, 0, copy, 0, length); return(ValueUtils.of(copy)); } else if (anyValue is string[]) { return(Values.stringArray(( string[] )anyValue)); } else { AnyValue[] copy = new AnyValue[length]; for (int i = 0; i < length; i++) { copy[i] = MaterializeAnyResult(proxySpi, Array.get(anyValue, i)); } return(VirtualValues.list(copy)); } } else { return(ValueUtils.of(anyValue)); } }