@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 ); }
@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; } } }
@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 ) ) ); }
@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 ); }
@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; } } }