Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StateHelper#computeIfAbsent #2024

Open
tandraschko opened this issue Mar 5, 2025 · 1 comment
Open

Add StateHelper#computeIfAbsent #2024

tandraschko opened this issue Mar 5, 2025 · 1 comment
Labels
myfaces-implemented API issue implemented by MyFaces
Milestone

Comments

@tandraschko
Copy link

Similar to: eclipse-ee4j/mojarra#4568

we already have a eval() with a lambda to provide the default value. However, this defaultValueSupplier does NOT store it as default in the state/stateHelper.

computeIfAbsent however will store the defaultValue in the state.

See PF code:

    /**
     * Tries to retrieve value from stateHelper by key first. If the value is not present (or is null),
     * then it is retrieved from defaultValueSupplier.
     *
     * Should be removed when {@link StateHelper} is extended with similar functionality.
     * (see https://github.com/eclipse-ee4j/mojarra/issues/4568 for details)
     * @param stateHelper The stateHelper to try to retrieve value from
     * @param key The key under which value is stored in the stateHelper
     * @param defaultValueSupplier The object, from which default value is retrieved
     * @param <T> the expected type of returned value
     * @return value from stateHelper or defaultValueSupplier
     */
    public static <T> T computeIfAbsent(StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier) {
        T value = (T) stateHelper.get(key);
        if (value == null) {
            value = defaultValueSupplier.get();
            stateHelper.put(key, value);
        }
        return value;
    }
@tandraschko tandraschko added this to the 5.0 milestone Mar 5, 2025
@tandraschko
Copy link
Author

apache/myfaces@65dcf36

@tandraschko tandraschko added the myfaces-implemented API issue implemented by MyFaces label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
myfaces-implemented API issue implemented by MyFaces
Projects
None yet
Development

No branches or pull requests

1 participant