Skip to content

Replaced Point2D and Point3D with Point #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.driver.internal;

import java.time.Duration;
import java.time.Period;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.List;
import java.util.Objects;

import org.neo4j.driver.v1.types.IsoDuration;

import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.NANOS;
import static java.time.temporal.ChronoUnit.SECONDS;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;

public class InternalIsoDuration implements IsoDuration
{
private static final List<TemporalUnit> SUPPORTED_UNITS = unmodifiableList( asList( MONTHS, DAYS, SECONDS, NANOS ) );

private final long months;
private final long days;
private final long seconds;
private final long nanoseconds;

public InternalIsoDuration( Period period )
{
this( period.toTotalMonths(), period.getDays(), 0, 0 );
}

public InternalIsoDuration( Duration duration )
{
this( 0, 0, duration.getSeconds(), duration.getNano() );
}

public InternalIsoDuration( long months, long days, long seconds, long nanoseconds )
{
this.months = months;
this.days = days;
this.seconds = seconds;
this.nanoseconds = nanoseconds;
}

@Override
public long months()
{
return months;
}

@Override
public long days()
{
return days;
}

@Override
public long seconds()
{
return seconds;
}

@Override
public long nanoseconds()
{
return nanoseconds;
}

@Override
public long get( TemporalUnit unit )
{
if ( unit == MONTHS )
{
return months;
}
else if ( unit == DAYS )
{
return days;
}
else if ( unit == SECONDS )
{
return seconds;
}
else if ( unit == NANOS )
{
return nanoseconds;
}
else
{
throw new UnsupportedTemporalTypeException( "Unsupported unit: " + unit );
}
}

@Override
public List<TemporalUnit> getUnits()
{
return SUPPORTED_UNITS;
}

@Override
public Temporal addTo( Temporal temporal )
{
if ( months != 0 )
{
temporal = temporal.plus( months, MONTHS );
}
if ( days != 0 )
{
temporal = temporal.plus( days, DAYS );
}
if ( seconds != 0 )
{
temporal = temporal.plus( seconds, SECONDS );
}
if ( nanoseconds != 0 )
{
temporal = temporal.plus( nanoseconds, NANOS );
}
return temporal;
}

@Override
public Temporal subtractFrom( Temporal temporal )
{
if ( months != 0 )
{
temporal = temporal.minus( months, MONTHS );
}
if ( days != 0 )
{
temporal = temporal.minus( days, DAYS );
}
if ( seconds != 0 )
{
temporal = temporal.minus( seconds, SECONDS );
}
if ( nanoseconds != 0 )
{
temporal = temporal.minus( nanoseconds, NANOS );
}
return temporal;
}

@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
InternalIsoDuration that = (InternalIsoDuration) o;
return months == that.months &&
days == that.days &&
seconds == that.seconds &&
nanoseconds == that.nanoseconds;
}

@Override
public int hashCode()
{
return Objects.hash( months, days, seconds, nanoseconds );
}

@Override
public String toString()
{
return "Duration{" +
"months=" + months +
", days=" + days +
", seconds=" + seconds +
", nanoseconds=" + nanoseconds +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@

import java.util.Objects;

import org.neo4j.driver.v1.types.Point2D;
import org.neo4j.driver.v1.types.Point;

public class InternalPoint2D implements Point2D
public class InternalPoint2D implements Point
{
private final long srid;
private final int srid;
private final double x;
private final double y;

public InternalPoint2D( long srid, double x, double y )
public InternalPoint2D( int srid, double x, double y )
{
this.srid = srid;
this.x = x;
this.y = y;
}

@Override
public long srid()
public int srid()
{
return srid;
}
Expand All @@ -53,6 +53,12 @@ public double y()
return y;
}

@Override
public double z()
{
return Double.NaN;
}

@Override
public boolean equals( Object o )
{
Expand All @@ -79,7 +85,7 @@ public int hashCode()
@Override
public String toString()
{
return "Point2D{" +
return "Point{" +
"srid=" + srid +
", x=" + x +
", y=" + y +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import java.util.Objects;

import org.neo4j.driver.v1.types.Point3D;
import org.neo4j.driver.v1.types.Point;

public class InternalPoint3D implements Point3D
public class InternalPoint3D implements Point
{
private final long srid;
private final int srid;
private final double x;
private final double y;
private final double z;

public InternalPoint3D( long srid, double x, double y, double z )
public InternalPoint3D( int srid, double x, double y, double z )
{
this.srid = srid;
this.x = x;
Expand All @@ -38,7 +38,7 @@ public InternalPoint3D( long srid, double x, double y, double z )
}

@Override
public long srid()
public int srid()
{
return srid;
}
Expand Down Expand Up @@ -88,11 +88,11 @@ public int hashCode()
@Override
public String toString()
{
return "Point3D{" +
return "Point({" +
"srid=" + srid +
", x=" + x +
", y=" + y +
", z=" + z +
'}';
"})";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import java.util.Map;
import java.util.NoSuchElementException;

import org.neo4j.driver.internal.util.Extract;
import org.neo4j.driver.internal.value.InternalValue;
import org.neo4j.driver.internal.types.InternalMapAccessorWithDefaultValue;
import org.neo4j.driver.internal.util.Extract;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Value;
import org.neo4j.driver.v1.Values;
Expand Down Expand Up @@ -129,7 +128,7 @@ public <T> Map<String,T> asMap( Function<Value,T> mapper )
@Override
public String toString()
{
return format( "Record<%s>", formatPairs( InternalValue.Format.VALUE_ONLY, asMap( ofValue() ) ) );
return format( "Record<%s>", formatPairs( asMap( ofValue() ) ) );
}

@Override
Expand Down
Loading