Class NameUtils


  • @Internal
    public class NameUtils
    extends java.lang.Object
    Helpers for extracting the name of objects and classes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  NameUtils.NameOverride
      Classes may implement this interface to change how names are generated for their instances.
    • Constructor Summary

      Constructors 
      Constructor Description
      NameUtils()  
    • Constructor Detail

      • NameUtils

        public NameUtils()
    • Method Detail

      • approximateSimpleName

        public static java.lang.String approximateSimpleName​(java.lang.Object object)
        As approximateSimpleName(Object, String) but returning "Anonymous" when object is an instance of anonymous class.
      • approximateSimpleName

        public static java.lang.String approximateSimpleName​(java.lang.Object object,
                                                             java.lang.String anonymousValue)
        Returns a simple name describing a class that is being used as a function (eg., a DoFn or Combine.CombineFn, etc.).

        Note: this is non-invertible - the name may be simplified to an extent that it cannot be mapped back to the original class.

        This can be used to generate human-readable names. It removes the package and outer classes from the name, and removes common suffixes.

        If the object is an instanceof NameUtils.NameOverride, the result of NameUtils.NameOverride.getNameOverride() is returned. This allows classes that act as wrappers to override the handling of names by delegating to the objects they wrap.

        If the class is anonymous, the string anonymousValue is returned.

        Examples:

        • some.package.Word.SummaryDoFn becomes "Summary"
        • another.package.PairingFn becomes "Pairing"
      • approximatePTransformName

        public static java.lang.String approximatePTransformName​(java.lang.Class<?> clazz)
        Returns a name for a PTransform class.

        This can be used to generate human-readable transform names. It removes the package from the name, and removes common suffixes.

        It is different than approximateSimpleName:

        • 1. It keeps the outer classes names.
        • 2. It removes the common transform inner class: "Bound".
        • 3. For classes generated by AutoValue, whose names start with AutoValue_, it delegates to the (parent) class declared in the user's source code.

        Examples:

        • some.package.Word.Summary becomes "Word.Summary"
        • another.package.Pairing.Bound becomes "Pairing"