Class ConversionTable

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class ConversionTable
    extends java.lang.Object
    implements java.lang.Cloneable
    Contains conversions functions organized by value's type. A ConversionTable grows as necessary.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConversionTable()
      Creates a new empty ConversionTable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ConversionTable chainThen​(ConversionTable after)
      Returns a ConversionTable that behaves as if the specified table was applied just after this table, for every conversion.
      ConversionTable clone()  
      boolean contains​(java.lang.Class<?> classToConvert)
      Checks that a function is defined for the specified class.
      java.lang.Object convert​(java.lang.Object value)
      Converts a value using the conversion function that corresponds to its type.
      void convertDeep​(Config config)
      Performs a deep in-place conversion of a Config.
      void convertShallow​(Config config)
      Performs a shallow in-place conversion of a Config.
      <T> void put​(java.lang.Class<T> classToConvert, java.util.function.Function<? super T,​java.lang.Object> conversionFunction)
      Puts a conversion function to the table.
      void remove​(java.lang.Class<?> classToConvert)
      Removes the function that is currently defined for the specified class, if any.
      java.lang.String toString()  
      UnmodifiableConfig wrap​(UnmodifiableConfig config)
      Returns an UnmodifiableConfig that converts "just-in-time" the values of the specified UnmodifiableConfig.
      CommentedConfig wrapRead​(CommentedConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      Config wrapRead​(Config config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      CommentedFileConfig wrapRead​(CommentedFileConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      FileConfig wrapRead​(FileConfig config)
      Returns an Config that converts "just-in-time" the values that are read from the specified Config.
      CommentedConfig wrapWrite​(CommentedConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      Config wrapWrite​(Config config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      CommentedFileConfig wrapWrite​(CommentedFileConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      FileConfig wrapWrite​(FileConfig config, java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
      Returns an Config that converts "just-in-time" the values that are put into the specified Config.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ConversionTable

        public ConversionTable()
        Creates a new empty ConversionTable.
    • Method Detail

      • put

        public <T> void put​(java.lang.Class<T> classToConvert,
                            java.util.function.Function<? super T,​java.lang.Object> conversionFunction)
        Puts a conversion function to the table. If a function is already defined for the specified class then it is replaced.
        Type Parameters:
        T - the type of the values that the function can convert
        Parameters:
        classToConvert - the class of the values that the function can convert, may be null
        conversionFunction - the conversion function
      • remove

        public void remove​(java.lang.Class<?> classToConvert)
        Removes the function that is currently defined for the specified class, if any.
        Parameters:
        classToConvert - the class of the values that the function we want to remove converts
      • contains

        public boolean contains​(java.lang.Class<?> classToConvert)
        Checks that a function is defined for the specified class.
        Parameters:
        classToConvert - the class of the values that the function converts
        Returns:
        true if the table contains a function for the class, false otherwise
      • convert

        public java.lang.Object convert​(java.lang.Object value)
        Converts a value using the conversion function that corresponds to its type.
        Parameters:
        value - the value to convert, may be null
        Returns:
        the result of the conversion
      • convertShallow

        public void convertShallow​(Config config)
        Performs a shallow in-place conversion of a Config. Each first-level value of the config is converted using the conversion function that corresponds to its type.
        Parameters:
        config - the config to convert
      • convertDeep

        public void convertDeep​(Config config)
        Performs a deep in-place conversion of a Config. Each simple (ie non-Config) value of the config is converted using the conversion function that corresponds to its type.
        Parameters:
        config - the config to convert
      • chainThen

        public ConversionTable chainThen​(ConversionTable after)
        Returns a ConversionTable that behaves as if the specified table was applied just after this table, for every conversion.
        Parameters:
        after - the table to apply after this one
        Returns:
        a ConversionTable that applies this table and then the specified table
      • wrap

        public UnmodifiableConfig wrap​(UnmodifiableConfig config)
        Returns an UnmodifiableConfig that converts "just-in-time" the values of the specified UnmodifiableConfig.
        Parameters:
        config - the config to wrap
        Returns:
        a wrapper that converts the config's values using this conversion table.
      • wrapRead

        public Config wrapRead​(Config config)
        Returns an Config that converts "just-in-time" the values that are read from the specified Config.
        Parameters:
        config - the config to wrap
        Returns:
        a wrapper that converts the values read from the config
      • wrapRead

        public CommentedConfig wrapRead​(CommentedConfig config)
        Returns an Config that converts "just-in-time" the values that are read from the specified Config.
        Parameters:
        config - the config to wrap
        Returns:
        a wrapper that converts the values read from the config
      • wrapRead

        public FileConfig wrapRead​(FileConfig config)
        Returns an Config that converts "just-in-time" the values that are read from the specified Config.
        Parameters:
        config - the config to wrap
        Returns:
        a wrapper that converts the values read from the config
      • wrapRead

        public CommentedFileConfig wrapRead​(CommentedFileConfig config)
        Returns an Config that converts "just-in-time" the values that are read from the specified Config.
        Parameters:
        config - the config to wrap
        Returns:
        a wrapper that converts the values read from the config
      • wrapWrite

        public Config wrapWrite​(Config config,
                                java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
        Returns an Config that converts "just-in-time" the values that are put into the specified Config.
        Parameters:
        config - the config to wrap
        supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
        Returns:
        a wrapper that converts the values put into the config
      • wrapWrite

        public CommentedConfig wrapWrite​(CommentedConfig config,
                                         java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
        Returns an Config that converts "just-in-time" the values that are put into the specified Config.
        Parameters:
        config - the config to wrap
        supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
        Returns:
        a wrapper that converts the values put into the config
      • wrapWrite

        public FileConfig wrapWrite​(FileConfig config,
                                    java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
        Returns an Config that converts "just-in-time" the values that are put into the specified Config.
        Parameters:
        config - the config to wrap
        supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
        Returns:
        a wrapper that converts the values put into the config
      • wrapWrite

        public CommentedFileConfig wrapWrite​(CommentedFileConfig config,
                                             java.util.function.Predicate<java.lang.Class<?>> supportValueTypePredicate)
        Returns an Config that converts "just-in-time" the values that are put into the specified Config.
        Parameters:
        config - the config to wrap
        supportValueTypePredicate - Predicate that checks if a given class is supported by the returned config
        Returns:
        a wrapper that converts the values put into the config
      • clone

        public ConversionTable clone()
        Overrides:
        clone in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object