Extract validateValueIsPowerOfTwo method
@@ -37,6 +37,7 @@ import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
+import static java.util.Objects.requireNonNull;
public final class SystemSessionProperties
{
@@ -139,15 +140,7 @@ public final class SystemSessionProperties
Integer.class,
taskManagerConfig.getWriterCount(),
false,
- value -> {
- int concurrency = ((Number) value).intValue();
- if (Integer.bitCount(concurrency) != 1) {
- throw new PrestoException(
- StandardErrorCode.INVALID_SESSION_PROPERTY,
- format("%s must be a power of 2: %s", TASK_WRITER_COUNT, concurrency));
- }
- return concurrency;
- },
+ value -> validateValueIsPowerOfTwo(value, TASK_WRITER_COUNT),
value -> value),
booleanSessionProperty(
REDISTRIBUTE_WRITES,
@@ -180,15 +173,7 @@ public final class SystemSessionProperties
Integer.class,
taskManagerConfig.getTaskConcurrency(),
false,
- value -> {
- int concurrency = ((Number) value).intValue();
- if (Integer.bitCount(concurrency) != 1) {
- throw new PrestoException(
- StandardErrorCode.INVALID_SESSION_PROPERTY,
- format("%s must be a power of 2: %s", TASK_CONCURRENCY, concurrency));
- }
- return concurrency;
- },
+ value -> validateValueIsPowerOfTwo(value, TASK_CONCURRENCY),
value -> value),
booleanSessionProperty(
TASK_SHARE_INDEX_LOADING,
@@ -652,4 +637,15 @@ public final class SystemSessionProperties
{
return session.getSystemProperty(FILTER_AND_PROJECT_MIN_OUTPUT_PAGE_ROW_COUNT, Integer.class);
}
+
+ private static int validateValueIsPowerOfTwo(Object value, String property)
+ {
+ int intValue = ((Number) requireNonNull(value, "value is null")).intValue();
+ if (Integer.bitCount(intValue) != 1) {
+ throw new PrestoException(
+ StandardErrorCode.INVALID_SESSION_PROPERTY,
+ format("%s must be a power of 2: %s", property, intValue));
+ }
+ return intValue;
+ }
}
