<commit_before>package jp.co.ixui.tamura.service;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jp.co.ixui.tamura.CalendarDate;
import jp.co.ixui.tamura.controller.reservation.ReservationForm;
import jp.co.ixui.tamura.domain.Reservation;
import jp.co.ixui.tamura.mapper.ReservationMapper;

/**
 * @author tamura
 *
 */
@Service
public class ReservationService {

	@Autowired
	ReservationMapper reservationMapper;

	/**
	 * カレンダーのセル数
	 */
	private static final int CELL_COUNT = 42;

	/**
	 * 日曜日を示す数字
	 */
	private static final int SUNDAY_NUMBER = 7;

	/**
	 * 現在の月のカレンダーを表示するための情報を設定
	 *
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeCurrentMonthCalendar() {
		// 現在の年月を取得
		YearMonth yearMonth = YearMonth.now();
		// 年月を文字列に変換
		DateTimeFormatter formatCurrentYearMonth = DateTimeFormatter.ofPattern("yyyyMM");
		String currentYearMonth = formatCurrentYearMonth.format(yearMonth);
		// 年と月をそれぞれ切り取る
		String year = currentYearMonth.substring(0, 4);
		String month = currentYearMonth.substring(4, 6);
		// 取得した月の1日の曜日をintで取得
		int startDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue();
		// 取得した月の日数を取得
		int currrentMonthLastDay = yearMonth.atEndOfMonth().lengthOfMonth();

		List<CalendarDate> calendarDateList = makeCalendarList(currentYearMonth, year, month, startDayOfWeek,
				currrentMonthLastDay);
		return calendarDateList;
	}

	/**
	 * URLで指定した月のカレンダーを表示するための情報を設定
	 *
	 * @param calendarDate
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeDesignatedMonthCalendar(String designatedMonth) {
		// 文字列から日付に変換
		YearMonth yearMonth = YearMonth.parse(designatedMonth, DateTimeFormatter.ofPattern("yyyyMM"));
		// 取得した月の1日の曜日をintで取得
		int startDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue();
		// 取得した月の日数を取得
		int designatedMonthLastDay = yearMonth.atEndOfMonth().lengthOfMonth();

		String year = String.valueOf(yearMonth.getYear());
		String month = String.valueOf(yearMonth.getMonthValue());
		if (month.length() == 1) {
			month = "0" + month;
		}

		List<CalendarDate> calendarDateList = makeCalendarList(designatedMonth, year, month, startDayOfWeek,
				designatedMonthLastDay);
		return calendarDateList;
	}

	/**
	 * カレンダーを表示するための日付インスタンスを格納
	 *
	 * @param yearMonth
	 * @param year
	 * @param month
	 * @param startDayOfWeek
	 * @param monthLastDay
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeCalendarList(String yearMonth, String year, String month, int startDayOfWeek,
			int monthLastDay) {
		int count = 0;
		List<CalendarDate> calendarDateList = new ArrayList<>();
		// カレンダーの頭の空白部分にnullを格納
		if (SUNDAY_NUMBER != startDayOfWeek) {
			for (int i = 1; i <= startDayOfWeek; i++) {
				calendarDateList.add(null);
				count++;
			}
		}
		for (int i = 1; i <= monthLastDay; i++) {
			CalendarDate calendarDate = new CalendarDate();
			calendarDate.setYear(year);
			calendarDate.setMonth(month);
			calendarDate.setDay(i);
			calendarDate.setDayOfWeek(YearMonth.of(Integer.parseInt(year), Integer.parseInt(month)).atDay(i).getDayOfWeek().getValue());
			String currentDay = String.valueOf(i);
			// iが一桁のとき dd の形にする
			if (10 > i) {
				currentDay = 0 + currentDay;
			}
			List<Reservation> reservationList = this.reservationMapper.selectReservationByCurrentDay(yearMonth + currentDay);
			calendarDate.setReservationList(reservationList);
			calendarDateList.add(calendarDate);
			count++;
		}<commit_msg>fixed #122<commit_after>package jp.co.ixui.tamura.service;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jp.co.ixui.tamura.CalendarDate;
import jp.co.ixui.tamura.controller.reservation.ReservationForm;
import jp.co.ixui.tamura.domain.Reservation;
import jp.co.ixui.tamura.mapper.ReservationMapper;

/**
 * @author tamura
 *
 */
@Service
public class ReservationService {

	@Autowired
	ReservationMapper reservationMapper;

	/**
	 * カレンダーのセル数
	 */
	private static final int CELL_COUNT = 42;

	/**
	 * 日曜日を示す数字
	 */
	private static final int SUNDAY_NUMBER = 7;

	/**
	 * 現在の月のカレンダーを表示するための情報を設定
	 *
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeCurrentMonthCalendar() {
		// 現在の年月を取得
		YearMonth yearMonth = YearMonth.now();
		// 年月を文字列に変換
		DateTimeFormatter formatCurrentYearMonth = DateTimeFormatter.ofPattern("yyyyMM");
		String currentYearMonth = formatCurrentYearMonth.format(yearMonth);
		// 年と月をそれぞれ切り取る
		String year = currentYearMonth.substring(0, 4);
		String month = currentYearMonth.substring(4, 6);
		// 取得した月の1日の曜日をintで取得
		int startDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue();
		// 取得した月の日数を取得
		int currrentMonthLastDay = yearMonth.atEndOfMonth().lengthOfMonth();

		List<CalendarDate> calendarDateList = makeCalendarList(currentYearMonth, year, month, startDayOfWeek,
				currrentMonthLastDay);
		return calendarDateList;
	}

	/**
	 * URLで指定した月のカレンダーを表示するための情報を設定
	 *
	 * @param calendarDate
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeDesignatedMonthCalendar(String designatedMonth) {
		// 文字列から日付に変換
		YearMonth yearMonth = YearMonth.parse(designatedMonth, DateTimeFormatter.ofPattern("yyyyMM"));
		// 取得した月の1日の曜日をintで取得
		int startDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue();
		// 取得した月の日数を取得
		int designatedMonthLastDay = yearMonth.atEndOfMonth().lengthOfMonth();

		String year = String.valueOf(yearMonth.getYear());
		String month = String.valueOf(yearMonth.getMonthValue());
		if (month.length() == 1) {
			month = "0" + month;
		}

		List<CalendarDate> calendarDateList = makeCalendarList(designatedMonth, year, month, startDayOfWeek,
				designatedMonthLastDay);
		return calendarDateList;
	}

	/**
	 * カレンダーを表示するための日付インスタンスを格納
	 *
	 * @param yearMonth
	 * @param year
	 * @param month
	 * @param startDayOfWeek
	 * @param monthLastDay
	 * @return calendarDateList
	 */
	public List<CalendarDate> makeCalendarList(String yearMonth, String year, String month, int startDayOfWeek,
			int monthLastDay) {
		int count = 0;
		List<CalendarDate> calendarDateList = new ArrayList<>();
		// カレンダーの頭の空白部分にnullを格納
		if (SUNDAY_NUMBER != startDayOfWeek) {
			for (int i = 1; i <= startDayOfWeek; i++) {
				calendarDateList.add(null);
				count++;
			}
		}
		// 受け取った月の日付の情報を格納
		for (int i = 1; i <= monthLastDay; i++) {
			CalendarDate calendarDate = new CalendarDate();
			calendarDate.setYear(year);
			calendarDate.setMonth(month);
			calendarDate.setDay(i);
			calendarDate.setDayOfWeek(YearMonth.of(Integer.parseInt(year), Integer.parseInt(month)).atDay(i).getDayOfWeek().getValue());
			String currentDay = String.valueOf(i);
			// iが一桁のとき dd の形にする
			if (10 > i) {
				currentDay = 0 + currentDay;
			}
			List<Reservation> reservationList = this.reservationMapper.selectReservationByCurrentDay(yearMonth + currentDay);
			calendarDate.setReservationList(reservationList);
			calendarDateList.add(calendarDate);
			count++;
		}
{'fraction_non_alphanumeric': 0.11373333333333334, 'fraction_numerical': 0.0054666666666666665, 'mean_word_length': 4.805727554179566, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '6719742', 'n_tokens_mistral': 2911, 'n_tokens_neox': 2635, 'n_words': 440}