예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query)
        public override R query <R>(TemporalQuery <R> query)
        {
            if (query == TemporalQueries.ZoneId())
            {
                return((R)Zone);
            }
            else if (query == TemporalQueries.Chronology())
            {
                return((R)Chrono);
            }
            else if (query == TemporalQueries.LocalDate())
            {
                return((R)(Date != java.time.temporal.TemporalAccessor_Fields.Null ? LocalDate.From(Date) : java.time.temporal.TemporalAccessor_Fields.Null));
            }
            else if (query == TemporalQueries.LocalTime())
            {
                return((R)Time);
            }
            else if (query == TemporalQueries.Zone() || query == TemporalQueries.Offset())
            {
                return(query.QueryFrom(this));
            }
            else if (query == TemporalQueries.Precision())
            {
                return(java.time.temporal.TemporalAccessor_Fields.Null);                // not a complete date/time
            }
            // inline TemporalAccessor.super.query(query) as an optimization
            // non-JDK classes are not permitted to make this optimization
            return(query.QueryFrom(this));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query)
            public override R query <R>(TemporalQuery <R> query)
            {
                if (query == TemporalQueries.ZoneId())
                {
                    return((R)ZoneId.this);
                }
                return(TemporalAccessor.this.query(query));
            }
예제 #3
0
        //-----------------------------------------------------------------------
        /// <summary>
        /// Queries this offset using the specified query.
        /// <para>
        /// This queries this offset using the specified query strategy object.
        /// The {@code TemporalQuery} object defines the logic to be used to
        /// obtain the result. Read the documentation of the query to understand
        /// what the result of this method will be.
        /// </para>
        /// <para>
        /// The result of this method is obtained by invoking the
        /// <seealso cref="TemporalQuery#queryFrom(TemporalAccessor)"/> method on the
        /// specified query passing {@code this} as the argument.
        ///
        /// </para>
        /// </summary>
        /// @param <R> the type of the result </param>
        /// <param name="query">  the query to invoke, not null </param>
        /// <returns> the query result, null may be returned (defined by the query) </returns>
        /// <exception cref="DateTimeException"> if unable to query (defined by the query) </exception>
        /// <exception cref="ArithmeticException"> if numeric overflow occurs (defined by the query) </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query)
        public override R query <R>(TemporalQuery <R> query)
        {
            if (query == TemporalQueries.Offset() || query == TemporalQueries.Zone())
            {
                return((R)this);
            }
            return(TemporalAccessor.this.query(query));
        }
예제 #4
0
        //-----------------------------------------------------------------------
        /// <summary>
        /// Queries this month-day using the specified query.
        /// <para>
        /// This queries this month-day using the specified query strategy object.
        /// The {@code TemporalQuery} object defines the logic to be used to
        /// obtain the result. Read the documentation of the query to understand
        /// what the result of this method will be.
        /// </para>
        /// <para>
        /// The result of this method is obtained by invoking the
        /// <seealso cref="TemporalQuery#queryFrom(TemporalAccessor)"/> method on the
        /// specified query passing {@code this} as the argument.
        ///
        /// </para>
        /// </summary>
        /// @param <R> the type of the result </param>
        /// <param name="query">  the query to invoke, not null </param>
        /// <returns> the query result, null may be returned (defined by the query) </returns>
        /// <exception cref="DateTimeException"> if unable to query (defined by the query) </exception>
        /// <exception cref="ArithmeticException"> if numeric overflow occurs (defined by the query) </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query)
        public override R query <R>(TemporalQuery <R> query)
        {
            if (query == TemporalQueries.Chronology())
            {
                return((R)IsoChronology.INSTANCE);
            }
            return(TemporalAccessor.this.query(query));
        }
예제 #5
0
        /// <summary>
        /// Validates that the temporal has the correct chronology.
        /// </summary>
        private void ValidateChrono(TemporalAccessor temporal)
        {
            Objects.RequireNonNull(temporal, "temporal");
            Chronology temporalChrono = temporal.query(TemporalQueries.Chronology());

            if (temporalChrono != null && Chrono.Equals(temporalChrono) == ChronoPeriod_Fields.False)
            {
                throw new DateTimeException("Chronology mismatch, expected: " + Chrono.Id + ", actual: " + temporalChrono.Id);
            }
        }
예제 #6
0
        //-----------------------------------------------------------------------
        /// <summary>
        /// Obtains an instance of {@code ZoneId} from a temporal object.
        /// <para>
        /// This obtains a zone based on the specified temporal.
        /// A {@code TemporalAccessor} represents an arbitrary set of date and time information,
        /// which this factory converts to an instance of {@code ZoneId}.
        /// </para>
        /// <para>
        /// A {@code TemporalAccessor} represents some form of date and time information.
        /// This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.
        /// </para>
        /// <para>
        /// The conversion will try to obtain the zone in a way that favours region-based
        /// zones over offset-based zones using <seealso cref="TemporalQueries#zone()"/>.
        /// </para>
        /// <para>
        /// This method matches the signature of the functional interface <seealso cref="TemporalQuery"/>
        /// allowing it to be used as a query via method reference, {@code ZoneId::from}.
        ///
        /// </para>
        /// </summary>
        /// <param name="temporal">  the temporal object to convert, not null </param>
        /// <returns> the zone ID, not null </returns>
        /// <exception cref="DateTimeException"> if unable to convert to a {@code ZoneId} </exception>
        public static ZoneId From(TemporalAccessor temporal)
        {
            ZoneId obj = temporal.query(TemporalQueries.Zone());

            if (obj == null)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " + temporal + " of type " + temporal.GetType().FullName);
            }
            return(obj);
        }
예제 #7
0
        //-----------------------------------------------------------------------
        /// <summary>
        /// Obtains an instance of {@code ZoneOffset} from a temporal object.
        /// <para>
        /// This obtains an offset based on the specified temporal.
        /// A {@code TemporalAccessor} represents an arbitrary set of date and time information,
        /// which this factory converts to an instance of {@code ZoneOffset}.
        /// </para>
        /// <para>
        /// A {@code TemporalAccessor} represents some form of date and time information.
        /// This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}.
        /// </para>
        /// <para>
        /// The conversion uses the <seealso cref="TemporalQueries#offset()"/> query, which relies
        /// on extracting the <seealso cref="ChronoField#OFFSET_SECONDS OFFSET_SECONDS"/> field.
        /// </para>
        /// <para>
        /// This method matches the signature of the functional interface <seealso cref="TemporalQuery"/>
        /// allowing it to be used as a query via method reference, {@code ZoneOffset::from}.
        ///
        /// </para>
        /// </summary>
        /// <param name="temporal">  the temporal object to convert, not null </param>
        /// <returns> the zone-offset, not null </returns>
        /// <exception cref="DateTimeException"> if unable to convert to an {@code ZoneOffset} </exception>
        public static ZoneOffset From(TemporalAccessor temporal)
        {
            Objects.RequireNonNull(temporal, "temporal");
            ZoneOffset offset = temporal.query(TemporalQueries.Offset());

            if (offset == temporal.TemporalAccessor_Fields.Null)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: " + temporal + " of type " + temporal.GetType().FullName);
            }
            return(offset);
        }
예제 #8
0
        internal static ZoneId ParseZoneName(string zoneName)
        {
            ZoneId parsedName;

            try
            {
                parsedName = _zoneNameParser.parse(zoneName.Replace(' ', '_')).query(TemporalQueries.zoneId());
            }
            catch (DateTimeParseException e)
            {
                throw new TemporalParseException("Invalid value for TimeZone: " + e.Message, e.ParsedString, e.ErrorIndex, e);
            }
            return(parsedName);
        }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query)
            public override R query <R>(TemporalQuery <R> query)
            {
                if (query == TemporalQueries.Chronology())
                {
                    return((R)EffectiveChrono);
                }
                if (query == TemporalQueries.ZoneId())
                {
                    return((R)EffectiveZone);
                }
                if (query == TemporalQueries.Precision())
                {
                    return(Temporal.query(query));
                }
                return(query.QueryFrom(this));
            }
예제 #10
0
        public static ZoneId ParseZoneOffsetOrZoneName(string zoneName)
        {
            Matcher matcher = OFFSET.matcher(zoneName);

            if (matcher.matches())
            {
                return(parseOffset(matcher));
            }
            try
            {
                return(_zoneNameParser.parse(zoneName.Replace(' ', '_')).query(TemporalQueries.zoneId()));
            }
            catch (DateTimeParseException e)
            {
                throw new TemporalParseException("Invalid value for TimeZone: " + e.Message, e.ParsedString, e.ErrorIndex, e);
            }
        }
예제 #11
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: private static java.time.temporal.TemporalAccessor adjust(final java.time.temporal.TemporalAccessor temporal, DateTimeFormatter formatter)
        private static TemporalAccessor Adjust(TemporalAccessor temporal, DateTimeFormatter formatter)
        {
            // normal case first (early return is an optimization)
            Chronology overrideChrono = formatter.Chronology;
            ZoneId     overrideZone   = formatter.Zone;

            if (overrideChrono == null && overrideZone == null)
            {
                return(temporal);
            }

            // ensure minimal change (early return is an optimization)
            Chronology temporalChrono = temporal.query(TemporalQueries.Chronology());
            ZoneId     temporalZone   = temporal.query(TemporalQueries.ZoneId());

            if (Objects.Equals(overrideChrono, temporalChrono))
            {
                overrideChrono = null;
            }
            if (Objects.Equals(overrideZone, temporalZone))
            {
                overrideZone = null;
            }
            if (overrideChrono == null && overrideZone == null)
            {
                return(temporal);
            }

            // make adjustment
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.chrono.Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono);
            Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono);

            if (overrideZone != null)
            {
                // if have zone and instant, calculation is simple, defaulting chrono if necessary
                if (temporal.IsSupported(INSTANT_SECONDS))
                {
                    Chronology chrono = (effectiveChrono != null ? effectiveChrono : IsoChronology.INSTANCE);
                    return(chrono.zonedDateTime(Instant.From(temporal), overrideZone));
                }
                // block changing zone on OffsetTime, and similar problem cases
                if (overrideZone.Normalized() is ZoneOffset && temporal.IsSupported(OFFSET_SECONDS) && temporal.get(OFFSET_SECONDS) != overrideZone.Rules.GetOffset(Instant.EPOCH).TotalSeconds)
                {
                    throw new DateTimeException("Unable to apply override zone '" + overrideZone + "' because the temporal object being formatted has a different offset but" + " does not represent an instant: " + temporal);
                }
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
            ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.chrono.ChronoLocalDate effectiveDate;
            ChronoLocalDate effectiveDate;

            if (overrideChrono != null)
            {
                if (temporal.IsSupported(EPOCH_DAY))
                {
                    effectiveDate = effectiveChrono.Date(temporal);
                }
                else
                {
                    // check for date fields other than epoch-day, ignoring case of converting null to ISO
                    if (!(overrideChrono == IsoChronology.INSTANCE && temporalChrono == null))
                    {
                        foreach (ChronoField f in ChronoField.values())
                        {
                            if (f.DateBased && temporal.IsSupported(f))
                            {
                                throw new DateTimeException("Unable to apply override chronology '" + overrideChrono + "' because the temporal object being formatted contains date fields but" + " does not represent a whole date: " + temporal);
                            }
                        }
                    }
                    effectiveDate = null;
                }
            }
            else
            {
                effectiveDate = null;
            }

            // combine available data
            // this is a non-standard temporal that is almost a pure delegate
            // this better handles map-like underlying temporal instances
            return(new TemporalAccessorAnonymousInnerClassHelper(temporal, effectiveChrono, effectiveZone, effectiveDate));
        }
예제 #12
0
        private static void BuildUpExpectedData(IList <InputEntity> nodeData, IList <InputEntity> relationshipData, IDictionary <string, InputEntity> expectedNodes, IDictionary <string, string[]> expectedNodeNames, IDictionary <string, IDictionary <string, System.Action <object> > > expectedNodePropertyVerifiers, IDictionary <string, IDictionary <string, IDictionary <string, AtomicInteger> > > expectedRelationships, IDictionary <string, AtomicLong> nodeCounts, IDictionary <string, IDictionary <string, IDictionary <string, AtomicLong> > > relationshipCounts)
        {
            foreach (InputEntity node in nodeData)
            {
                expectedNodes[( string )node.Id()] = node;
                expectedNodeNames[NameOf(node)]    = node.Labels();

                // Build default verifiers for all the properties that compares the property value using equals
                assertTrue(!node.HasIntPropertyKeyIds);
                IDictionary <string, System.Action <object> > propertyVerifiers = new SortedDictionary <string, System.Action <object> >();
                for (int i = 0; i < node.PropertyCount(); i++)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Object expectedValue = node.propertyValue(i);
                    object        expectedValue = node.PropertyValue(i);
                    System.Action verify;
                    if (expectedValue is TemporalAmount)
                    {
                        // Since there is no straightforward comparison for TemporalAmount we add it to a reference
                        // point in time and compare the result
                        verify = actualValue =>
                        {
                            DateTime referenceTemporal = new DateTime(0, 1, 1, 0, 0);
                            DateTime expected          = referenceTemporal.plus(( TemporalAmount )expectedValue);
                            DateTime actual            = referenceTemporal.plus(( TemporalAmount )actualValue);
                            assertEquals(expected, actual);
                        };
                    }
                    else if (expectedValue is Temporal)
                    {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.LocalDate expectedDate = ((java.time.temporal.Temporal) expectedValue).query(java.time.temporal.TemporalQueries.localDate());
                        LocalDate expectedDate = (( Temporal )expectedValue).query(TemporalQueries.localDate());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.LocalTime expectedTime = ((java.time.temporal.Temporal) expectedValue).query(java.time.temporal.TemporalQueries.localTime());
                        LocalTime expectedTime = (( Temporal )expectedValue).query(TemporalQueries.localTime());
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.time.ZoneId expectedZoneId = ((java.time.temporal.Temporal) expectedValue).query(java.time.temporal.TemporalQueries.zone());
                        ZoneId expectedZoneId = (( Temporal )expectedValue).query(TemporalQueries.zone());

                        verify = actualValue =>
                        {
                            LocalDate actualDate   = (( Temporal )actualValue).query(TemporalQueries.localDate());
                            LocalTime actualTime   = (( Temporal )actualValue).query(TemporalQueries.localTime());
                            ZoneId    actualZoneId = (( Temporal )actualValue).query(TemporalQueries.zone());

                            assertEquals(expectedDate, actualDate);
                            assertEquals(expectedTime, actualTime);
                            if (expectedZoneId == null)
                            {
                                if (actualZoneId != null)
                                {
                                    // If the actual value is zoned it should have the default zone
                                    assertEquals(_testDefaultTimeZone.get(), actualZoneId);
                                }
                            }
                            else
                            {
                                assertEquals(expectedZoneId, actualZoneId);
                            }
                        };
                    }
                    else
                    {
                        verify = actualValue => assertEquals(expectedValue, actualValue);
                    }
                    propertyVerifiers[( string )node.PropertyKey(i)] = verify;
                }

                // Special verifier for pointA property
                System.Action verifyPointA = actualValue =>
                {
                    // The y-coordinate should match the node number
                    PointValue v         = ( PointValue )actualValue;
                    double     actualY   = v.Coordinates.get(0).Coordinate.get(1);
                    double     expectedY = IndexOf(node);
                    string     message   = actualValue.ToString() + " does not have y=" + expectedY;
                    assertEquals(message, expectedY, actualY, 0.1);
                    message = actualValue.ToString() + " does not have crs=wgs-84";
                    assertEquals(message, CoordinateReferenceSystem.WGS84.Name, v.CoordinateReferenceSystem.Name);
                };
                propertyVerifiers["pointA"] = verifyPointA;

                // Special verifier for pointB property
                System.Action verifyPointB = actualValue =>
                {
                    // The y-coordinate should match the node number
                    PointValue v         = ( PointValue )actualValue;
                    double     actualY   = v.Coordinates.get(0).Coordinate.get(1);
                    double     expectedY = IndexOf(node);
                    string     message   = actualValue.ToString() + " does not have y=" + expectedY;
                    assertEquals(message, expectedY, actualY, 0.1);
                    message = actualValue.ToString() + " does not have crs=cartesian";
                    assertEquals(message, CoordinateReferenceSystem.Cartesian.Name, v.CoordinateReferenceSystem.Name);
                };
                propertyVerifiers["pointB"] = verifyPointB;

                expectedNodePropertyVerifiers[NameOf(node)] = propertyVerifiers;

                CountNodeLabels(nodeCounts, node.Labels());
            }
            foreach (InputEntity relationship in relationshipData)
            {
                // Expected relationship counts per node, type and direction
                InputEntity startNode = expectedNodes[relationship.StartId()];
                InputEntity endNode   = expectedNodes[relationship.EndId()];
                {
                    expectedRelationships[NameOf(startNode)][NameOf(endNode)][relationship.StringType].incrementAndGet();
                }

                // Expected counts per start/end node label ids
                // Let's do what CountsState#addRelationship does, roughly
                relationshipCounts[null][null][null].incrementAndGet();
                relationshipCounts[null][relationship.StringType][null].incrementAndGet();
                foreach (string startNodeLabelName in asSet(startNode.Labels()))
                {
                    IDictionary <string, IDictionary <string, AtomicLong> > startLabelCounts = relationshipCounts[startNodeLabelName];
                    startLabelCounts[null][null].incrementAndGet();
                    IDictionary <string, AtomicLong> typeCounts = startLabelCounts[relationship.StringType];
                    typeCounts[null].incrementAndGet();
                    if (COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS)
                    {
                        foreach (string endNodeLabelName in asSet(endNode.Labels()))
                        {
                            startLabelCounts[null][endNodeLabelName].incrementAndGet();
                            typeCounts[endNodeLabelName].incrementAndGet();
                        }
                    }
                }
                foreach (string endNodeLabelName in asSet(endNode.Labels()))
                {
                    relationshipCounts[null][null][endNodeLabelName].incrementAndGet();
                    relationshipCounts[null][relationship.StringType][endNodeLabelName].incrementAndGet();
                }
            }
        }