月曜始まりのカレンダー日付配列リスト

月曜始まりのカレンダー日付配列リストを求めるものを作った。
使う機会は稀にあるようだ。。。

/**
 * 指定日の月のカレンダー配列List を作成する(月曜始まり)
 * @param date カレンダーを求めたい日付
 * @param blank 該当しない曜日の表示文字、null を渡すと前月、翌月の日付けが格納される
 * @return  List<String> String length = 7
 */

public static List<String> calendarListStartMonday(Date date,String blank){
   Calendar c = Calendar.getInstance();
   c.setTime(date);
   c.set(c.get(Calendar.YEAR),c.get(Calendar.MONTH),1);
   int firstWeek = c.get(Calendar.DAY_OF_WEEK);
   c.add(Calendar.MONTH, 1);
   c.set(c.get(Calendar.YEAR),c.get(Calendar.MONTH),1);
   c.add(Calendar.DAY_OF_MONTH, - c.get(Calendar.DAY_OF_MONTH));
   int endday = c.get(Calendar.DAY_OF_MONTH);
   int last = 31;
   if (blank==null){
      c.set(Calendar.DAY_OF_MONTH,1);
      c.add(Calendar.DAY_OF_MONTH,-1);
      last = c.get(Calendar.DAY_OF_MONTH);
   }

   List<String
> list = new ArrayList<String>();
   int day = 1;
   int week = 0;
   String
 s = new String[7];
   if (firstWeek==1){
      if (blank==null){
         int x = last;
         for(int i=5;i >= 0;i--,x--){
            s[i] = Integer.toString(x);
         }
      }else{
         for(int i=0;i < 6;i++){
            s[i] = blank;
         }
      }
      s[6] = "1";
      week = 7;
      day=2;
   }else{
      int o = firstWeek-2;
      if (blank==null){
         int x = last;
         for(int i=o-1;i >= 0;i--,x--){
            s[i] = Integer.toString(x);
            week++;
         }
      }else{
         for(;week < o;week++){
            s[week] = blank;
         }
      }
   }

   for(int d=day;d <= endday;d++){
      if (week==7){
         list.add(s);
         s = new String[7];
         week = 0;
      }
      s[week] = Integer.toString(d);
      week++;
   }
   if (blank==null){
      int x = 1;
      for(;week < 7;week++,x++){
         s[week] = Integer.toString(x);
      }
   }else{
      for(;week < 7;week++){
         s[week] = blank;
      }
   }

   list.add(s);
   return list;
}