void updateValue() {
   String value = comboBox.getSelectedValue(relatedGuiField.getName());
   for (FieldSetter fieldSetter : FIELD_SETTERS) {
     if (fieldSetter.handle(relatedGuiFieldComponent)) {
       fieldSetter.setValue(relatedGuiFieldComponent, value);
       break;
     }
   }
 }
示例#2
0
 /**
  * Gets an instance of the config, sets the fields and validates them. The method sets up the
  * configuration by loading properties and parsing command line arguments, then tries to find a
  * constructor of the config class that matches the arguments passed to it, instantiates the
  * config class, sets its fields and validates the instance.
  *
  * @param objects a vararg of Objects passed to a corresponding constructor of the config class.
  * @return An instance of the config class.
  */
 public T build(Object... objects) {
   initializeErrorMessageSetup(propertyLoader);
   setupBuilderConfiguration(propertyLoader);
   T instanceOfConfigClass = constructionHelper.getInstance(configClass, objects);
   fieldSetter.setFields(instanceOfConfigClass, builderConfiguration);
   configValidator.validate(instanceOfConfigClass);
   return instanceOfConfigClass;
 }
示例#3
0
  private void parsePart(String part) {
    int spaceIndex = part.indexOf(' ');
    if (spaceIndex == -1) {
      throw new RuntimeException("couldn't parse duration part " + part);
    }
    String quantityText = part.substring(0, spaceIndex).trim();
    spaceIndex = part.lastIndexOf(' ');
    String unitText = part.substring(spaceIndex + 1).trim().toLowerCase();

    int quantity;
    try {
      quantity = Integer.parseInt(quantityText);
    } catch (NumberFormatException e) {
      throw new RuntimeException(
          "couldn't parse quantity " + quantityText + " in duration text", e);
    }
    FieldSetter fieldSetter = fieldSetters.get(unitText);
    if (fieldSetter == null) {
      throw new RuntimeException("couldn't parse quantity " + quantityText);
    }
    fieldSetter.set(this, quantity);
  }