SHARE
TWEET

Untitled

a guest Feb 17th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.toedter.calendar.IDateEvaluator;
  2. import java.awt.Color;
  3. import java.time.DayOfWeek;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.List;
  7.  
  8. public class DayOfWeekEvaluator implements IDateEvaluator {
  9.  
  10.     private final List<DayOfWeek> validDaysOfWeek;
  11.  
  12.     public DayOfWeekEvaluator(List<DayOfWeek> validDaysOfWeek) {
  13.         this.validDaysOfWeek = validDaysOfWeek;
  14.     }
  15.  
  16.     private DayOfWeek determineDayOfWeek(Date date) {
  17.         Calendar c = Calendar.getInstance();
  18.         c.setTime(date);
  19.         int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
  20.         return DayOfWeek.of(convertSundayFirstToMondayFirst(dayOfWeek));
  21.     }
  22.  
  23.     private int convertSundayFirstToMondayFirst(int sundayFirstValue) {
  24.         // Converts from weeks that are Sunday-Saturday (1-7)
  25.         // to weeks that are Monday-Sunday (1-7)
  26.         if (sundayFirstValue == 1) {
  27.             return 7;
  28.         }
  29.         return sundayFirstValue - 1;
  30.     }
  31.  
  32.     @Override
  33.     public boolean isSpecial(Date date) {
  34.         return false;
  35.     }
  36.  
  37.     @Override
  38.     public Color getSpecialForegroundColor() {
  39.         return null;
  40.     }
  41.  
  42.     @Override
  43.     public Color getSpecialBackroundColor() {
  44.         return null;
  45.     }
  46.  
  47.     @Override
  48.     public String getSpecialTooltip() {
  49.         return null;
  50.     }
  51.  
  52.     @Override
  53.     public boolean isInvalid(Date date) {
  54.         DayOfWeek dayOfWeek = determineDayOfWeek(date);
  55.         return !validDaysOfWeek.contains(dayOfWeek);
  56.     }
  57.  
  58.     @Override
  59.     public Color getInvalidForegroundColor() {
  60.         return null;
  61.     }
  62.  
  63.     @Override
  64.     public Color getInvalidBackroundColor() {
  65.         return null;
  66.     }
  67.  
  68.     @Override
  69.     public String getInvalidTooltip() {
  70.         return null;
  71.     }
  72.  
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top