Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTreatCharArrayAsListOfStrings() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTreatCharArrayAsListOfStrings()
        {
            // Given
            PackedOutputArray output = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);
            packer.pack(charArray(new char[] { 'W', 'H', 'Y' }));
            object unpacked = unpacked(output.Bytes());

            // Then
            assertThat(unpacked, instanceOf(typeof(ListValue)));
            assertThat(unpacked, equalTo(VirtualValues.list(stringValue("W"), stringValue("H"), stringValue("Y"))));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleMaps()
        internal virtual void ShouldHandleMaps()
        {
            // Given
            IDictionary <string, object> map = MapUtil.map("a", Arrays.asList("foo", 42));

            // When
            AnyValue anyValue = ValueUtils.of(map);

            // Then
            assertThat(anyValue, instanceOf(typeof(MapValue)));
            MapValue mapValue = ( MapValue )anyValue;

            assertThat(mapValue.Get("a"), equalTo(VirtualValues.list(stringValue("foo"), intValue(42))));
            assertThat(mapValue.Size(), equalTo(1));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: org.neo4j.values.virtual.ListValue unpackList() throws java.io.IOException
            internal virtual ListValue UnpackList()
            {
                int size = ( int )UnpackListHeader();

                if (size == 0)
                {
                    return(VirtualValues.EMPTY_LIST);
                }
                else if (size == UNKNOWN_SIZE)
                {
                    IList <AnyValue> list = new List <AnyValue>();
                    bool             more = true;
                    while (more)
                    {
                        PackType keyType = PeekNextType();
                        switch (keyType)
                        {
                        case PackType.END_OF_STREAM:
                            Unpack();
                            more = false;
                            break;

                        default:
                            list.Add(Unpack());
                            break;
                        }
                    }
                    return(VirtualValues.list(list.ToArray()));
                }
                else
                {
                    AnyValue[] values = new AnyValue[size];
                    for (int i = 0; i < size; i++)
                    {
                        values[i] = Unpack();
                    }
                    return(VirtualValues.list(values));
                }
            }
Beispiel #4
0
            public override ListValue Apply(AnyValue value, Neo4jTypes.AnyType innerType, DbAccess access)
            {
                //Fast route
                if (innerType == NTAny)
                {
                    return(FastListConversion(value));
                }

                //slow route, recursively convert the list
                if (!(value is SequenceValue))
                {
                    throw CantCoerce(value, "List");
                }
                SequenceValue listValue    = ( SequenceValue )value;
                Coercer       innerCoercer = _converters[innerType.GetType()];

                AnyValue[]         coercedValues = new AnyValue[listValue.Length()];
                Neo4jTypes.AnyType nextInner     = nextInner(innerType);
                if (listValue.IterationPreference() == RANDOM_ACCESS)
                {
                    for (int i = 0; i < coercedValues.Length; i++)
                    {
                        AnyValue nextItem = listValue.Value(i);
                        coercedValues[i] = nextItem == NO_VALUE ? NO_VALUE : innerCoercer(nextItem, nextInner, access);
                    }
                }
                else
                {
                    int i = 0;
                    foreach (AnyValue anyValue in listValue)
                    {
                        AnyValue nextItem = listValue.Value(i);
                        coercedValues[i++] = nextItem == NO_VALUE ? NO_VALUE : innerCoercer(anyValue, nextInner, access);
                    }
                }
                return(VirtualValues.list(coercedValues));
            }
//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));
            }
        }