<commit_before>package com.marverenic.music.instances.playlistrules;

import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.marverenic.music.data.store.MusicStore;
import com.marverenic.music.data.store.PlayCountStore;
import com.marverenic.music.data.store.PlaylistStore;
import com.marverenic.music.instances.Song;

import java.io.IOException;
import java.util.List;

import rx.Observable;

public abstract class AutoPlaylistRule implements Parcelable {

    public static final int PLAYLIST = 0;
    public static final int SONG = 1;
    public static final int ARTIST = 2;
    public static final int ALBUM = 3;
    public static final int GENRE = 4;

    public static final int ID = 5;
    public static final int NAME = 6;
    public static final int PLAY_COUNT = 7;
    public static final int SKIP_COUNT = 8;
    public static final int YEAR = 9;
    public static final int DATE_ADDED = 10;
    public static final int DATE_PLAYED = 11;

    public static final int EQUALS = 12;
    public static final int NOT_EQUALS = 13;
    public static final int CONTAINS = 14;
    public static final int NOT_CONTAINS = 15;
    public static final int LESS_THAN = 16;
    public static final int GREATER_THAN = 17;

    @IntDef(value = {PLAYLIST, SONG, ARTIST, ALBUM, GENRE})
    public @interface Type {
    }

    @IntDef(value = {ID, NAME, PLAY_COUNT, SKIP_COUNT, YEAR, DATE_ADDED, DATE_PLAYED})
    public @interface Field {
    }

    @IntDef(value = {EQUALS, NOT_EQUALS, CONTAINS, NOT_CONTAINS, LESS_THAN, GREATER_THAN})
    public @interface Match {
    }

    @Type
    @SerializedName("type")
    private final int mType;

    @Field
    @SerializedName("field")
    private final int mField;

    @Match
    @SerializedName("match")
    private final int mMatch;

    @SerializedName("value")
    private final String mValue;

    protected AutoPlaylistRule(@Type int type, @Field int field, @Match int match, String value) {
        mType = type;
        mField = field;
        mMatch = match;
        mValue = value;
    }

    @SuppressWarnings("WrongConstant")
    protected AutoPlaylistRule(Parcel in) {
        mType = in.readInt();
        mField = in.readInt();
        mMatch = in.readInt();
        mValue = in.readString();
    }

    @Type
    public int getType() {
        return mType;
    }

    @Field
    public int getField() {
        return mField;
    }

    @Match
    public int getMatch() {
        return mMatch;
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkId(long actual) {
        switch (getMatch()) {
            case EQUALS:
                return actual == Long.parseLong(getValue());
            case NOT_EQUALS:
                return actual != Long.parseLong(getValue());
        }
        throw new IllegalArgumentException("Cannot compare ids with match type " + getMatch());
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkString(String actual) {
        switch (getMatch()) {
            case EQUALS:
                return actual.equalsIgnoreCase(getValue());
            case NOT_EQUALS:
                return !actual.equalsIgnoreCase(getValue());
            case CONTAINS:
                return actual.contains(getValue());
            case NOT_CONTAINS:
                return !actual.contains(getValue());
        }
        throw new IllegalArgumentException("Cannot compare Strings with match type " + getMatch());
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkInt(long actual) {
        switch (getMatch()) {
            case EQUALS:<commit_msg>Make "contains" rules case insensitive<commit_after>package com.marverenic.music.instances.playlistrules;

import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.marverenic.music.data.store.MusicStore;
import com.marverenic.music.data.store.PlayCountStore;
import com.marverenic.music.data.store.PlaylistStore;
import com.marverenic.music.instances.Song;

import java.io.IOException;
import java.util.List;

import rx.Observable;

public abstract class AutoPlaylistRule implements Parcelable {

    public static final int PLAYLIST = 0;
    public static final int SONG = 1;
    public static final int ARTIST = 2;
    public static final int ALBUM = 3;
    public static final int GENRE = 4;

    public static final int ID = 5;
    public static final int NAME = 6;
    public static final int PLAY_COUNT = 7;
    public static final int SKIP_COUNT = 8;
    public static final int YEAR = 9;
    public static final int DATE_ADDED = 10;
    public static final int DATE_PLAYED = 11;

    public static final int EQUALS = 12;
    public static final int NOT_EQUALS = 13;
    public static final int CONTAINS = 14;
    public static final int NOT_CONTAINS = 15;
    public static final int LESS_THAN = 16;
    public static final int GREATER_THAN = 17;

    @IntDef(value = {PLAYLIST, SONG, ARTIST, ALBUM, GENRE})
    public @interface Type {
    }

    @IntDef(value = {ID, NAME, PLAY_COUNT, SKIP_COUNT, YEAR, DATE_ADDED, DATE_PLAYED})
    public @interface Field {
    }

    @IntDef(value = {EQUALS, NOT_EQUALS, CONTAINS, NOT_CONTAINS, LESS_THAN, GREATER_THAN})
    public @interface Match {
    }

    @Type
    @SerializedName("type")
    private final int mType;

    @Field
    @SerializedName("field")
    private final int mField;

    @Match
    @SerializedName("match")
    private final int mMatch;

    @SerializedName("value")
    private final String mValue;

    protected AutoPlaylistRule(@Type int type, @Field int field, @Match int match, String value) {
        mType = type;
        mField = field;
        mMatch = match;
        mValue = value;
    }

    @SuppressWarnings("WrongConstant")
    protected AutoPlaylistRule(Parcel in) {
        mType = in.readInt();
        mField = in.readInt();
        mMatch = in.readInt();
        mValue = in.readString();
    }

    @Type
    public int getType() {
        return mType;
    }

    @Field
    public int getField() {
        return mField;
    }

    @Match
    public int getMatch() {
        return mMatch;
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkId(long actual) {
        switch (getMatch()) {
            case EQUALS:
                return actual == Long.parseLong(getValue());
            case NOT_EQUALS:
                return actual != Long.parseLong(getValue());
        }
        throw new IllegalArgumentException("Cannot compare ids with match type " + getMatch());
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkString(String actual) {
        switch (getMatch()) {
            case EQUALS:
                return actual.equalsIgnoreCase(getValue());
            case NOT_EQUALS:
                return !actual.equalsIgnoreCase(getValue());
            case CONTAINS:
                return actual.toLowerCase().contains(getValue().toLowerCase());
            case NOT_CONTAINS:
                return !actual.toLowerCase().contains(getValue().toLowerCase());
        }
        throw new IllegalArgumentException("Cannot compare Strings with match type " + getMatch());
    }

    @SuppressLint("SwitchIntDef")
    protected boolean checkInt(long actual) {
        switch (getMatch()) {
            case EQUALS:
{'fraction_non_alphanumeric': 0.09204589403119763, 'fraction_numerical': 0.006703622534484982, 'mean_word_length': 2.7641921397379914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2147798', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2250, 'n_words': 635}