Skip to content

Commit

Permalink
Introduce Types for ascii, basic multilingual plane and alpha numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Sep 17, 2018
1 parent 57c6866 commit 9fa378b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.values.storable;

import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.collections.impl.factory.Lists;

import java.lang.reflect.Array;
import java.time.Duration;
Expand Down Expand Up @@ -82,7 +81,10 @@ public enum Types
LONG( ValueGroup.NUMBER, LongValue.class ),
FLOAT( ValueGroup.NUMBER, FloatValue.class ),
DOUBLE( ValueGroup.NUMBER, DoubleValue.class ),
STRING( ValueGroup.TEXT, UTF8StringValue.class ),
STRING( ValueGroup.TEXT, TextValue.class ),
STRING_ALPHANUMERIC( ValueGroup.TEXT, TextValue.class ),
STRING_ASCII( ValueGroup.TEXT, TextValue.class ),
STRING_BMP( ValueGroup.TEXT, TextValue.class ),
LOCAL_DATE_TIME( ValueGroup.LOCAL_DATE_TIME, LocalDateTimeValue.class ),
DATE( ValueGroup.DATE, DateValue.class ),
LOCAL_TIME( ValueGroup.LOCAL_TIME, LocalTimeValue.class ),
Expand All @@ -102,6 +104,9 @@ public enum Types
FLOAT_ARRAY( ValueGroup.NUMBER_ARRAY, FloatArray.class, true ),
DOUBLE_ARRAY( ValueGroup.NUMBER_ARRAY, DoubleArray.class, true ),
STRING_ARRAY( ValueGroup.TEXT_ARRAY, StringArray.class, true ),
STRING_ALPHANUMERIC_ARRAY( ValueGroup.TEXT_ARRAY, StringArray.class, true ),
STRING_ASCII_ARRAY( ValueGroup.TEXT_ARRAY, StringArray.class, true ),
STRING_BMP_ARRAY( ValueGroup.TEXT_ARRAY, StringArray.class, true ),
LOCAL_DATE_TIME_ARRAY( ValueGroup.LOCAL_DATE_TIME_ARRAY, LocalDateTimeArray.class, true ),
DATE_ARRAY( ValueGroup.DATE_ARRAY, DateArray.class, true ),
LOCAL_TIME_ARRAY( ValueGroup.LOCAL_TIME_ARRAY, LocalTimeArray.class, true ),
Expand Down Expand Up @@ -132,16 +137,16 @@ public enum Types

static Types[] arrayTypes()
{
return Lists.mutable.of( Types.values() )
.select( t -> t.arrayType )
.toArray( new Types[0] );
return Arrays.stream( Types.values() )
.filter( t -> t.arrayType )
.toArray( Types[]::new );
}

static Types[] nonArrayTypes()
{
return Lists.mutable.of( Types.values() )
.select( t -> !t.arrayType )
.toArray( new Types[0] );
return Arrays.stream( Types.values() )
.filter( t -> !t.arrayType )
.toArray( Types[]::new );
}
}

Expand Down Expand Up @@ -294,9 +299,9 @@ public Value nextValueOfTypes( Types... types )

public Types[] excluding( Types... types )
{
return Lists.mutable.of( Types.values() )
.withoutAll( Arrays.asList( types ) )
.toArray( new Types[Types.values().length - types.length] );
return Arrays.stream( Types.values() )
.filter( t -> !ArrayUtils.contains( types, t ) )
.toArray( Types[]::new );
}

public Value nextValueOfType( Types type )
Expand All @@ -319,6 +324,12 @@ public Value nextValueOfType( Types type )
return nextFloatValue();
case DOUBLE:
return nextDoubleValue();
case STRING_ALPHANUMERIC:
return nextAlphaNumericTextValue();
case STRING_ASCII:
return nextAsciiTextValue();
case STRING_BMP:
return nextBasicMultilingualPlaneTextValue();
case LOCAL_DATE_TIME:
return nextLocalDateTimeValue();
case DATE:
Expand Down Expand Up @@ -357,6 +368,12 @@ public Value nextValueOfType( Types type )
return nextDoubleArray();
case STRING_ARRAY:
return nextStringArray();
case STRING_ALPHANUMERIC_ARRAY:
return nextAlphaNumericStringArray();
case STRING_ASCII_ARRAY:
return nextAsciiTextArray();
case STRING_BMP_ARRAY:
return nextBasicMultilingualPlaneTextArray();
case LOCAL_DATE_TIME_ARRAY:
return nextLocalDateTimeArray();
case DATE_ARRAY:
Expand Down Expand Up @@ -1355,6 +1372,28 @@ public String[] nextAlphaNumericStringArrayRaw( int minLength, int maxLength, in
return strings;
}

private TextArray nextAsciiTextArray()
{
int length = intBetween( configuration.arrayMinLength(), configuration.arrayMaxLength() );
String[] strings = new String[length];
for ( int i = 0; i < length; i++ )
{
strings[i] = nextAsciiTextValue( configuration.stringMinLength(), configuration.stringMaxLength() ).stringValue();
}
return Values.stringArray( strings );
}

private TextArray nextBasicMultilingualPlaneTextArray()
{
int length = intBetween( configuration.arrayMinLength(), configuration.arrayMaxLength() );
String[] strings = new String[length];
for ( int i = 0; i < length; i++ )
{
strings[i] = nextBasicMultilingualPlaneTextValue( configuration.stringMinLength(), configuration.stringMaxLength() ).stringValue();
}
return Values.stringArray( strings );
}

/**
* Returns the next pseudorandom {@link TextArray}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class RandomValuesTest
{
private static final int ITERATIONS = 500;

@Parameterized.Parameter( 0 )
@Parameterized.Parameter()
public RandomValues randomValues;

@Parameterized.Parameter( 1 )
Expand Down

0 comments on commit 9fa378b

Please sign in to comment.