ValuePropertiesUtils { public static ValueProperties.Builder getAllOptional(final ValueProperties originalProperties) { ArgumentChecker.notNull(originalProperties, "original properties"); final ValueProperties.Builder optionalProperties = ValueProperties.builder(); for (String propertyName : originalProperties.getProperties()) { if (originalProperties.isOptional(propertyName)) { final Set<String> propertyValues = originalProperties.getValues(propertyName); if (propertyValues == null || propertyValues.isEmpty()) { optionalProperties.withAny(propertyName).withOptional(propertyName); } else { optionalProperties.with(propertyName, propertyValues).withOptional(propertyName); } } } return optionalProperties; }  static ValueProperties.Builder addOptional(final ValueProperties originalProperties, final String propertyName, final String propertyValue); static ValueProperties.Builder addAllOptional(final ValueProperties originalProperties, final ValueProperties propertiesToAdd); static void withAllOptional(final ValueProperties.Builder properties, final ValueProperties propertiesToAdd); static ValueProperties.Builder removeAll(final ValueProperties originalProperties, final String... propertiesToRemove); static ValueProperties.Builder getAllOptional(final ValueProperties originalProperties);  }
@Test public void testGetAllOptional() { assertEquals(ValueProperties.builder().get(), ValuePropertiesUtils.getAllOptional(CURVE_PROPERTIES).get()); final ValueProperties properties = ValueProperties.builder() .with(ValuePropertyNames.CURVE, "CurveName").withOptional(ValuePropertyNames.CURVE) .with(ValuePropertyNames.CURVE_CALCULATION_CONFIG, "CurveCalculationConfigName") .with(ValuePropertyNames.CURVE_CALCULATION_METHOD, "CurveCalculationMethodName") .with(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG, "PayCurveCalculationConfigName").withOptional(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG) .withAny(ValuePropertyNames.RECEIVE_CURVE).withOptional(ValuePropertyNames.RECEIVE_CURVE) .with(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG, "ReceiveCurveName1", "ReceiveCurveName2").withOptional(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG) .get(); final ValueProperties expectedProperties = ValueProperties.builder() .with(ValuePropertyNames.CURVE, "CurveName").withOptional(ValuePropertyNames.CURVE) .with(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG, "PayCurveCalculationConfigName").withOptional(ValuePropertyNames.PAY_CURVE_CALCULATION_CONFIG) .withAny(ValuePropertyNames.RECEIVE_CURVE).withOptional(ValuePropertyNames.RECEIVE_CURVE) .with(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG, "ReceiveCurveName1", "ReceiveCurveName2").withOptional(ValuePropertyNames.RECEIVE_CURVE_CALCULATION_CONFIG) .get(); final ValueProperties optionalProperties = ValuePropertiesUtils.getAllOptional(properties).get(); assertFalse(properties == optionalProperties); assertEquals(expectedProperties, optionalProperties); }