private static ListValue FastListConversion(AnyValue value) { if (value is ListValue) { return(( ListValue )value); } else if (value is ArrayValue) { return(VirtualValues.fromArray(( ArrayValue )value)); } else if (value is PathValue) { return((( PathValue )value).asList()); } throw CantCoerce(value, "List"); }
public override ListValue Split(string separator) { Debug.Assert(!string.ReferenceEquals(separator, null)); string asString = Value(); //Cypher has different semantics for the case where the separator //is exactly the value, in cypher we expect two empty arrays //where as java returns an empty array if (separator.Equals(asString)) { return(EmptySplit); } else if (separator.Length == 0) { return(VirtualValues.fromArray(Values.CharArray(asString.ToCharArray()))); } IList <AnyValue> split = SplitNonRegex(asString, separator); return(VirtualValues.fromList(split)); }
//TODO this is horrible spaghetti code, we should push most of this down to AnyValue public static AnyValue Add(AnyValue lhs, AnyValue rhs) { if (lhs is NumberValue && rhs is NumberValue) { return((( NumberValue )lhs).plus(( NumberValue )rhs)); } //List addition //arrays are same as lists when it comes to addition if (lhs is ArrayValue) { lhs = VirtualValues.fromArray(( ArrayValue )lhs); } if (rhs is ArrayValue) { rhs = VirtualValues.fromArray(( ArrayValue )rhs); } bool lhsIsListValue = lhs is ListValue; if (lhsIsListValue && rhs is ListValue) { return(VirtualValues.concat(( ListValue )lhs, ( ListValue )rhs)); } else if (lhsIsListValue) { return((( ListValue )lhs).append(rhs)); } else if (rhs is ListValue) { return((( ListValue )rhs).prepend(lhs)); } // String addition if (lhs is TextValue && rhs is TextValue) { return((( TextValue )lhs).plus(( TextValue )rhs)); } else if (lhs is TextValue) { if (rhs is Value) { // Unfortunately string concatenation is not defined for temporal and spatial types, so we need to // exclude them if (!(rhs is TemporalValue || rhs is DurationValue || rhs is PointValue)) { return(stringValue((( TextValue )lhs).stringValue() + ((Value)rhs).prettyPrint())); } else { return(stringValue((( TextValue )lhs).stringValue() + rhs.ToString())); } } } else if (rhs is TextValue) { if (lhs is Value) { // Unfortunately string concatenation is not defined for temporal and spatial types, so we need to // exclude them if (!(lhs is TemporalValue || lhs is DurationValue || lhs is PointValue)) { return(stringValue((( Value )lhs).prettyPrint() + ((TextValue)rhs).stringValue())); } else { return(stringValue(lhs.ToString() + ((TextValue)rhs).stringValue())); } } } // Temporal values if (lhs is TemporalValue) { if (rhs is DurationValue) { return((( TemporalValue )lhs).plus(( DurationValue )rhs)); } } if (lhs is DurationValue) { if (rhs is TemporalValue) { return((( TemporalValue )rhs).plus(( DurationValue )lhs)); } if (rhs is DurationValue) { return((( DurationValue )lhs).add(( DurationValue )rhs)); } } throw new CypherTypeException(string.Format("Cannot add `{0}` and `{1}`", lhs.TypeName, rhs.TypeName), null); }