示例#1
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));
            }
示例#2
0
        public override AnyValue Map(AnyValue input)
        {
            if (input is ByteArray)
            {
                return(input);
            }
            if (input is SequenceValue)
            {
                SequenceValue list = ( SequenceValue )input;
                if (list.IterationPreference() == RANDOM_ACCESS)
                {
                    sbyte[] bytes = new sbyte[list.Length()];
                    for (int a = 0; a < bytes.Length; a++)
                    {
                        bytes[a] = AsByte(list.Value(a));
                    }
                    return(Values.byteArray(bytes));
                }
                else
                {
                    //this may have linear complexity, still worth doing it upfront
                    sbyte[] bytes = new sbyte[list.Length()];
                    int     i     = 0;
                    foreach (AnyValue anyValue in list)
                    {
                        bytes[i++] = AsByte(anyValue);
                    }

                    return(Values.byteArray(bytes));
                }
            }
            else
            {
                throw new System.ArgumentException("Cannot convert " + input.GetType().Name + " to byte[] for input to procedure");
            }
        }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: public static java.util.Set<?> toSet(Object value)
        public static ISet <object> ToSet(object value)
        {
            if (value == null || value == NO_VALUE)
            {
                return(Collections.emptySet());
            }
            else if (value is SequenceValue)
            {
                SequenceValue          sequenceValue = ( SequenceValue )value;
                IEnumerator <AnyValue> iterator      = sequenceValue.GetEnumerator();
                ISet <AnyValue>        set;
                if (sequenceValue.IterationPreference() == RANDOM_ACCESS)
                {
                    // If we have a random access sequence value length() should be cheap and we can optimize the initial capacity
                    int length = sequenceValue.Length();
                    set = new HashSet <AnyValue>(length);
                    for (int i = 0; i < length; i++)
                    {
                        set.Add(sequenceValue.Value(i));
                    }
                }
                else
                {
                    set = new HashSet <AnyValue>();
                    while (iterator.MoveNext())
                    {
                        AnyValue element = iterator.Current;
                        set.Add(element);
                    }
                }
                return(set);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: else if (value instanceof java.util.Collection<?>)
            else if (value is ICollection <object> )
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return new java.util.HashSet<>((java.util.Collection<?>) value);
                return(new HashSet <object>((ICollection <object>)value));
            }
            else if (value is LongStream)
            {
                LongStream stream = ( LongStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value is IntStream)
            {
                IntStream stream = ( IntStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value is DoubleStream)
            {
                DoubleStream stream = ( DoubleStream )value;
                return(stream.boxed().collect(Collectors.toSet()));
            }
            else if (value.GetType().IsArray)
            {
                int len = Array.getLength(value);
                HashSet <object> collection = new HashSet <object>(len);
                for (int i = 0; i < len; i++)
                {
                    collection.Add(Array.get(value, i));
                }
                return(collection);
            }

            throw new CypherTypeException("Don't know how to create a set out of " + value.GetType().Name, null);
        }