private SurfaceMetadata updateSurfaceMetadata(Set<DoublesPair> pairs) {
   SurfaceMetadata surfaceMetadata = surface.getMetadata();
   List<SurfaceParameterMetadata> sortedMetaList = new ArrayList<SurfaceParameterMetadata>();
   if (surfaceMetadata.getParameterMetadata().isPresent()) {
     List<SurfaceParameterMetadata> metaList =
         new ArrayList<SurfaceParameterMetadata>(surfaceMetadata.getParameterMetadata().get());
     for (DoublesPair pair : pairs) {
       metadataLoop:
       for (SurfaceParameterMetadata parameterMetadata : metaList) {
         ArgChecker.isTrue(
             parameterMetadata instanceof GenericVolatilitySurfaceYearFractionMetadata,
             "Surface parameter metadata must be instance of GenericVolatilitySurfaceYearFractionMetadata");
         GenericVolatilitySurfaceYearFractionMetadata casted =
             (GenericVolatilitySurfaceYearFractionMetadata) parameterMetadata;
         if (pair.getFirst() == casted.getYearFraction()
             && pair.getSecond() == casted.getStrike().getValue()) {
           sortedMetaList.add(casted);
           metaList.remove(parameterMetadata);
           break metadataLoop;
         }
       }
     }
     ArgChecker.isTrue(
         metaList.size() == 0,
         "Mismatch between surface parameter metadata list and doubles pair list");
   } else {
     for (DoublesPair pair : pairs) {
       GenericVolatilitySurfaceYearFractionMetadata parameterMetadata =
           GenericVolatilitySurfaceYearFractionMetadata.of(
               pair.getFirst(), SimpleStrike.of(pair.getSecond()));
       sortedMetaList.add(parameterMetadata);
     }
   }
   return surfaceMetadata.withParameterMetadata(sortedMetaList);
 }
 @Test
 public void testMultiply() {
   final InterestRateCurveSensitivity sensitivity1 =
       new InterestRateCurveSensitivity(SENSITIVITY_11);
   final InterestRateCurveSensitivity sensitivity2 =
       new InterestRateCurveSensitivity(SENSITIVITY_12);
   final InterestRateCurveSensitivity sensitivity3 =
       new InterestRateCurveSensitivity(SENSITIVITY_22);
   final InterestRateCurveSensitivity sensitivity4 =
       new InterestRateCurveSensitivity(SENSITIVITY_33);
   final double factor = Math.random() - 1;
   final List<DoublesPair> list1 = new ArrayList<>();
   final List<DoublesPair> list2 = new ArrayList<>();
   final List<DoublesPair> list3 = new ArrayList<>();
   for (final DoublesPair pair : SENSITIVITY_DATA_1) {
     list1.add(DoublesPair.of(pair.getFirst(), pair.getSecond() * factor));
   }
   for (final DoublesPair pair : SENSITIVITY_DATA_2) {
     final DoublesPair scaledPair = DoublesPair.of(pair.getFirst(), pair.getSecond() * factor);
     list1.add(scaledPair);
     list2.add(scaledPair);
   }
   for (final DoublesPair pair : SENSITIVITY_DATA_3) {
     list3.add(DoublesPair.of(pair.getFirst(), pair.getSecond() * factor));
   }
   final Map<String, List<DoublesPair>> map = new HashMap<>();
   map.put(CURVE_NAME_1, list1);
   map.put(CURVE_NAME_2, list2);
   map.put(CURVE_NAME_3, list3);
   final InterestRateCurveSensitivity expected = new InterestRateCurveSensitivity(map);
   final InterestRateCurveSensitivity actualUnscaled =
       sensitivity1.plus(sensitivity2).plus(sensitivity3).plus(sensitivity4);
   InterestRateCurveSensitivity actual = actualUnscaled.multipliedBy(factor);
   assertFalse(actualUnscaled == actual);
   assertFalse(actualUnscaled.getSensitivities() == actual.getSensitivities());
   assertEquals(expected, actual);
   actual =
       sensitivity1
           .multipliedBy(factor)
           .plus(sensitivity2.multipliedBy(factor))
           .plus(sensitivity3.multipliedBy(factor))
           .plus(sensitivity4.multipliedBy(factor));
   assertEquals(expected, actual);
 }
  private void assertIRCSEquals(
      final InterestRateCurveSensitivity expected, final InterestRateCurveSensitivity actual) {
    final Iterator<Map.Entry<String, List<DoublesPair>>> expectedIterator =
        new TreeMap<>(expected.getSensitivities()).entrySet().iterator();
    final Iterator<Map.Entry<String, List<DoublesPair>>> actualIterator =
        new TreeMap<>(actual.getSensitivities()).entrySet().iterator();
    do {
      final Map.Entry<String, List<DoublesPair>> expectedEntry = expectedIterator.next();
      final Map.Entry<String, List<DoublesPair>> actualEntry = actualIterator.next();
      assertEquals(expectedEntry.getKey(), actualEntry.getKey());
      assertEquals(expectedEntry.getValue().size(), actualEntry.getValue().size());
      for (int i = 0; i < expectedEntry.getValue().size(); i++) {
        final DoublesPair expectedPair = expectedEntry.getValue().get(i);
        final DoublesPair actualPair = actualEntry.getValue().get(i);
        assertEquals(expectedPair.getFirst(), actualPair.getFirst(), EPS);
        assertEquals(expectedPair.getSecond(), actualPair.getSecond(), EPS);
      }

    } while (expectedIterator.hasNext() && actualIterator.hasNext());
  }
 @Test
 public void testCompareDifferentValues() {
   AssertSensitivityObjects.assertEquals(
       "", new InterestRateCurveSensitivity(), new InterestRateCurveSensitivity(), EPS);
   final TreeMap<String, List<DoublesPair>> sortedMap = new TreeMap<>(SENSITIVITY_11);
   final InterestRateCurveSensitivity sensitivity1 = new InterestRateCurveSensitivity(sortedMap);
   final InterestRateCurveSensitivity sensitivity2 =
       new InterestRateCurveSensitivity(SENSITIVITY_12);
   AssertSensitivityObjects.assertDoesNotEqual("", sensitivity1, sensitivity2, EPS);
   final Map<String, List<DoublesPair>> map = Maps.newTreeMap();
   final double eps = 1e-4;
   for (final Map.Entry<String, List<DoublesPair>> entry : sortedMap.entrySet()) {
     final List<DoublesPair> list = new ArrayList<>();
     for (final DoublesPair pair : entry.getValue()) {
       list.add(DoublesPair.of(pair.getFirst(), pair.getSecond() + 0.01 * eps));
     }
     map.put(entry.getKey(), list);
   }
   final InterestRateCurveSensitivity sensitivity3 = new InterestRateCurveSensitivity(map);
   AssertSensitivityObjects.assertEquals("", sensitivity1, sensitivity3, eps);
   AssertSensitivityObjects.assertDoesNotEqual("", sensitivity1, sensitivity3, EPS);
 }