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

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);
            packer.PackMapHeader(ALICE.properties().size());
            ALICE.properties().@foreach((s, value) =>
            {
                try
                {
                    packer.pack(s);
                    packer.pack(value);
                }
                catch (IOException e)
                {
                    throw new UncheckedIOException(e);
                }
            });
            AnyValue unpacked = unpacked(output.Bytes());

            // Then
            assertThat(unpacked, instanceOf(typeof(MapValue)));
            MapValue unpackedMap = ( MapValue )unpacked;

            assertThat(unpackedMap, equalTo(ALICE.properties()));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void VisitAnyValue(AnyValue value)
        {
            //read fielded value through memory assistant
            var fielded = _context.MemoryAssistant.ReadAnyField(value, _field);

            _fieldStorages.Add(new TemporaryVariableKey(fielded));
        }
Esempio n. 3
0
        /// <inheritdoc />
        public override void VisitAnyValue(AnyValue value)
        {
            //read indexed value through memory assistant
            var indexed = _context.MemoryAssistant.ReadAnyValueIndex(value, _index);

            _indexStorages.Add(new TemporaryVariableKey(indexed));
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static Bookmark parseMultipleBookmarks(org.neo4j.values.virtual.MapValue params) throws BookmarkFormatException
        private static Bookmark ParseMultipleBookmarks(MapValue @params)
        {
            AnyValue bookmarksObject = @params.Get(BOOKMARKS_KEY);

            if (bookmarksObject == Values.NO_VALUE)
            {
                return(null);
            }
            else if (bookmarksObject is ListValue)
            {
                ListValue bookmarks = ( ListValue )bookmarksObject;

                long maxTxId = -1;
                foreach (AnyValue bookmark in 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);
            }
        }
Esempio n. 5
0
 /// <inheritdoc />
 public override MemoryEntry ReadAnyValueIndex(AnyValue value, MemberIdentifier index)
 {
     // TODO: Copy info
     if (value is AnyStringValue)
     {
         // Element of string is one charachter but since PHP has no character type,
         // it returns string with one character. The character do not need to be initialized
         SetWarning("Possibly uninitialized string offset");
         return(new MemoryEntry(Context.AnyStringValue));
     }
     else if ((value is AnyNumericValue) || (value is AnyBooleanValue) || (value is AnyResourceValue))
     {
         SetWarning("Trying to get element of scalar value",
                    AnalysisWarningCause.ELEMENT_OF_NON_ARRAY_VARIABLE);
         return(new MemoryEntry(Context.UndefinedValue));
     }
     else if (value is AnyObjectValue)
     {
         // TODO: This must be error
         SetWarning("Cannot use object as array");
         return(new MemoryEntry(Context.AnyValue));
     }
     else
     {
         // This is case of AnyArrayValue, AnyValue and possibly others.
         // If value is AnyValue, it can be any object too, so it can cause an error.
         Value newValue = Context.AnyValue;
         newValue = FlagsHandler.CopyFlags(value, newValue);
         return(new MemoryEntry(newValue));
     }
 }
Esempio n. 6
0
 public static void AssertNotEqual(AnyValue a, AnyValue b)
 {
     assertNotEquals(a + " should not be equivalent to " + b, a, b);
     assertNotEquals(b + " should not be equivalent to " + a, b, a);
     assertFalse(a + " should not equal " + b, a.TernaryEquals(b));
     assertFalse(b + " should not equal " + a, b.TernaryEquals(a));
 }
Esempio n. 7
0
        public virtual void Set(int i, AnyValue value)
        {
            Debug.Assert(value != null);
            Debug.Assert(i >= 0 && i < _fields.Length);

            _fields[i] = value;
        }
Esempio n. 8
0
        /// <inheritdoc />
        public override void VisitAnyValue(AnyValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
            case Operations.NotIdentical:
                result = OutSet.AnyBooleanValue;
                break;

            case Operations.Mod:
                // Ommitted warning message that object cannot be converted to integer
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    // Ommitted warning message that object cannot be converted to integer
                    // Ommitted error report that array is unsupported operand in arithmetic operation
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    // Ommitted warning message that object cannot be converted to integer
                    break;
                }

                base.VisitAnyValue(value);
                break;
            }
        }
Esempio n. 9
0
        private unsafe void ProcessInvokeResponse(IMessageChannel channel, MessageChunk *first)
        {
            var response = channel.Deserialize <InvokeResponse>(first); //TODO:处理反序列化异常

            if (response.Source == InvokeSource.Client || response.Source == InvokeSource.Host)
            {
                GCHandle tcsHandle = GCHandle.FromIntPtr(response.WaitHandle);
                var      tcs       = (PooledTaskSource <AnyValue>)tcsHandle.Target;
                if (response.Error != InvokeResponseError.None) //仅Host,重新包装为异常
                {
                    tcs.SetResultOnOtherThread(AnyValue.From(new Exception((string)response.Result.ObjectValue)));
                }
                else
                {
                    tcs.SetResultOnOtherThread(response.Result);
                }
            }
            else if (response.Source == InvokeSource.Debugger)
            {
                _debugSessionManager.GotInvokeResponse(channel.RemoteRuntimeId, response); //注意暂直接在当前线程处理
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 10
0
 public static void AssertEqualValues(AnyValue a, AnyValue b)
 {
     assertEquals(a + " should be equivalent to " + b, a, b);
     assertEquals(a + " should be equivalent to " + b, b, a);
     assertTrue(a + " should be equal to " + b, a.TernaryEquals(b));
     assertTrue(a + " should be equal to " + b, b.TernaryEquals(a));
 }
Esempio n. 11
0
        public void ShouldGetSignature()
        {
            var val1      = new AnyValue();
            var signature = val1.GetSignature(false);

            Assert.NotNull(signature);
        }
Esempio n. 12
0
        public static TimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            OffsetTime time        = input.getTimePart(defaultZone);
            OffsetTime truncatedOT = AssertValidUnit(() => time.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(time(truncatedOT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    ZonedDateTime currentDT     = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), TimezoneOf(timezone)));
                    ZoneOffset    currentOffset = currentDT.Offset;
                    truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return time(offsetTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
                    }
                }));
            }
        }
Esempio n. 13
0
        internal static string FormatAnyValue(AnyValue value)
        {
            PrettyPrinter printer = new PrettyPrinter("'");

            value.WriteTo(printer);
            return(printer.Value());
        }
Esempio n. 14
0
        public void ShouldCreateNewAnyValueByCopy()
        {
            var val1 = new AnyValue();
            var val2 = new AnyValue(val1);

            Assert.NotNull(val2);
        }
Esempio n. 15
0
        public virtual 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;
                    }
                }));
            }
        }
Esempio n. 16
0
        public static object Pow(object lhs, object rhs)
        {
            if (lhs == null || rhs == null || lhs == Values.NO_VALUE || rhs == Values.NO_VALUE)
            {
                return(null);
            }

            // Handle NumberValues
            if (lhs is NumberValue)
            {
                lhs = (( NumberValue )lhs).asObject();
            }
            if (rhs is NumberValue)
            {
                rhs = (( NumberValue )rhs).asObject();
            }

            // now we have Numbers
            if (lhs is Number && rhs is Number)
            {
                return(Math.Pow((( Number )lhs).doubleValue(), ((Number)rhs).doubleValue()));
            }

            AnyValue lhsValue = lhs is AnyValue ? ( AnyValue )lhs : Values.of(lhs);
            AnyValue rhsValue = rhs is AnyValue ? ( AnyValue )rhs : Values.of(rhs);

            throw new CypherTypeException(string.Format("Cannot raise `{0}` to the power of `{1}`", lhsValue.TypeName, rhsValue.TypeName), null);
        }
Esempio n. 17
0
        public override MemoryEntry ReadAnyField(AnyValue value, VariableIdentifier field)
        {
            var info    = value.GetInfo <SimpleInfo>();
            var indexed = Context.AnyValue.SetInfo(info);

            return(new MemoryEntry(indexed));
        }
Esempio n. 18
0
 public static void AssertIncomparable(AnyValue a, AnyValue b)
 {
     assertNotEquals(a + " should not be equivalent to " + b, a, b);
     assertNotEquals(b + " should not be equivalent to " + a, b, a);
     assertNull(a + " should be incomparable to " + b, a.TernaryEquals(b));
     assertNull(b + " should be incomparable to " + a, b.TernaryEquals(a));
 }
Esempio n. 19
0
        public override MemoryEntry ReadAnyValueIndex(AnyValue value, MemberIdentifier index)
        {
            //copy info
            var info    = value.GetInfo <SimpleInfo>();
            var indexed = Context.AnyValue.SetInfo(info);

            return(new MemoryEntry(indexed));
        }
Esempio n. 20
0
 public static AnyValue Pow(AnyValue lhs, AnyValue rhs)
 {
     if (lhs is NumberValue && rhs is NumberValue)
     {
         return(doubleValue(Math.Pow((( NumberValue )lhs).doubleValue(), ((NumberValue)rhs).doubleValue())));
     }
     throw new CypherTypeException(string.Format("Cannot raise `{0}` to the power of `{1}`", lhs.TypeName, rhs.TypeName), null);
 }
Esempio n. 21
0
 public static DurationValue AsDurationValue(AnyValue value)
 {
     if (!(value is DurationValue))
     {
         throw CantCoerce(value, "Duration");
     }
     return(( DurationValue )value);
 }
Esempio n. 22
0
 protected internal override LocalDateTimeValue selectDateTime(AnyValue datetime)
 {
     if (datetime is LocalDateTimeValue)
     {
         return(( LocalDateTimeValue )datetime);
     }
     return(LocalDateTime(getLocalDateTimeOf(datetime)));
 }
Esempio n. 23
0
 public static void AssertEqual(AnyValue a, AnyValue b)
 {
     assertEquals(FormatMessage("should be equivalent to", a, b), a, b);
     assertEquals(FormatMessage("should be equivalent to", b, a), b, a);
     assertTrue(FormatMessage("should be equal to", a, b), a.TernaryEquals(b));
     assertTrue(FormatMessage("should be equal to", b, a), b.TernaryEquals(a));
     assertEquals(FormatMessage("should have same hashcode as", a, b), a.GetHashCode(), b.GetHashCode());
 }
Esempio n. 24
0
 public static LocalDateTimeValue AsLocalDateTimeValue(AnyValue value)
 {
     if (!(value is LocalDateTimeValue))
     {
         throw CantCoerce(value, "LocalDateTime");
     }
     return(( LocalDateTimeValue )value);
 }
Esempio n. 25
0
 public static PointValue AsPointValue(AnyValue value)
 {
     if (!(value is PointValue))
     {
         throw CantCoerce(value, "Point");
     }
     return(( PointValue )value);
 }
Esempio n. 26
0
 public static DateTimeValue AsDateTimeValue(AnyValue value)
 {
     if (!(value is DateTimeValue))
     {
         throw CantCoerce(value, "DateTime");
     }
     return(( DateTimeValue )value);
 }
Esempio n. 27
0
 public static BooleanValue AsBooleanValue(AnyValue value)
 {
     if (!(value is BooleanValue))
     {
         throw CantCoerce(value, "Boolean");
     }
     return(( BooleanValue )value);
 }
Esempio n. 28
0
 public static TimeValue AsTimeValue(AnyValue value)
 {
     if (!(value is TimeValue))
     {
         throw CantCoerce(value, "Time");
     }
     return(( TimeValue )value);
 }
Esempio n. 29
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private byte[] packed(org.neo4j.values.AnyValue object) throws java.io.IOException
        private sbyte[] Packed(AnyValue @object)
        {
            PackedOutputArray output = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = _neo4jPack.newPacker(output);
            packer.Pack(@object);
            return(output.Bytes());
        }
Esempio n. 30
0
 public static NumberValue AsNumberValue(AnyValue value)
 {
     if (!(value is NumberValue))
     {
         throw CantCoerce(value, "Number");
     }
     return(( NumberValue )value);
 }