Class Naming

  • All Implemented Interfaces:
    com.google.common.base.Function<java.lang.String,​java.lang.String>, java.util.function.Function<java.lang.String,​java.lang.String>
    Direct Known Subclasses:
    Naming.ConstantNaming, Naming.JavaBeanNaming, Naming.PrefixSuffixNaming

    public abstract class Naming
    extends java.lang.Object
    implements com.google.common.base.Function<java.lang.String,​java.lang.String>
    Converter-like function to apply or extract naming, derived from input.
    • Field Detail

      • NAME_PLACEHOLDER

        private static final java.lang.String NAME_PLACEHOLDER
        See Also:
        Constant Field Values
      • TEMPLATE_SPLITTER

        private static final com.google.common.base.Splitter TEMPLATE_SPLITTER
      • TEMPLATE_CHAR_MATCHER

        private static final com.google.common.base.CharMatcher TEMPLATE_CHAR_MATCHER
      • IDENTITY_NAMING

        private static final Naming IDENTITY_NAMING
    • Constructor Detail

      • Naming

        private Naming()
    • Method Detail

      • apply

        public abstract java.lang.String apply​(java.lang.String input)
        Applies naming to input identifier, converting it to desired naming.
        Specified by:
        apply in interface com.google.common.base.Function<java.lang.String,​java.lang.String>
        Specified by:
        apply in interface java.util.function.Function<java.lang.String,​java.lang.String>
        Parameters:
        input - the input identifier
        Returns:
        applied naming
      • detect

        public abstract java.lang.String detect​(java.lang.String identifier)
        Tries to extract source identifier name out of already applied naming.
        Parameters:
        identifier - to detect naming from
        Returns:
        empty string if nothing detected
      • isIdentity

        public abstract boolean isIdentity()
        Checks if it's identity naming.
        Returns:
        true, if is identity naming
        See Also:
        identity()
      • isConstant

        public abstract boolean isConstant()
        Checks if is constant naming. Verbatim naming convention do not use any supplied input name as base. Consider example factory method "from" constant naming, contrary to the factory method "newMyType" uses "MyType" as and input applying "new" prefix.
        Returns:
        true, if is constant
      • requireNonConstant

        public abstract Naming requireNonConstant​(Naming.Preference preference)
        Returns non-contant naming which is this. Sometimes context require naming should be non-contant, otherwise names will clash in shared identifier scope. If this naming is constant, then it is turned into corresponding prefix naming.
        Parameters:
        preference - preference for prefix or suffix naming
        Returns:
        non-constant naming template or this if already non-constant
      • requireJavaBeanConvention

        public abstract Naming requireJavaBeanConvention()
        Require naming to follow JavaBeam capitalization convention.

        See 8.8 Capitalization of inferred names

         Thus when we extract a property or event name from the middle of an existing Java name, we
         normally convert the first character to lower case. However to support the occasional use of all
         upper-case names, we check if the first two characters of the name are both upper case and if
         so leave it alone. So for example, "FooBah" becomes "fooBah", "Z" becomes "z", "URL" becomes "URL"
         
        See Also:
        javabean spec
      • identity

        public static Naming identity()
        Naming the repeats the input name
        Returns:
        identity naming
      • from

        public static Naming from​(java.lang.String template)
        Parameters:
        template - template string
        Returns:
        naming that could be applied or detected following template
      • fromAll

        public static Naming[] fromAll​(java.lang.String... templates)