Class Converter<From,To>

java.lang.Object
org.netbeans.validation.api.conversion.Converter<From,To>
Direct Known Subclasses:
SelectedIndicesToButtonModelArrayConverter, SelectedIndicesToListSelectionModelConverter, StringToComboBoxModelConverter, StringToDocumentConverter

public abstract class Converter<From,To> extends Object
Converts validators. Can convert a Validator working on one type (such as String) to a Validator of a different type, such as javax.swing.text.Document. In this way, it is possible to write only validators for Strings, but use them against javax.swing.text.Documents (for validating JTextField and JTextArea components), etc.
Author:
Tim Boudreau
  • Constructor Details

  • Method Details

    • from

      public final Class<From> from()
    • to

      public final Class<To> to()
    • convert

      public abstract Validator<To> convert(Validator<From> from)
      Create a Validator for type To from a validator for type From. For example, a converter that is a factory for Validators of javax.swing.text.Documents from a validator that only handles Strings may be created. (Convert would simply return a Validator that wraps the Validator. At validation time it will first call Document.getText(), and then pass the result to the wrapped Validator).
      Parameters:
      from - The original validator.
      Returns:
      A validator of the type requested
    • convert

      @SafeVarargs public final Validator<To> convert(Validator<From>... froms)
      Will merge the chain of passed validators to one, and then convert it to the requested type. See convert(org.netbeans.validation.api.Validator)
      Parameters:
      froms - A chain of validator to convert.
      Returns:
      A validator of the type requested
    • register

      public static void register(Converter<?,?> converter)
      Register a converter
      Type Parameters:
      From -
      To -
      Parameters:
      converter -
      from -
      to -
    • find

      public static <From,To> Converter<From,To> find(Class<From> from, Class<To> to)
      Find a converter to create validators for one type from validators for another type.
      Type Parameters:
      From - The type of object we get from a component, such as a javax.swing.text.Document
      To - The type of object we want to process, such as a java.lang.String
      Parameters:
      from - A class, such as Document.class
      to - A class such as String.class
      Returns:
      An object which can take validators for type From and produce validators for type To
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object