Interface PreferenceStore


  • public interface PreferenceStore
    Store API for preferences. All preference management should be made through this service.
    • Method Detail

      • getDefaultScopeResolutionStrategyInfo

        PreferenceScopeResolutionStrategyInfo getDefaultScopeResolutionStrategyInfo()
        Provides a portable instance that has the scope resolution strategy order and the default scope for preference persistence.
        Returns:
        A portable scope information instance.
      • getDefaultScopeResolver

        PreferenceScopeResolver getDefaultScopeResolver()
        Provides a portable instance that resolves scopes in the default scope resolution strategy order.
        Returns:
        A portable scope resolver instance.
      • put

        <T> void put​(PreferenceScope scope,
                     String key,
                     T value)
        Stores a preference inside a specific scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scope - Scope in which the preference will be stored. Must not be null.
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • put

        <T> void put​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                     String key,
                     T value)
        Stores a preference inside the default scope (see defaultScope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the default scope, in which the preference will be stored. Must not be null.
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • put

        <T> void put​(String key,
                     T value)
        Stores a preference inside the default scope (see defaultScope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • put

        <T> void put​(PreferenceScope scope,
                     Map<String,​T> valueByKey)
        Stores several preferences inside a specific scope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        scope - Scope in which the preference will be stored. Must not be null.
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • put

        <T> void put​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                     Map<String,​T> valueByKey)
        Stores several preferences inside the default scope (see defaultScope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the default scope. Must not be null.
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • put

        <T> void put​(Map<String,​T> valueByKey)
        Stores several preferences inside the default scope (see defaultScope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • putIfAbsent

        <T> void putIfAbsent​(PreferenceScope scope,
                             String key,
                             T value)
        Stores a preference inside a specific scope, if it is not already defined in that scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scope - Scope in which the preference will be stored. Must not be null.
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • putIfAbsent

        <T> void putIfAbsent​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                             String key,
                             T value)
        Stores a preference inside the default scope (see defaultScope, if it is not already defined in that scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the default scope. in which the preference will be stored. Must not be null.
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • putIfAbsent

        <T> void putIfAbsent​(String key,
                             T value)
        Stores a preference inside the default scope (see defaultScope, if it is not already defined in that scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - The key of the preference, must not be null.
        value - The value of the preference, could be null.
      • putIfAbsent

        <T> void putIfAbsent​(PreferenceScope scope,
                             Map<String,​T> valueByKey)
        Stores several preferences inside a specific scope, if they are not already defined in that scope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        scope - Scope in which the preference will be stored. Must not be null.
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • putIfAbsent

        <T> void putIfAbsent​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                             Map<String,​T> valueByKey)
        Stores several preferences inside the default scope (see defaultScope, if they are not already defined in that scope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the default scope. Must not be null.
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • putIfAbsent

        <T> void putIfAbsent​(Map<String,​T> valueByKey)
        Stores several preferences inside the default scope (see defaultScope.
        Type Parameters:
        T - Type of the preference values.
        Parameters:
        valueByKey - Map that contains a preference value (can be null) for each preference key (must not be null).
      • get

        <T> T get​(PreferenceScope scope,
                  String key)
        Retrieves a preference value from a specific scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scope - Scope in which the preference value will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        Returns:
        The preference value (or null, if it does not exist).
      • get

        <T> T get​(PreferenceScope scope,
                  String key,
                  T defaultValue)
        Retrieves a preference value from a specific scope.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scope - Scope in which the preference value will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        defaultValue - Value to be returned if the preference is not defined in that scope.
        Returns:
        The preference value (or defaultValue, if it does not exist).
      • get

        <T> T get​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                  String key)
        Retrieves a preference value from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        Returns:
        The preference value (or null, if it does not exist).
      • get

        <T> T get​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                  String key,
                  T defaultValue)
        Retrieves a preference value from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        defaultValue - Value to be returned if the preference is not defined in any scope.
        Returns:
        The preference value (or null, if it does not exist).
      • get

        <T> T get​(String key)
        Retrieves a preference value from the first scope of the default scope resolution strategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - Preference key to be searched, must not be null.
        Returns:
        The preference value (or null, if it does not exist).
      • get

        <T> T get​(String key,
                  T defaultValue)
        Retrieves a preference value from the first scope of the default scope resolution strategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - Preference key to be searched, must not be null.
        defaultValue - Value to be returned if the preference is not defined in any scope.
        Returns:
        The preference value (or null, if it does not exist).
      • getScoped

        <T> PreferenceScopedValue<T> getScoped​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                               String key)
        Retrieves a scoped preference value from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        Returns:
        A preference scoped value, which contains the preference value and its scope (or null, if the preference does not exist).
      • getScoped

        <T> PreferenceScopedValue<T> getScoped​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                               String key,
                                               T defaultValue)
        Retrieves a scoped preference value from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        key - Preference key to be searched, must not be null.
        defaultValue - Value to be returned if the preference is not defined in any scope.
        Returns:
        A preference scoped value, which contains the preference value and its scope (or defaultValue, if the preference does not exist in any scope).
      • getScoped

        <T> PreferenceScopedValue<T> getScoped​(String key)
        Retrieves a preference value from the first scope of the default scope resolution strategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - Preference key to be searched, must not be null.
        Returns:
        A preference scoped value, which contains the preference value and its scope (or null, if the preference does not exist).
      • getScoped

        <T> PreferenceScopedValue<T> getScoped​(String key,
                                               T defaultValue)
        Retrieves a preference value from the first scope of the default scope resolution strategy order that has the preference defined.
        Type Parameters:
        T - Type of the preference value.
        Parameters:
        key - Preference key to be searched, must not be null.
        defaultValue - Value to be returned if the preference is not defined in any scope.
        Returns:
        A preference scoped value, which contains the preference value and its scope (or defaultValue, if the preference does not exist in any scope).
      • search

        Map<String,​Object> search​(PreferenceScope scope,
                                        Collection<String> keys)
        Retrieves several preferences, which keys were passed, from a specific scope.
        Parameters:
        scope - Scope in which the preferences values will be searched. Must not be null.
        keys - Preference keys to search. If null, all keys in that scope will be searched.
        Returns:
        A Map containing all passed preference keys and its values (or null, if a preference does not exist).
      • search

        Map<String,​Object> search​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                        Collection<String> keys)
        Retrieves several preferences, which keys were passed. Each one from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        keys - Preference keys to search. If null, all keys in that scope resolution strategy will be searched.
        Returns:
        A Map containing all passed preference keys and its values (or null, if a preference does not exist).
      • search

        Map<String,​Object> search​(Collection<String> keys)
        Retrieves several preferences, which keys were passed. Each one from the first scope of the default scope resolution strategy order that has the preference defined.
        Parameters:
        keys - Preference keys to search. If null, all keys in the default scope resolution strategy type will be searched.
        Returns:
        A Map containing all passed preference keys and its values (or null, if a preference does not exist).
      • searchScoped

        Map<String,​PreferenceScopedValue<Object>> searchScoped​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                                                     Collection<String> keys)
        Retrieves several scoped preferences, which keys were passed. Each one from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        keys - Preference keys to search. If null, all keys in that scope resolution strategy will be searched.
        Returns:
        A Map containing all passed preference keys and its preference scoped value, which contains the preference value and its scope (or null, if the preference does not exist in any scope).
      • searchScoped

        Map<String,​PreferenceScopedValue<Object>> searchScoped​(Collection<String> keys)
        Retrieves several scoped preferences, which keys were passed. Each one from the first scope of the default scope resolution strategy order that has the preference defined.
        Parameters:
        keys - Preference keys to search. If null, all keys in the default scope resolution strategy will be searched.
        Returns:
        A Map containing all passed preference keys and its preference scoped value, which contains the preference value and its scope (or null, if the preference does not exist in any scope).
      • all

        Map<String,​Object> all​(PreferenceScope scope)
        Retrieves all defined preferences from a specific scope.
        Parameters:
        scope - Scope in which the preferences values will be searched. Must not be null.
        Returns:
        A Map containing all preference keys and its values.
      • all

        Map<String,​Object> all​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo)
        Retrieves all defined preferences. Each one from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        Returns:
        A Map containing all preference keys and its values.
      • all

        Map<String,​Object> all()
        Retrieves all defined preferences. Each one from the first scope of the default scope resolution strategy order that has the preference defined.
        Returns:
        A Map containing all preference keys and its values.
      • allScoped

        Map<String,​PreferenceScopedValue<Object>> allScoped​(PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo)
        Retrieves all defined preferences. Each one from the first scope of the scopeResolutionStrategy order that has the preference defined.
        Parameters:
        scopeResolutionStrategyInfo - Scope resolution strategy that defines the order on which the scopes will be searched. Must not be null.
        Returns:
        A Map containing all preferences keys and its preference scoped value, which contains the preference value and its scope.
      • allScoped

        Map<String,​PreferenceScopedValue<Object>> allScoped()
        Retrieves all defined preferences. Each one from the first scope of the default scope resolution strategy order that has the preference defined.
        Returns:
        A Map containing all preferences keys and its preference scoped value, which contains the preference value and its scope.
      • remove

        void remove​(PreferenceScope scope,
                    String key)
        Removes a preference from a specific scope.
        Parameters:
        scope - Scope in which the preference will be removed. Must not be null.
        key - Key of the preference that should be removed. Must not be null.
      • remove

        void remove​(List<PreferenceScope> scopes,
                    String key)
        Removes a preference from a list of scopes.
        Parameters:
        scopes - Scopes from which the preference will be removed. Must not be null.
        key - Key of the preference that will be removed. Must not be null.