Permalink
Browse files

Added NumberOfBytesRange that is ensured to be within the int range

  • Loading branch information...
tinwelint committed Aug 23, 2012
1 parent 56f75d4 commit b6054816ec52b9942d37df11214c175cdb0c332d
Showing with 26 additions and 0 deletions.
  1. +26 −0 kernel/src/main/java/org/neo4j/graphdb/factory/GraphDatabaseSetting.java
@@ -624,6 +624,32 @@ else if ( mem.endsWith( "g" ) )
}
}
+ public static class IntegerRangeNumberOfBytesSetting extends GraphDatabaseSetting<Integer>
+ {
+ private final GraphDatabaseSetting<Long> fullRange;
+
+ public IntegerRangeNumberOfBytesSetting( String name )
+ {
+ super( name, "" );
+ this.fullRange = new NumberOfBytesSetting( name );
+ }
+
+ @Override
+ public void validate( Locale locale, String value )
+ {
+ fullRange.validate( locale, value );
+ }
+
+ @Override
+ public Integer valueOf( String rawValue, Config config )
+ {
+ Long fullValue = fullRange.valueOf( rawValue, config );
+ if ( fullValue.longValue() > Integer.MAX_VALUE )
+ throw new IllegalArgumentException( "Size '" + rawValue + "' too big, keep within integer range (2^32-1)" );
+ return fullValue.intValue();
+ }
+ }
+
public static class ListSetting<T>
extends GraphDatabaseSetting<List<T>>
{

0 comments on commit b605481

Please sign in to comment.