<commit_before>/*
 * Copyright (c) 2016. <NAME>
 */

package com.stulsoft.pjava.basics.optional;

import java.util.Optional;

/**
 * Playing with Optional
 *
 * @author <NAME>
 */
class POptional {
    private static final boolean TO_SUCCESS = false;
    private static final boolean TO_FAIL = true;
    private static Optional<String> f1(final boolean toFail) {
        System.out.println("==>f1");
        System.out.println("<==f1");
        if (toFail) {
            return Optional.empty();
        } else {
            return Optional.of("A result");
        }
    }

    private static void showResult(Optional<String> result, boolean toFail) {
        System.out.printf("toFail is %s, result is %s\n", toFail, result);
        result.ifPresent(s -> System.out.printf("Result value is \"%s\"\n", s));
    }

    public static void main(String[] args) {
        System.out.println("==>main");
        Optional<String> result;

        result = POptional.f1(TO_SUCCESS);
        showResult(result, TO_SUCCESS);

        result = POptional.f1(TO_FAIL);
        showResult(result, TO_FAIL);

        System.out.println("<==main");
    }
}
<commit_msg>filter<commit_after>/*
 * Copyright (c) 2016. <NAME>
 */

package com.stulsoft.pjava.basics.optional;

import java.util.Optional;

/**
 * Playing with Optional
 *
 * @author <NAME>
 */
class POptional {
    private static final boolean TO_SUCCESS = false;
    private static final boolean TO_FAIL = true;
    private static Optional<String> f1(final boolean toFail) {
        System.out.println("==>f1");
        System.out.println("<==f1");
        if (toFail) {
            return Optional.empty();
        } else {
            return Optional.of("A result");
        }
    }

    private static void showResult(Optional<String> result, boolean toFail) {
        System.out.printf("toFail is %s, result is %s\n", toFail, result);
        result.ifPresent(s -> System.out.printf("Result value is \"%s\"\n", s));
    }

    public static void main(String[] args) {
        System.out.println("==>main");
        Optional<String> result;

        result = POptional.f1(TO_SUCCESS);
        showResult(result, TO_SUCCESS);

        result = POptional.f1(TO_FAIL);
        showResult(result, TO_FAIL);

        // Using filter
        result = POptional.f1(TO_SUCCESS);
        String textResult= result.filter(s -> s.contains("result")).isPresent()? "Success": "Filure";
        System.out.printf("filter: textResult is %s\n", textResult);

        System.out.println("<==main");
    }
}

{'fraction_non_alphanumeric': 0.14606299212598425, 'fraction_numerical': 0.007480314960629921, 'mean_word_length': 2.609375, 'pattern_counts': {'":': 1, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '376524', 'n_tokens_mistral': 788, 'n_tokens_neox': 766, 'n_words': 179}