/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.web.analytics.formatting;

import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Sets;
import com.opengamma.analytics.financial.model.volatility.surface.VolatilitySurface;
import com.opengamma.analytics.math.surface.DoublesSurface;
import com.opengamma.analytics.math.surface.Surface;
import com.opengamma.engine.value.ValueSpecification;

/**
 *
 */
/* package */ class VolatilitySurfaceFormatter extends AbstractFormatter<VolatilitySurface> {

  private static final Logger s_logger = LoggerFactory.getLogger(VolatilitySurfaceFormatter.class);

  /* package */ VolatilitySurfaceFormatter() {
    super(VolatilitySurface.class);
    addFormatter(new Formatter<VolatilitySurface>(Format.EXPANDED) {
      @Override
      Object format(VolatilitySurface value, ValueSpecification valueSpec, Object inlineKey) {
        return SurfaceFormatterUtils.formatExpanded(value.getSurface());
      }
    });
  }

  @Override
  public String formatCell(VolatilitySurface value, ValueSpecification valueSpec, Object inlineKey) {
    Surface<Double, Double, Double> inputSurface = value.getSurface();
    if (inputSurface instanceof DoublesSurface) {
      Set<Double> uniqueXValues = Sets.newHashSet(inputSurface.getXData());
      Set<Double> uniqueYValues = Sets.newHashSet(inputSurface.getYData());
      return "Volatility Surface (" + uniqueXValues.size() + " x " + uniqueYValues.size() + ")";
    } else {
      // TODO ConstantDoublesSurface
      s_logger.warn("Unable to format surface of type {}", inputSurface.getClass());
      return null;
    }
  }

  /**
   * Returns {@link DataType#UNKNOWN UNKNOWN} because the type can be differ for different instances of
   * {@link VolatilitySurface} depending on the type returned by {@link VolatilitySurface#getSurface() getSurface()}.
   * The type for a given surface instance can be obtained from {@link #getDataTypeForValue}
   * @return {@link DataType#UNKNOWN}
   */
  @Override
  public DataType getDataType() {
    return DataType.UNKNOWN;
  }

  @Override
  public DataType getDataTypeForValue(VolatilitySurface value) {
    return SurfaceFormatterUtils.getDataType(value.getSurface());
  }
}

@@ -377,32 +377,100 @@
 atilitySurface;%0A
+import com.opengamma.analytics.math.surface.ConstantDoublesSurface;%0A
 import com.openg
@@ -1684,46 +1684,165 @@
 lse 
-%7B%0A      // TODO ConstantDoublesSurface
+if (inputSurface instanceof ConstantDoublesSurface) %7B%0A      return %22Constant Volatility Surface (z = %22 + inputSurface.getZValue(0.0, 0.0) + %22)%22;%0A    %7D else %7B
 %0A   

Add cell formatter for ConstantDoublesSurface