class UnitParameterSensitivity implements ImmutableBean, Serializable {

  public static UnitParameterSensitivity combine(
      MarketDataName<?> marketDataName,
      UnitParameterSensitivity... sensitivities) {

    ArgChecker.notEmpty(sensitivities, "sensitivities");
    if (sensitivities.length < 2) {
      throw new IllegalArgumentException("At least two sensitivity instances must be specified");
    }
    int size = Stream.of(sensitivities).mapToInt(s -> s.getParameterCount()).sum();
    double[] combinedSensitivities = new double[size];
    ImmutableList.Builder<ParameterMetadata> combinedMeta = ImmutableList.builder();
    ImmutableList.Builder<ParameterSize> split = ImmutableList.builder();
    int count = 0;
    for (int i = 0; i < sensitivities.length; i++) {
      UnitParameterSensitivity sens = sensitivities[i];
      System.arraycopy(sens.getSensitivity().toArrayUnsafe(), 0, combinedSensitivities, count, sens.getParameterCount());
      combinedMeta.addAll(sens.getParameterMetadata());
      split.add(ParameterSize.of(sens.getMarketDataName(), sens.getParameterCount()));
      count += sens.getParameterCount();
    }

    return new UnitParameterSensitivity(
        marketDataName, combinedMeta.build(), DoubleArray.ofUnsafe(combinedSensitivities), split.build());
  }

  private  UnitParameterSensitivity(
      MarketDataName<?> marketDataName,
      List<? extends ParameterMetadata> parameterMetadata,
      DoubleArray sensitivity,
      List<ParameterSize> parameterSplit);

}