class ValuePropertiesUtils {

  public static ValueProperties.Builder addOptional(final ValueProperties originalProperties, final String propertyName, final String propertyValue) {
    ArgumentChecker.notNull(originalProperties, "original properties");
    ArgumentChecker.notNull(propertyName, "property name");
    ArgumentChecker.notNull(propertyValue, "property value");
    final Set<String> originalPropertyValues = originalProperties.getValues(propertyName);
    if (originalPropertyValues != null && !originalPropertyValues.equals(Collections.singleton(propertyValue))) {
      throw new IllegalStateException("Property " + propertyName + " already present, but value " + 
          propertyValue + " not equal to " + originalProperties.getValues(propertyName));
    }
    final ValueProperties.Builder newProperties = originalProperties.copy()
        .with(propertyName, propertyValue)
        .withOptional(propertyName);
    return newProperties;
  }

}