title: Android Java: Convert else-if to switch
body: <p>I use else-if statement to check Boolean values and since using the else-if, it causes poor performance. </p>
  
  <blockquote>
    <p>From that reason, I am considering to convert the else-if statement into switch statement, so that I'd like to hear your advice to converting it appropriately. </p>
  </blockquote>
  
  <p><strong>This is my else-if statement</strong></p>
  
  <pre><code>public class Config_Monday_0 {
  private Context mContext;
  
  public Config_Monday_0(Context context){
      this.mContext = context;
  }
  
  public int monday_0(TextView mon_1, TextView mon_2, TextView mon_3, TextView mon_4, TextView mon_5,
                       TextView mon_6, TextView mon_7, TextView mon_8, TextView mon_9, TextView mon_10,
                       TextView mon_11, TextView mon_12, TextView mon_13, TextView mon_14, TextView mon_15,
                       TextView mon_16, TextView mon_17, TextView mon_18, TextView mon_19, TextView mon_20,
                       TextView mon_21, TextView mon_22, TextView mon_23, TextView mon_24){
  
      Schedule_Boolean_Monday_0 schedule_boolean_monday0 = new Schedule_Boolean_Monday_0(mContext);
      DatabaseTimetable databaseTimetable = new DatabaseTimetable(mContext);
  
      int start_time;
      int end_time;
  
      //Database 0 AM is not used
      if (!schedule_boolean_monday0.Monday_0_1() &amp;&amp; !schedule_boolean_monday0.Monday_0_2() &amp;&amp; !schedule_boolean_monday0.Monday_0_3() &amp;&amp; !schedule_boolean_monday0.Monday_0_4() &amp;&amp; !schedule_boolean_monday0.Monday_0_5() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_6() &amp;&amp; !schedule_boolean_monday0.Monday_0_7()&amp;&amp; !schedule_boolean_monday0.Monday_0_8() &amp;&amp; !schedule_boolean_monday0.Monday_0_9() &amp;&amp; !schedule_boolean_monday0.Monday_0_10() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_11() &amp;&amp; !schedule_boolean_monday0.Monday_0_12() &amp;&amp; !schedule_boolean_monday0.Monday_0_13() &amp;&amp; !schedule_boolean_monday0.Monday_0_14() &amp;&amp; !schedule_boolean_monday0.Monday_0_15() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_16() &amp;&amp; !schedule_boolean_monday0.Monday_0_17()&amp;&amp; !schedule_boolean_monday0.Monday_0_18() &amp;&amp; !schedule_boolean_monday0.Monday_0_19() &amp;&amp; !schedule_boolean_monday0.Monday_0_20() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_21() &amp;&amp; !schedule_boolean_monday0.Monday_0_22() &amp;&amp; !schedule_boolean_monday0.Monday_0_23() &amp;&amp; !schedule_boolean_monday0.Monday_0_24()){
          return 0;
      }
      //0 am - 1 hr.
      else if (schedule_boolean_monday0.Monday_0_1() &amp;&amp; !schedule_boolean_monday0.Monday_0_2() &amp;&amp; !schedule_boolean_monday0.Monday_0_3() &amp;&amp; !schedule_boolean_monday0.Monday_0_4() &amp;&amp; !schedule_boolean_monday0.Monday_0_5() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_6() &amp;&amp; !schedule_boolean_monday0.Monday_0_7()&amp;&amp; !schedule_boolean_monday0.Monday_0_8() &amp;&amp; !schedule_boolean_monday0.Monday_0_9() &amp;&amp; !schedule_boolean_monday0.Monday_0_10() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_11() &amp;&amp; !schedule_boolean_monday0.Monday_0_12() &amp;&amp; !schedule_boolean_monday0.Monday_0_13() &amp;&amp; !schedule_boolean_monday0.Monday_0_14() &amp;&amp; !schedule_boolean_monday0.Monday_0_15() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_16() &amp;&amp; !schedule_boolean_monday0.Monday_0_17()&amp;&amp; !schedule_boolean_monday0.Monday_0_18() &amp;&amp; !schedule_boolean_monday0.Monday_0_19() &amp;&amp; !schedule_boolean_monday0.Monday_0_20() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_21() &amp;&amp; !schedule_boolean_monday0.Monday_0_22() &amp;&amp; !schedule_boolean_monday0.Monday_0_23() &amp;&amp; !schedule_boolean_monday0.Monday_0_24()){
          start_time = 0;
          end_time = 1;
          schedule_boolean_monday0.Monday_0_1();
          mon_1.setText(databaseTimetable.Monday_Title(start_time, end_time));
          mon_1.setTextColor(Color.parseColor(databaseTimetable.Monday_Text_Color(start_time, end_time)));
          mon_1.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          return 1;
      }
      //0 am - 2 hr.
      else if (!schedule_boolean_monday0.Monday_0_1() &amp;&amp; schedule_boolean_monday0.Monday_0_2() &amp;&amp; !schedule_boolean_monday0.Monday_0_3() &amp;&amp; !schedule_boolean_monday0.Monday_0_4() &amp;&amp; !schedule_boolean_monday0.Monday_0_5() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_6() &amp;&amp; !schedule_boolean_monday0.Monday_0_7()&amp;&amp; !schedule_boolean_monday0.Monday_0_8() &amp;&amp; !schedule_boolean_monday0.Monday_0_9() &amp;&amp; !schedule_boolean_monday0.Monday_0_10() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_11() &amp;&amp; !schedule_boolean_monday0.Monday_0_12() &amp;&amp; !schedule_boolean_monday0.Monday_0_13() &amp;&amp; !schedule_boolean_monday0.Monday_0_14() &amp;&amp; !schedule_boolean_monday0.Monday_0_15() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_16() &amp;&amp; !schedule_boolean_monday0.Monday_0_17()&amp;&amp; !schedule_boolean_monday0.Monday_0_18() &amp;&amp; !schedule_boolean_monday0.Monday_0_19() &amp;&amp; !schedule_boolean_monday0.Monday_0_20() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_21() &amp;&amp; !schedule_boolean_monday0.Monday_0_22() &amp;&amp; !schedule_boolean_monday0.Monday_0_23() &amp;&amp; !schedule_boolean_monday0.Monday_0_24()){
          start_time = 0;
          end_time = 2;
          schedule_boolean_monday0.Monday_0_2();
          mon_1.setText(databaseTimetable.Monday_Title(start_time, end_time));
          mon_1.setTextColor(Color.parseColor(databaseTimetable.Monday_Text_Color(start_time, end_time)));
          mon_1.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          mon_2.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          return 2;
      }
      //0 am - 3 hr.
      else if (!schedule_boolean_monday0.Monday_0_1() &amp;&amp; !schedule_boolean_monday0.Monday_0_2() &amp;&amp; schedule_boolean_monday0.Monday_0_3() &amp;&amp; !schedule_boolean_monday0.Monday_0_4() &amp;&amp; !schedule_boolean_monday0.Monday_0_5() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_6() &amp;&amp; !schedule_boolean_monday0.Monday_0_7()&amp;&amp; !schedule_boolean_monday0.Monday_0_8() &amp;&amp; !schedule_boolean_monday0.Monday_0_9() &amp;&amp; !schedule_boolean_monday0.Monday_0_10() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_11() &amp;&amp; !schedule_boolean_monday0.Monday_0_12() &amp;&amp; !schedule_boolean_monday0.Monday_0_13() &amp;&amp; !schedule_boolean_monday0.Monday_0_14() &amp;&amp; !schedule_boolean_monday0.Monday_0_15() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_16() &amp;&amp; !schedule_boolean_monday0.Monday_0_17()&amp;&amp; !schedule_boolean_monday0.Monday_0_18() &amp;&amp; !schedule_boolean_monday0.Monday_0_19() &amp;&amp; !schedule_boolean_monday0.Monday_0_20() &amp;&amp;
              !schedule_boolean_monday0.Monday_0_21() &amp;&amp; !schedule_boolean_monday0.Monday_0_22() &amp;&amp; !schedule_boolean_monday0.Monday_0_23() &amp;&amp; !schedule_boolean_monday0.Monday_0_24()){
          start_time = 0;
          end_time = 3;
          schedule_boolean_monday0.Monday_0_3();
          mon_1.setText(databaseTimetable.Monday_Title(start_time, end_time));
          mon_1.setTextColor(Color.parseColor(databaseTimetable.Monday_Text_Color(start_time, end_time)));
          mon_1.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          mon_2.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          mon_3.setBackgroundColor(Color.parseColor(databaseTimetable.Monday_Text_BG_Color(start_time, end_time)));
          return 3;
      }
  
      return 99;
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>This is a class that indicates Boolean variables</strong></p>
  </blockquote>
  
  <pre><code>public class Schedule_Boolean_Monday_0 {
  
      private Context mContext;
      private DatabaseTimetable databaseTimetable;
  
      public Schedule_Boolean_Monday_0(Context context){
          this.mContext = context;
      }
  
      public Boolean Monday_0_1(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,1);
          return !result.equals("");
      }
  
      public Boolean Monday_0_2(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,2);
          return !result.equals("");
      }
  
      public Boolean Monday_0_3(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,3);
          return !result.equals("");
      }
  
      public Boolean Monday_0_4(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,4);
          return !result.equals("");
      }
  
      public Boolean Monday_0_5(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,5);
          return !result.equals("");
      }
  
      public Boolean Monday_0_6(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,6);
          return !result.equals("");
      }
  
      public Boolean Monday_0_7(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,7);
          return !result.equals("");
      }
  
      public Boolean Monday_0_8(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,8);
          return !result.equals("");
      }
  
      public Boolean Monday_0_9(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,9);
          return !result.equals("");
      }
  
      public Boolean Monday_0_10(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,10);
          return !result.equals("");
      }
  
      public Boolean Monday_0_11(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,11);
          return !result.equals("");
      }
  
      public Boolean Monday_0_12(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,12);
          return !result.equals("");
      }
  
      public Boolean Monday_0_13(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,13);
          return !result.equals("");
      }
  
      public Boolean Monday_0_14(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,14);
          return !result.equals("");
      }
  
      public Boolean Monday_0_15(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,15);
          return !result.equals("");
      }
  
      public Boolean Monday_0_16(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,16);
          return !result.equals("");
      }
  
      public Boolean Monday_0_17(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,17);
          return !result.equals("");
      }
  
      public Boolean Monday_0_18(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,18);
          return !result.equals("");
      }
  
      public Boolean Monday_0_19(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,19);
          return !result.equals("");
      }
  
      public Boolean Monday_0_20(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,20);
          return !result.equals("");
      }
  
      public Boolean Monday_0_21(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,21);
          return !result.equals("");
      }
  
      public Boolean Monday_0_22(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,22);
          return !result.equals("");
      }
  
      public Boolean Monday_0_23(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,23);
          return !result.equals("");
      }
  
      public Boolean Monday_0_24(){
          databaseTimetable = new DatabaseTimetable(mContext);
          String result = databaseTimetable.Monday_Title(0,0);
          return !result.equals("");
      }
  }
  </code></pre>
  
  <blockquote>
    <p>There are 24 Boolean variables in each if/else-if arguments. I thought converting to switch methods might lead better performance for my app and if you have any ideas, I'd like to hear your advice.</p>
  </blockquote>