Java days of week calculation

Posted by Shahid on Stack Overflow See other posts from Stack Overflow or by Shahid
Published on 2010-03-17T11:34:14Z Indexed on 2010/03/17 11:41 UTC
Read the original article Hit count: 243

Filed under:
|
|

I have an Enum for Days of week (with Everyday, weekend and weekdays) as follows where each entry has an int value.

public enum DaysOfWeek {


  Everyday(127),
  Weekend(65),
  Weekdays(62), 
  Monday(2),
  Tuesday(4),
  Wednesday(8),
  Thursday(16),
  Friday(32), 
  Saturday(64),
  Sunday(1);

  private int bitValue;

  private DaysOfWeek(int n){
    this.bitValue = n;
  }

  public int getBitValue(){
    return this.bitValue;
  }
}

Given a TOTAL of any combination of the entries, what would be the simplest way to calculate all individual values and make an arraylist from it. For example given the number 56 (i.e. Wed+Thur+Fri), how to calculate the list of individual values.

© Stack Overflow or respective owner

Related posts about java

Related posts about enum