Skip to content

Commit cc2fc61

Browse files
committed
Merge pull request #96 from boggle/new-results-api
New results api
2 parents 1a5faf3 + e1d696e commit cc2fc61

File tree

214 files changed

+6425
-2966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+6425
-2966
lines changed

driver/src/main/java/org/neo4j/driver/v1/internal/value/InternalValue.java renamed to driver/src/main/java/org/neo4j/driver/internal/AsValue.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.v1.internal.value;
19+
package org.neo4j.driver.internal;
2020

2121
import org.neo4j.driver.v1.Value;
22-
import org.neo4j.driver.v1.internal.types.TypeConstructor;
2322

24-
public interface InternalValue extends Value
23+
public interface AsValue
2524
{
26-
TypeConstructor typeConstructor();
25+
/**
26+
* Retrieve a value representation of this
27+
*
28+
* @see Value
29+
* @return {@link Value} that represents this
30+
*/
31+
Value asValue();
2732
}

driver/src/main/java/org/neo4j/driver/v1/internal/Identities.java renamed to driver/src/main/java/org/neo4j/driver/internal/Identities.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.v1.internal;
19+
package org.neo4j.driver.internal;
2020

2121
import org.neo4j.driver.v1.Identity;
2222

2323
public class Identities
2424
{
2525
public static Identity identity( long raw )
2626
{
27-
return new SimpleIdentity( raw );
27+
return new InternalIdentity( raw );
2828
}
29-
3029
}

driver/src/main/java/org/neo4j/driver/v1/internal/SimpleEntity.java renamed to driver/src/main/java/org/neo4j/driver/internal/InternalEntity.java

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,28 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.v1.internal;
19+
package org.neo4j.driver.internal;
2020

21-
import java.util.Collection;
2221
import java.util.Map;
2322

23+
import org.neo4j.driver.internal.util.Extract;
24+
import org.neo4j.driver.internal.util.Iterables;
25+
import org.neo4j.driver.internal.value.MapValue;
2426
import org.neo4j.driver.v1.Entity;
27+
import org.neo4j.driver.v1.Function;
2528
import org.neo4j.driver.v1.Identity;
29+
import org.neo4j.driver.v1.Property;
2630
import org.neo4j.driver.v1.Value;
31+
import org.neo4j.driver.v1.Values;
2732

28-
public abstract class SimpleEntity implements Entity
33+
import static org.neo4j.driver.v1.Values.valueAsIs;
34+
35+
public abstract class InternalEntity implements Entity, AsValue
2936
{
3037
private final Identity id;
3138
private final Map<String,Value> properties;
3239

33-
public SimpleEntity( Identity id, Map<String,Value> properties )
40+
public InternalEntity( Identity id, Map<String, Value> properties )
3441
{
3542
this.id = id;
3643
this.properties = properties;
@@ -43,21 +50,19 @@ public Identity identity()
4350
}
4451

4552
@Override
46-
public Collection<String> propertyKeys()
53+
public Property property( String key )
4754
{
48-
return properties.keySet();
55+
return InternalProperty.of( key, value( key ) );
4956
}
5057

51-
@Override
52-
public Value property( String key )
58+
public int propertyCount()
5359
{
54-
return properties.get( key );
60+
return properties.size();
5561
}
5662

57-
@Override
58-
public int propertyCount()
63+
public Value asValue()
5964
{
60-
return properties.size();
65+
return new MapValue( properties );
6166
}
6267

6368
@Override
@@ -72,7 +77,7 @@ public boolean equals( Object o )
7277
return false;
7378
}
7479

75-
SimpleEntity that = (SimpleEntity) o;
80+
InternalEntity that = (InternalEntity) o;
7681

7782
return id.equals( that.id );
7883

@@ -92,4 +97,47 @@ public String toString()
9297
", properties=" + properties +
9398
'}';
9499
}
100+
101+
@Override
102+
public boolean containsKey( String key )
103+
{
104+
return properties.containsKey( key );
105+
}
106+
107+
@Override
108+
public Iterable<String> keys()
109+
{
110+
return properties.keySet();
111+
}
112+
113+
@Override
114+
public Value value( String key )
115+
{
116+
Value value = properties.get( key );
117+
return value == null ? Values.NULL : value;
118+
}
119+
120+
@Override
121+
public Iterable<Value> values()
122+
{
123+
return properties.values();
124+
}
125+
126+
@Override
127+
public <T> Iterable<T> values( Function<Value,T> mapFunction )
128+
{
129+
return Iterables.map( properties.values(), mapFunction );
130+
}
131+
132+
@Override
133+
public Iterable<Property<Value>> properties()
134+
{
135+
return properties( valueAsIs() );
136+
}
137+
138+
@Override
139+
public <V> Iterable<Property<V>> properties( final Function<Value, V> Function )
140+
{
141+
return Extract.properties( this, Function );
142+
}
95143
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Copyright (c) 2002-2015 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.internal;
20+
21+
import java.util.Objects;
22+
23+
import org.neo4j.driver.v1.Field;
24+
import org.neo4j.driver.v1.Function;
25+
import org.neo4j.driver.v1.Property;
26+
27+
public class InternalField<V> implements Field<V>
28+
{
29+
private final int index;
30+
private final String key;
31+
private final V value;
32+
33+
public InternalField( String key, int index, V value )
34+
{
35+
if ( key == null )
36+
{
37+
throw new IllegalArgumentException( "null key" );
38+
}
39+
if ( value == null )
40+
{
41+
throw new IllegalArgumentException( "null value" );
42+
}
43+
this.index = index;
44+
this.key = key;
45+
this.value = value;
46+
}
47+
48+
public String key()
49+
{
50+
return key;
51+
}
52+
53+
public V value()
54+
{
55+
return value;
56+
}
57+
58+
@Override
59+
public int index()
60+
{
61+
return index;
62+
}
63+
64+
@Override
65+
public Property<V> asProperty()
66+
{
67+
return InternalProperty.of( key, value );
68+
}
69+
70+
@Override
71+
public String toString()
72+
{
73+
return String.format( "%s: %s", key, Objects.toString( value ) );
74+
}
75+
76+
public String toString( Function<V, String> printValue )
77+
{
78+
return String.format( "%s: %s", key, printValue.apply( value ) );
79+
}
80+
81+
@Override
82+
public boolean equals( Object o )
83+
{
84+
if ( this == o )
85+
{
86+
return true;
87+
}
88+
if ( o == null || getClass() != o.getClass() )
89+
{
90+
return false;
91+
}
92+
93+
InternalField<?> that = (InternalField<?>) o;
94+
return index == that.index && key.equals( that.key ) && value.equals( that.value );
95+
}
96+
97+
@Override
98+
public int hashCode()
99+
{
100+
int result = index;
101+
result = 31 * result + key.hashCode();
102+
result = 31 * result + value.hashCode();
103+
return result;
104+
}
105+
106+
public static <V> Field<V> of( String key, int index, V value )
107+
{
108+
return new InternalField<>( key, index, value );
109+
}
110+
}

driver/src/main/java/org/neo4j/driver/v1/internal/SimpleIdentity.java renamed to driver/src/main/java/org/neo4j/driver/internal/InternalIdentity.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.v1.internal;
19+
package org.neo4j.driver.internal;
2020

21+
import org.neo4j.driver.internal.value.IdentityValue;
2122
import org.neo4j.driver.v1.Identity;
23+
import org.neo4j.driver.v1.Value;
2224

23-
public class SimpleIdentity implements Identity
25+
public class InternalIdentity implements Identity, AsValue
2426
{
2527
private final long raw;
2628

27-
public SimpleIdentity( long raw )
29+
public InternalIdentity( long raw )
2830
{
2931
this.raw = raw;
3032
}
3133

34+
@Override
35+
public Value asValue()
36+
{
37+
return new IdentityValue( this );
38+
}
39+
3240
@Override
3341
public String toString()
3442
{
@@ -47,7 +55,7 @@ public boolean equals( Object o )
4755
return false;
4856
}
4957

50-
SimpleIdentity that = (SimpleIdentity) o;
58+
InternalIdentity that = (InternalIdentity) o;
5159

5260
return raw == that.raw;
5361

driver/src/main/java/org/neo4j/driver/v1/internal/SimpleNode.java renamed to driver/src/main/java/org/neo4j/driver/internal/InternalNode.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,35 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.v1.internal;
19+
package org.neo4j.driver.internal;
2020

2121
import java.util.Collection;
2222
import java.util.Collections;
2323
import java.util.Map;
2424

25+
import org.neo4j.driver.internal.value.NodeValue;
2526
import org.neo4j.driver.v1.Identity;
2627
import org.neo4j.driver.v1.Node;
2728
import org.neo4j.driver.v1.Value;
2829

2930
/**
3031
* {@link Node} implementation that directly contains labels and properties.
3132
*/
32-
public class SimpleNode extends SimpleEntity implements Node
33+
public class InternalNode extends InternalEntity implements Node
3334
{
3435
private final Collection<String> labels;
3536

36-
public SimpleNode( long id )
37+
public InternalNode( long id )
3738
{
3839
this( id, Collections.<String>emptyList(), Collections.<String,Value>emptyMap() );
3940
}
4041

41-
public SimpleNode( long id, Collection<String> labels, Map<String,Value> properties )
42+
public InternalNode( long id, Collection<String> labels, Map<String, Value> properties )
4243
{
4344
this( Identities.identity( id ), labels, properties );
4445
}
4546

46-
public SimpleNode( Identity identity, Collection<String> labels, Map<String,Value> properties )
47+
public InternalNode( Identity identity, Collection<String> labels, Map<String, Value> properties )
4748
{
4849
super( identity, properties );
4950
this.labels = labels;
@@ -55,10 +56,22 @@ public Collection<String> labels()
5556
return labels;
5657
}
5758

59+
@Override
60+
public boolean hasLabel( String label )
61+
{
62+
return labels.contains( label );
63+
}
64+
65+
@Override
66+
public Value asValue()
67+
{
68+
return new NodeValue( this );
69+
}
70+
5871
@Override
5972
public String toString()
6073
{
61-
return "node<" + identity() + '>';
74+
return String.format( "node<%s>", identity() );
6275
}
6376

6477
@Override
@@ -77,7 +90,7 @@ public boolean equals( Object o )
7790
return false;
7891
}
7992

80-
SimpleNode that = (SimpleNode) o;
93+
InternalNode that = (InternalNode) o;
8194

8295
return !(labels != null ? !labels.equals( that.labels ) : that.labels != null);
8396

0 commit comments

Comments
 (0)