<commit_before>package org.ligi.snackengage.snacks;

import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.view.View;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.ligi.snackengage.SnackContext;
import org.ligi.snackengage.conditions.SnackCondition;

public abstract class BaseSnack implements Snack {

    protected SnackContext snackContext;
    protected List<SnackCondition> conditionList = new ArrayList<>();

    @Override
    public boolean opportunity(final SnackContext snackContext) {
        this.snackContext = snackContext;

        for (final SnackCondition snackCondition : conditionList) {
            if (!snackCondition.isAppropriate(snackContext,this)) {
                return false;
            }
        }

        Snackbar.make(snackContext.getRootView(), getText(), Snackbar.LENGTH_LONG).setAction(getActionText(), new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                snackContext.getStats().registerSnackClick(BaseSnack.this);
                engage();
            }
        }).show();
        return true;
    }

    public abstract void engage();

    @StringRes
    public abstract int getText();

    @StringRes
    public abstract int getActionText();

    public Snack withConditions(SnackCondition... conditions) {
        Collections.addAll(conditionList, conditions);
        return this;<commit_msg>Add option to add duration<commit_after>package org.ligi.snackengage.snacks;

import android.support.annotation.IntDef;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.view.View;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.ligi.snackengage.SnackContext;
import org.ligi.snackengage.conditions.SnackCondition;

public abstract class BaseSnack implements Snack {

    public static final int DURATION_INDEFINITE = -2;
    public static final int DURATION_SHORT = -1;
    public static final int DURATION_LONG = 0;

    @IntDef({DURATION_INDEFINITE, DURATION_SHORT, DURATION_LONG})
    @Retention(RetentionPolicy.SOURCE)
    public @interface SnackDuration {
    }

    @SnackDuration
    private int duration = DURATION_LONG;

    protected SnackContext snackContext;
    protected List<SnackCondition> conditionList = new ArrayList<>();

    @Override
    public boolean opportunity(final SnackContext snackContext) {
        this.snackContext = snackContext;

        for (final SnackCondition snackCondition : conditionList) {
            if (!snackCondition.isAppropriate(snackContext, this)) {
                return false;
            }
        }

        Snackbar.make(snackContext.getRootView(), getText(), duration).setAction(getActionText(), new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                snackContext.getStats().registerSnackClick(BaseSnack.this);
                engage();
            }
        }).show();
        return true;
    }

    public abstract void engage();

    @StringRes
    public abstract int getText();

    @StringRes
    public abstract int getActionText();

    public Snack withDuration(@SnackDuration int duration) {
        this.duration = duration;
        return this;
    }

    public Snack withConditions(SnackCondition... conditions) {
        Collections.addAll(conditionList, conditions);
        return this;
{'fraction_non_alphanumeric': 0.08795782463928968, 'fraction_numerical': 0.000832408435072142, 'mean_word_length': 3.153225806451613, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6818010', 'n_tokens_mistral': 993, 'n_tokens_neox': 952, 'n_words': 223}