Interface TypedConfigGetter

  • All Known Implementing Classes:
    DefaultTypedConfigGetter

    public interface TypedConfigGetter
    Something that knows how to convert plain strings from a git Config to typed values.
    Since:
    4.9
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int UNSET_INT
      Use Integer#MIN_VALUE as unset int value
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean getBoolean​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, boolean defaultValue)
      Get a boolean value from a git Config.
      <T extends java.lang.Enum<?>>
      T
      getEnum​(Config config, T[] all, java.lang.String section, java.lang.String subsection, java.lang.String name, T defaultValue)
      Parse an enumeration from a git Config.
      int getInt​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, int defaultValue)
      Obtain an integer value from a git Config.
      int getIntInRange​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, int minValue, int maxValue, int defaultValue)
      Obtain an integer value from a git Config which must be in given range.
      long getLong​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, long defaultValue)
      Obtain a long value from a git Config.
      default java.nio.file.Path getPath​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, FS fs, java.io.File resolveAgainst, java.nio.file.Path defaultValue)
      Parse a string value from a git Config and treat it as a file path, replacing a ~/ prefix by the user's home directory.
      java.util.List<RefSpec> getRefSpecs​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name)
      Parse a list of RefSpecs from a git Config.
      long getTimeUnit​(Config config, java.lang.String section, java.lang.String subsection, java.lang.String name, long defaultValue, java.util.concurrent.TimeUnit wantUnit)
      Parse a numerical time unit, such as "1 minute", from a git Config.
    • Field Detail

      • UNSET_INT

        static final int UNSET_INT
        Use Integer#MIN_VALUE as unset int value
        Since:
        6.1
        See Also:
        Constant Field Values
    • Method Detail

      • getBoolean

        boolean getBoolean​(Config config,
                           java.lang.String section,
                           java.lang.String subsection,
                           java.lang.String name,
                           boolean defaultValue)
        Get a boolean value from a git Config.
        Parameters:
        config - to get the value from
        section - section the key is grouped within.
        subsection - subsection name, such a remote or branch name.
        name - name of the key to get.
        defaultValue - default value to return if no value was present.
        Returns:
        true if any value or defaultValue is true, false for missing or explicit false
      • getEnum

        <T extends java.lang.Enum<?>> T getEnum​(Config config,
                                                T[] all,
                                                java.lang.String section,
                                                java.lang.String subsection,
                                                java.lang.String name,
                                                T defaultValue)
        Parse an enumeration from a git Config.
        Parameters:
        config - to get the value from
        all - all possible values in the enumeration which should be recognized. Typically EnumType.values().
        section - section the key is grouped within.
        subsection - subsection name, such a remote or branch name.
        name - name of the key to get.
        defaultValue - default value to return if no value was present.
        Returns:
        the selected enumeration value, or defaultValue.
      • getInt

        int getInt​(Config config,
                   java.lang.String section,
                   java.lang.String subsection,
                   java.lang.String name,
                   int defaultValue)
        Obtain an integer value from a git Config.
        Parameters:
        config - to get the value from
        section - section the key is grouped within.
        subsection - subsection name, such a remote or branch name.
        name - name of the key to get.
        defaultValue - default value to return if no value was present.
        Returns:
        an integer value from the configuration, or defaultValue.
      • getIntInRange

        int getIntInRange​(Config config,
                          java.lang.String section,
                          java.lang.String subsection,
                          java.lang.String name,
                          int minValue,
                          int maxValue,
                          int defaultValue)
        Obtain an integer value from a git Config which must be in given range.
        Parameters:
        config - to get the value from
        section - section the key is grouped within.
        subsection - subsection name, such a remote or branch name.
        name - name of the key to get.
        minValue - minimal value
        maxValue - maximum value
        defaultValue - default value to return if no value was present. Use #UNSET_INT to set the default to unset.
        Returns:
        an integer value from the configuration, or defaultValue. #UNSET_INT if unset.
        Since:
        6.1
      • getLong

        long getLong​(Config config,
                     java.lang.String section,
                     java.lang.String subsection,
                     java.lang.String name,
                     long defaultValue)
        Obtain a long value from a git Config.
        Parameters:
        config - to get the value from
        section - section the key is grouped within.
        subsection - subsection name, such a remote or branch name.
        name - name of the key to get.
        defaultValue - default value to return if no value was present.
        Returns:
        a long value from the configuration, or defaultValue.
      • getTimeUnit

        long getTimeUnit​(Config config,
                         java.lang.String section,
                         java.lang.String subsection,
                         java.lang.String name,
                         long defaultValue,
                         java.util.concurrent.TimeUnit wantUnit)
        Parse a numerical time unit, such as "1 minute", from a git Config.
        Parameters:
        config - to get the value from
        section - section the key is in.
        subsection - subsection the key is in, or null if not in a subsection.
        name - the key name.
        defaultValue - default value to return if no value was present.
        wantUnit - the units of defaultValue and the return value, as well as the units to assume if the value does not contain an indication of the units.
        Returns:
        the value, or defaultValue if not set, expressed in units.
      • getPath

        default java.nio.file.Path getPath​(Config config,
                                           java.lang.String section,
                                           java.lang.String subsection,
                                           java.lang.String name,
                                           @NonNull
                                           FS fs,
                                           java.io.File resolveAgainst,
                                           java.nio.file.Path defaultValue)
        Parse a string value from a git Config and treat it as a file path, replacing a ~/ prefix by the user's home directory.

        Note: this may throw InvalidPathException if the string is not a valid path.

        Parameters:
        config - to get the path from.
        section - section the key is in.
        subsection - subsection the key is in, or null if not in a subsection.
        name - the key name.
        fs - to use to convert the string into a path.
        resolveAgainst - directory to resolve the path against if it is a relative path.
        defaultValue - to return if no value was present
        Returns:
        the Path, or defaultValue if not set
        Since:
        5.10
      • getRefSpecs

        @NonNull
        java.util.List<RefSpec> getRefSpecs​(Config config,
                                            java.lang.String section,
                                            java.lang.String subsection,
                                            java.lang.String name)
        Parse a list of RefSpecs from a git Config.
        Parameters:
        config - to get the list from
        section - section the key is in.
        subsection - subsection the key is in, or null if not in a subsection.
        name - the key name.
        Returns:
        a possibly empty list of RefSpecs