class CredentialFlowStateHelper {

    static Set<CredentialFlowState> restoreFrom(final Restorer restore,
        final HttpServletRequest request) {
        final Cookie[] servletCookies = request.getCookies();

        if (ArrayUtils.isEmpty(servletCookies)) {
            return Collections.emptySet();
        }

        final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies)
            .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX))
            .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList());

        try {
            return restore.apply(credentialCookies, CredentialFlowState.class);
        } catch (final IllegalArgumentException e) {
            return Collections.emptySet();
        }
    }

    private  CredentialFlowStateHelper();

}