Skip to content

Commit

Permalink
Don't use Optional as field
Browse files Browse the repository at this point in the history
Optional shouldn't be used as a field.
  • Loading branch information
pontusmelke committed Jun 19, 2017
1 parent 14908b2 commit 295c72b
Showing 1 changed file with 20 additions and 20 deletions.
Expand Up @@ -48,8 +48,8 @@
*/ */
public class Neo4jPack public class Neo4jPack
{ {
public static final List<Object> EMPTY_LIST = new ArrayList<>(); private static final List<Object> EMPTY_LIST = new ArrayList<>();
public static final Map<String, Object> EMPTY_MAP = new HashMap<>(); private static final Map<String, Object> EMPTY_MAP = new HashMap<>();


public static final byte NODE = 'N'; public static final byte NODE = 'N';
public static final byte RELATIONSHIP = 'R'; public static final byte RELATIONSHIP = 'R';
Expand All @@ -59,7 +59,7 @@ public class Neo4jPack
public static class Packer extends PackStream.Packer public static class Packer extends PackStream.Packer
{ {
private PathPack.Packer pathPacker = new PathPack.Packer(); private PathPack.Packer pathPacker = new PathPack.Packer();
private Optional<Error> error = Optional.empty(); private Error error = null;


public Packer( PackOutput output ) public Packer( PackOutput output )
{ {
Expand All @@ -83,7 +83,7 @@ else if ( obj instanceof Boolean )
pack( (boolean) obj ); pack( (boolean) obj );
} }
else if ( obj instanceof Byte || obj instanceof Short || obj instanceof Integer || else if ( obj instanceof Byte || obj instanceof Short || obj instanceof Integer ||
obj instanceof Long ) obj instanceof Long )
{ {
pack( ((Number) obj).longValue() ); pack( ((Number) obj).longValue() );
} }
Expand All @@ -101,16 +101,16 @@ else if ( obj instanceof Character )
} }
else if ( obj instanceof Map ) else if ( obj instanceof Map )
{ {
Map<Object, Object> map = (Map<Object, Object>) obj; Map<Object,Object> map = (Map<Object,Object>) obj;


packMapHeader( map.size() ); packMapHeader( map.size() );
for ( Map.Entry<?, ?> entry : map.entrySet() ) for ( Map.Entry<?,?> entry : map.entrySet() )
{ {
Object key = entry.getKey(); Object key = entry.getKey();
if ( key == null ) if ( key == null )
{ {
error = Optional.of( new Error( Status.Request.Invalid, error = new Error( Status.Request.Invalid,
"Value `null` is not supported as key in maps, must be a non-nullable string." ) ); "Value `null` is not supported as key in maps, must be a non-nullable string." );
packNull(); packNull();
pack( entry.getValue() ); pack( entry.getValue() );
} }
Expand Down Expand Up @@ -220,15 +220,15 @@ else if ( obj instanceof Path )
} }
else if ( obj instanceof Point ) else if ( obj instanceof Point )
{ {
error = Optional.of(new Error( Status.Request.Invalid, error = new Error( Status.Request.Invalid,
"Point is not yet supported as a return type in Bolt" ) ); "Point is not yet supported as a return type in Bolt" );
packNull(); packNull();


} }
else else
{ {
error = Optional.of(new Error( Status.Request.Invalid, error = new Error( Status.Request.Invalid,
"Unpackable value " + obj + " of type " + obj.getClass().getName() )); "Unpackable value " + obj + " of type " + obj.getClass().getName() );
packNull(); packNull();
} }
} }
Expand All @@ -243,19 +243,19 @@ public void packRawMap( Map<String,Object> map ) throws IOException
} }
} }


public void consumeError( ) throws BoltIOException void consumeError() throws BoltIOException
{ {
if ( error.isPresent() ) if ( error != null )
{ {
Error e = error.get(); BoltIOException exception = new BoltIOException( error.status(), error.msg() );
error = Optional.empty(); error = null;
throw new BoltIOException( e.status(), e.msg() ); throw exception;
} }
} }


public boolean hasErrors() public boolean hasErrors()
{ {
return error.isPresent(); return error != null;
} }
} }


Expand Down Expand Up @@ -334,7 +334,7 @@ public Object unpack() throws IOException
} }
} }


public List<Object> unpackList() throws IOException List<Object> unpackList() throws IOException
{ {
int size = (int) unpackListHeader(); int size = (int) unpackListHeader();
if ( size == 0 ) if ( size == 0 )
Expand Down Expand Up @@ -447,7 +447,7 @@ public Map<String, Object> unpackMap() throws IOException
return map; return map;
} }


public Optional<Neo4jError> consumeError() Optional<Neo4jError> consumeError()
{ {
if ( errors.isEmpty() ) if ( errors.isEmpty() )
{ {
Expand Down

0 comments on commit 295c72b

Please sign in to comment.