Interface PreferenceStorage


  • public interface PreferenceStorage
    Storage API for preferences.
    • Method Detail

      • exists

        boolean exists​(PreferenceScope preferenceScope,
                       String key)
        Checks if a given preference key is defined in a certain scope.
        Parameters:
        preferenceScope - Scope in which the key will be checked.
        key - Key to be checked (must not be null).
        Returns:
        true if the key is defined in that scope, and false otherwise.
      • exists

        boolean exists​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                       String key)
        Checks if a given preference key is defined in any scope of the provided hierarchy.
        Parameters:
        scopeResolutionStrategyInfo - Hierarchy of scopes in which the key will be checked.
        key - Key to be checked (must not be null).
        Returns:
        true if the key is defined in any scope, and false otherwise.
      • read

        <T> T read​(PreferenceScope preferenceScope,
                   String key)
        Tries to read a preference value from a specific scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        preferenceScope - Scope in which the key will be searched.
        key - Preference key to be read (must not be null).
        Returns:
        The preference value (null if it is not defined).
      • read

        <T> T read​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                   String key)
        Tries to read a preference value from a scope hierarchy.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope hierarchy in which the key will be searched.
        key - Preference key to be read (must not be null).
        Returns:
        The preference value (null if it is not defined in any scope in the hierarchy).
      • readWithScope

        <T> PreferenceScopedValue<T> readWithScope​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                                   String key)
        Tries to read a preference value from a scope hierarchy.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope hierarchy in which the key will be searched.
        key - Preference key to be read (must not be null).
        Returns:
        The preference value and its scope (null if it is not defined in any scope in the hierarchy).
      • write

        void write​(PreferenceScope scope,
                   String key,
                   Object value)
        (Over) Writes a preference value related to a preference key, for a specific scope.
        Parameters:
        scope - Scope in which the preference will be written.
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • delete

        void delete​(PreferenceScope scope,
                    String key)
        Deletes a preference, in a specific scope, if it exists.
        Parameters:
        scope - Scope in which the preference is stored.
        key - The key of the preference to be deleted, must not be null.
      • allKeys

        Collection<String> allKeys​(PreferenceScope scope)
        Returns all preference keys defined in a specific scope.
        Parameters:
        scope - Scope in which the preference keys will be searched.
        Returns:
        All preference keys defined in the passed scope.
      • allKeys

        Collection<String> allKeys​(List<PreferenceScope> scopes)
        Returns all preference keys defined in all passed scopes.
        Parameters:
        scopes - Scopes in which the preference keys will be searched.
        Returns:
        All preference keys defined in all passed scopes.