<commit_before>package org.bostonandroid.umbrellatoday;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.text.format.DateUtils;

public class Alert {
  private Exception errorCanBeNull;
  private Calendar alertAt;
  private boolean sunday;
  private boolean monday;
  private boolean tuesday;
  private boolean wednesday;
  private boolean thursday;
  private boolean friday; 
  private boolean saturday;
  private String location;
  private boolean autolocate;

  public static Cursor all(Context c) {
    SQLiteDatabase db = UmbrellaTodayApplication.getAlertsDatabase(c).getReadableDatabase();
    Cursor x = db.query("alerts", null, null, null, null, null, null);
    return x;
  }
  
  public static Maybe<SavedAlert> find(Context context, long id) {
    return SavedAlert.find(context, id);
  }
  
  protected Alert(Calendar alertAt, boolean sunday, boolean monday, boolean tuesday, boolean wednesday, boolean thursday, boolean friday, boolean saturday, String location, boolean autolocate) {
    this.alertAt = alertAt;
    this.sunday = sunday;
    this.monday = monday;
    this.tuesday = tuesday;
    this.wednesday = wednesday;
    this.thursday = thursday;
    this.friday = friday;
    this.saturday = saturday;
    this.location = location;
    this.autolocate = autolocate;
  }
  
  public boolean isRepeating() {
    return this.monday || this.tuesday || this.wednesday || this.thursday || this.friday || this.saturday || this.sunday;
  }

  public Calendar alertAt() {
    if (isRepeating())
      if (repeatsFor(this.alertAt))
        if (wasAlertedAfterNow())
          return this.alertAt;
        else
          return alertAtRepeating(this.alertAt);
      else
        return alertAtRepeating(this.alertAt);
    else if (wasAlertedAfterNow())
      return nextDay(this.alertAt);
    else
      return this.alertAt;
  }
  
  private boolean repeatsFor(Calendar c) {
    return repeatDays().contains(DateUtils.getDayOfWeekString(Calendar.DAY_OF_WEEK, DateUtils.LENGTH_LONG));
  }
  
  private boolean wasAlertedAfterNow() {
    Calendar now = new GregorianCalendar();
    return this.alertAt.getTimeInMillis() > now.getTimeInMillis();
  }

  public List<String> repeatDays() {
    String[] dayStrings = {
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",<commit_msg>Revert "Use the DateUtils library instead"<commit_after>package org.bostonandroid.umbrellatoday;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class Alert {
  private Exception errorCanBeNull;
  private Calendar alertAt;
  private boolean sunday;
  private boolean monday;
  private boolean tuesday;
  private boolean wednesday;
  private boolean thursday;
  private boolean friday; 
  private boolean saturday;
  private String location;
  private boolean autolocate;
  
  private static final String[] DAYS_MAP = new String[8];

  static {
    DAYS_MAP[Calendar.SUNDAY] = "Sunday";
    DAYS_MAP[Calendar.MONDAY] = "Monday";
    DAYS_MAP[Calendar.TUESDAY] = "Tuesday";
    DAYS_MAP[Calendar.WEDNESDAY] = "Wednesday";
    DAYS_MAP[Calendar.THURSDAY] = "Thursday";
    DAYS_MAP[Calendar.FRIDAY] = "Friday";
    DAYS_MAP[Calendar.SATURDAY] = "Saturday";
  }

  public static Cursor all(Context c) {
    SQLiteDatabase db = UmbrellaTodayApplication.getAlertsDatabase(c).getReadableDatabase();
    Cursor x = db.query("alerts", null, null, null, null, null, null);
    return x;
  }
  
  public static Maybe<SavedAlert> find(Context context, long id) {
    return SavedAlert.find(context, id);
  }
  
  protected Alert(Calendar alertAt, boolean sunday, boolean monday, boolean tuesday, boolean wednesday, boolean thursday, boolean friday, boolean saturday, String location, boolean autolocate) {
    this.alertAt = alertAt;
    this.sunday = sunday;
    this.monday = monday;
    this.tuesday = tuesday;
    this.wednesday = wednesday;
    this.thursday = thursday;
    this.friday = friday;
    this.saturday = saturday;
    this.location = location;
    this.autolocate = autolocate;
  }
  
  public boolean isRepeating() {
    return this.monday || this.tuesday || this.wednesday || this.thursday || this.friday || this.saturday || this.sunday;
  }

  public Calendar alertAt() {
    if (isRepeating())
      if (repeatsFor(this.alertAt))
        if (wasAlertedAfterNow())
          return this.alertAt;
        else
          return alertAtRepeating(this.alertAt);
      else
        return alertAtRepeating(this.alertAt);
    else if (wasAlertedAfterNow())
      return nextDay(this.alertAt);
    else
      return this.alertAt;
  }
  
  private boolean repeatsFor(Calendar c) {
    return repeatDays().contains(DAYS_MAP[c.get(Calendar.DAY_OF_WEEK)]);
  }
  
  private boolean wasAlertedAfterNow() {
    Calendar now = new GregorianCalendar();
    return this.alertAt.getTimeInMillis() > now.getTimeInMillis();
  }

  public List<String> repeatDays() {
    String[] dayStrings = {
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
{'fraction_non_alphanumeric': 0.09917503586800575, 'fraction_numerical': 0.0001793400286944046, 'mean_word_length': 3.734295415959253, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2758895', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1693, 'n_words': 407}