Skip to content

Commit

Permalink
Added Value.prettyPrint()
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 15, 2017
1 parent 7757bd8 commit af5e611
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 59 deletions.
Expand Up @@ -154,55 +154,8 @@ private String propertyString( TokenNameLookup tokenNameLookup, int[] propertyId
sb.append( '`' );
sb.append( tokenNameLookup.propertyKeyGetName( propertyIds[i] ) );
sb.append( "` = " );
sb.append( quote( propertyValues.valueAt( i ).asPublic() ) );
sb.append( propertyValues.valueAt( i ).prettyPrint() );
}
return sb.toString();
}

private static String quote( Object propertyValue )
{
if ( propertyValue instanceof String )
{
return format( "'%s'", propertyValue );
}
else if ( propertyValue.getClass().isArray() )
{
Class<?> type = propertyValue.getClass().getComponentType();
if ( type == Boolean.TYPE )
{
return Arrays.toString( (boolean[]) propertyValue );
}
else if ( type == Byte.TYPE )
{
return Arrays.toString( (byte[]) propertyValue );
}
else if ( type == Short.TYPE )
{
return Arrays.toString( (short[]) propertyValue );
}
else if ( type == Character.TYPE )
{
return Arrays.toString( (char[]) propertyValue );
}
else if ( type == Integer.TYPE )
{
return Arrays.toString( (int[]) propertyValue );
}
else if ( type == Long.TYPE )
{
return Arrays.toString( (long[]) propertyValue );
}
else if ( type == Float.TYPE )
{
return Arrays.toString( (float[]) propertyValue );
}
else if ( type == Double.TYPE )
{
return Arrays.toString( (double[]) propertyValue );
}
return Arrays.toString( (Object[]) propertyValue );
}
return valueOf( propertyValue );
}

}
Expand Up @@ -145,6 +145,12 @@ public NumberType numberType()
return NumberType.NO_NUMBER;
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends BooleanArray
{
private final boolean[] value;
Expand Down
28 changes: 17 additions & 11 deletions community/values/src/main/java/org/neo4j/values/BooleanValue.java
Expand Up @@ -27,11 +27,11 @@
*/
final class BooleanValue extends ScalarValue
{
private final boolean bool;
private final boolean value;

BooleanValue( boolean bool )
BooleanValue( boolean value )
{
this.bool = bool;
this.value = value;
}

@Override
Expand All @@ -43,13 +43,13 @@ public boolean equals( Object other )
@Override
public boolean equals( Value other )
{
return other.equals( bool );
return other.equals( value );
}

@Override
public boolean equals( boolean x )
{
return bool == x;
return value == x;
}

@Override
Expand All @@ -67,35 +67,41 @@ public boolean equals( String x )
@Override
public int hashCode()
{
return bool ? -1 : 0;
return value ? -1 : 0;
}

public boolean booleanValue()
{
return bool;
return value;
}

public int compareTo( BooleanValue other )
{
return Boolean.compare( bool, other.booleanValue() );
return Boolean.compare( value, other.booleanValue() );
}

@Override
public void writeTo( ValueWriter writer )
{
writer.writeBoolean( bool );
writer.writeBoolean( value );
}

@Override
public Object asPublic()
{
return bool;
return value;
}

@Override
public String prettyPrint()
{
return Boolean.toString( value );
}

@Override
public String toString()
{
return format( "Boolean('%s')", Boolean.toString( bool ) );
return format( "Boolean('%s')", Boolean.toString( value ) );
}

public ValueGroup valueGroup()
Expand Down
Expand Up @@ -112,6 +112,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends ByteArray
{
final byte[] value;
Expand Down
Expand Up @@ -70,6 +70,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Byte.toString( value );
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -95,6 +95,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends CharArray
{
final char[] value;
Expand Down
Expand Up @@ -78,6 +78,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return format( "'%s'", value );
}

@Override
public String stringValue()
{
Expand Down
Expand Up @@ -112,6 +112,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends DoubleArray
{
final double[] value;
Expand Down
Expand Up @@ -66,6 +66,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Double.toString( value );
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -112,6 +112,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends FloatArray
{
final float[] value;
Expand Down
Expand Up @@ -66,6 +66,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Float.toString( value );
}

@Override
public String toString()
{
Expand Down
6 changes: 6 additions & 0 deletions community/values/src/main/java/org/neo4j/values/IntArray.java
Expand Up @@ -112,6 +112,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends IntArray
{
final int[] value;
Expand Down
6 changes: 6 additions & 0 deletions community/values/src/main/java/org/neo4j/values/IntValue.java
Expand Up @@ -48,6 +48,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Integer.toString( value );
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -105,6 +105,12 @@ public Object asPublic()
return value().clone();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

@Override
@Deprecated
public Object asLegacyObject()
Expand Down
Expand Up @@ -66,6 +66,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Long.toString( value );
}

@Override
public String toString()
{
Expand Down
6 changes: 6 additions & 0 deletions community/values/src/main/java/org/neo4j/values/NoValue.java
Expand Up @@ -136,6 +136,12 @@ public Object asPublic()
return null;
}

@Override
public String prettyPrint()
{
return "NO_VALUE";
}

public ValueGroup valueGroup()
{
return ValueGroup.NO_VALUE;
Expand Down
Expand Up @@ -112,6 +112,12 @@ public Object asLegacyObject()
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends ShortArray
{
final short[] value;
Expand Down
Expand Up @@ -70,6 +70,12 @@ public Object asPublic()
return value;
}

@Override
public String prettyPrint()
{
return Short.toString( value );
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -93,6 +93,12 @@ public int compareTo( TextArray other )
return TextValues.compareTextArrays( this, other );
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends StringArray
{
final String[] value;
Expand Down
Expand Up @@ -85,6 +85,12 @@ public String stringValue()
return value();
}

@Override
public String prettyPrint()
{
return format( "'%s'", value() );
}

static final class Direct extends StringValue
{
final String value;
Expand Down
5 changes: 5 additions & 0 deletions community/values/src/main/java/org/neo4j/values/Value.java
Expand Up @@ -75,6 +75,11 @@ public Object asLegacyObject()
return asPublic();
}

/**
* Returns a json-like string representation of the current value.
*/
public abstract String prettyPrint();

public abstract ValueGroup valueGroup();

public abstract NumberType numberType();
Expand Down
Expand Up @@ -50,4 +50,10 @@ public Object asPublic()
{
return this;
}

@Override
public String prettyPrint()
{
return null;
}
}

0 comments on commit af5e611

Please sign in to comment.