public static int compareTextArrays( TextArray a, TextArray b ) { int i = 0; int x = 0; int length = Math.min( a.length(), b.length() ); while ( x == 0 && i < length ) { x = a.stringValue( i ).compareTo( b.stringValue( i ) ); i++; } if ( x == 0 ) { x = a.length() - b.length(); } return x; } }
public static Special writeNode( long nodeId, TextArray labels, MapValue properties ) { return new Special( SpecialKind.WriteNode, Arrays.hashCode( new Object[]{nodeId, properties} ) + 31 * labels.hashCode() ); }
@Override public void writeNode( long nodeId, TextArray labels, MapValue properties ) throws IOException { packStructHeader( NODE_SIZE, NODE ); pack( nodeId ); packListHeader( labels.length() ); for ( int i = 0; i < labels.length(); i++ ) { labels.value( i ).writeTo( this ); } properties.writeTo( this ); }
@Test void shouldHandleArrays() { // Given PrettyPrinter printer = new PrettyPrinter(); TextArray array = Values.stringArray( "a", "b", "c" ); // When array.writeTo( printer ); // Then assertThat( printer.value(), equalTo( "[\"a\", \"b\", \"c\"]" ) ); }
@Override public void writeNode( long nodeId, TextArray labels, MapValue properties ) { append( format( "(id=%d", nodeId ) ); String sep = " "; for ( int i = 0; i < labels.length(); i++ ) { append( sep ); append( ":" + labels.stringValue( i ) ); sep = ""; } if ( properties.size() > 0 ) { append( " " ); properties.writeTo( this ); } append( ")" ); }
@Override public void writeNode( long nodeId, TextArray labels, MapValue properties ) throws IOException { packStructHeader( NODE_SIZE, NODE ); pack( nodeId ); packListHeader( labels.length() ); for ( int i = 0; i < labels.length(); i++ ) { labels.value( i ).writeTo( this ); } properties.writeTo( this ); }
private static int worstCaseLength( AnyValue value ) { if ( value.isSequenceValue() ) { SequenceValue sequenceValue = (SequenceValue) value; if ( sequenceValue instanceof TextArray ) { TextArray textArray = (TextArray) sequenceValue; int length = 0; for ( int i = 0; i < textArray.length(); i++ ) { length += stringWorstCaseLength( textArray.stringValue( i ).length() ); } return length; } return sequenceValue.length() * BIGGEST_STATIC_SIZE; } else { switch ( ((Value) value).valueGroup().category() ) { case TEXT: // For text, which is very dynamic in its nature do a worst-case off of number of characters in it return stringWorstCaseLength( ((TextValue) value).length() ); default: // For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy return BIGGEST_STATIC_SIZE; } } }
@Test public void shouldBeAbleToPackAndUnpackList() throws IOException { // Given PackedOutputArray output = new PackedOutputArray(); Neo4jPack.Packer packer = neo4jPack.newPacker( output ); packer.packListHeader( ALICE.labels().length() ); List<String> expected = new ArrayList<>(); TextArray labels = ALICE.labels(); for ( int i = 0; i < labels.length(); i++ ) { String labelName = labels.stringValue( i ); packer.pack( labelName ); expected.add( labelName ); } AnyValue unpacked = unpacked( output.bytes() ); // Then assertThat( unpacked, instanceOf( ListValue.class ) ); ListValue unpackedList = (ListValue) unpacked; assertThat( unpackedList, equalTo( ValueUtils.asListValue( expected ) ) ); }
public static int compareTextArrays( TextArray a, TextArray b ) { int i = 0; int x = 0; int length = Math.min( a.length(), b.length() ); while ( x == 0 && i < length ) { x = a.stringValue( i ).compareTo( b.stringValue( i ) ); i++; } if ( x == 0 ) { x = a.length() - b.length(); } return x; } }
@Override public void writeNode( long nodeId, TextArray labels, MapValue properties ) { append( format( "(id=%d", nodeId ) ); String sep = " "; for ( int i = 0; i < labels.length(); i++ ) { append( sep ); append( ":" + labels.stringValue( i ) ); sep = ""; } if ( properties.size() > 0 ) { append( " " ); properties.writeTo( this ); } append( ")" ); }
private static int worstCaseLength( AnyValue value ) { if ( value.isSequenceValue() ) { SequenceValue sequenceValue = (SequenceValue) value; if ( sequenceValue instanceof TextArray ) { TextArray textArray = (TextArray) sequenceValue; int length = 0; for ( int i = 0; i < textArray.length(); i++ ) { length += stringWorstCaseLength( textArray.stringValue( i ).length() ); } return length; } return sequenceValue.length() * BIGGEST_STATIC_SIZE; } else { switch ( ((Value) value).valueGroup().category() ) { case TEXT: // For text, which is very dynamic in its nature do a worst-case off of number of characters in it return stringWorstCaseLength( ((TextValue) value).length() ); default: // For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy return BIGGEST_STATIC_SIZE; } } }