/*
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */
package com.facebook.litho;

/**
 * Default provider for a ThreadPoolLayoutHandler. If no values are configured for the pool sizes,
 * it will create a pool with a size of 1.
 *
 * <p>If a fixed size pool is enabled, a ThreadPoolLayoutHandler with a fixed core and max pool size
 * will be provided. Otherwise, it uses the multiplier and increment values passed to the builder to
 * define the core pool size and max pool size as (numProcessors * multiplier + increment).
 */
public class DefaultThreadPoolLayoutHandlerBuilder {

  private boolean mHasFixedSizePool;
  private int mCorePoolSize = 1;
  private int mMaxPoolSize = 1;
  private int mCorePoolSizeMultiplier = 1;
  private int mCorePoolSizeIncrement = 0;
  private int mMaxPoolSizeMultiplier = 1;
  private int mMaxPoolSizeIncrement = 0;

  public DefaultThreadPoolLayoutHandlerBuilder() {}

  public DefaultThreadPoolLayoutHandlerBuilder hasFixedSizePool(boolean hasFixedSizePool) {
    mHasFixedSizePool = hasFixedSizePool;
    return this;
  }

  public DefaultThreadPoolLayoutHandlerBuilder fixedSizePoolConfiguration(
      int corePoolSize, int maxPoolSize) {
    mCorePoolSize = corePoolSize;
    mMaxPoolSize = maxPoolSize;
    return this;
  }

  public DefaultThreadPoolLayoutHandlerBuilder coreDependentPoolConfiguration(
      int corePoolSizeMultiplier,
      int corePoolSizeIncrement,
      int maxPoolSizeMultiplier,
      int maxPoolSizeIncrement) {
    mCorePoolSizeMultiplier = corePoolSizeMultiplier;
    mCorePoolSizeIncrement = corePoolSizeIncrement;
    mMaxPoolSizeMultiplier = maxPoolSizeMultiplier;
    mMaxPoolSizeIncrement = maxPoolSizeIncrement;
    return this;
  }

  /**
   * Creates a ThreadPoolLayoutHandler based on the Builder configuration. If no
   *
   * @return
   */
  public ThreadPoolLayoutHandler build() {
    if (mHasFixedSizePool) {
      return new ThreadPoolLayoutHandler(mCorePoolSize, mMaxPoolSize);
    }

    return new ThreadPoolLayoutHandler(
        new ThreadPoolLayoutHandler.PoolSizeCalculator() {
          @Override
          public int getCorePoolSize(int numProcessors) {
            return numProcessors * mCorePoolSizeMultiplier + mCorePoolSizeIncrement;
          }

          @Override
          public int getMaxPoolSize(int numProcessors) {
            return numProcessors * mMaxPoolSizeMultiplier + mMaxPoolSizeIncrement;
          }
        });
  }
}

@@ -935,35 +935,38 @@
  = 1;%0A  private 
-int
+double
  mCorePoolSizeMu
@@ -1023,35 +1023,38 @@
  = 0;%0A  private 
-int
+double
  mMaxPoolSizeMul
@@ -1600,35 +1600,38 @@
 guration(%0A      
-int
+double
  corePoolSizeMul
@@ -1670,35 +1670,38 @@
 ncrement,%0A      
-int
+double
  maxPoolSizeMult
@@ -2421,32 +2421,39 @@
          return 
+(int) (
 numProcessors * 
@@ -2492,32 +2492,33 @@
 oolSizeIncrement
+)
 ;%0A          %7D%0A%0A 
@@ -2612,16 +2612,23 @@
  return 
+(int) (
 numProce
@@ -2677,24 +2677,25 @@
 izeIncrement
+)
 ;%0A          

Fix incorrect param type for thread pools experiment