Я использую оператор else-if для проверки логических значений, и поскольку использование else-if вызывает низкую производительность.
По этой причине я планирую преобразовать оператор else-if в оператор switch, поэтому я хотел бы услышать ваш совет по его правильному преобразованию.
Это мой оператор else-if
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() && !schedule_boolean_monday0.Monday_0_2() && !schedule_boolean_monday0.Monday_0_3() && !schedule_boolean_monday0.Monday_0_4() && !schedule_boolean_monday0.Monday_0_5() &&
!schedule_boolean_monday0.Monday_0_6() && !schedule_boolean_monday0.Monday_0_7()&& !schedule_boolean_monday0.Monday_0_8() && !schedule_boolean_monday0.Monday_0_9() && !schedule_boolean_monday0.Monday_0_10() &&
!schedule_boolean_monday0.Monday_0_11() && !schedule_boolean_monday0.Monday_0_12() && !schedule_boolean_monday0.Monday_0_13() && !schedule_boolean_monday0.Monday_0_14() && !schedule_boolean_monday0.Monday_0_15() &&
!schedule_boolean_monday0.Monday_0_16() && !schedule_boolean_monday0.Monday_0_17()&& !schedule_boolean_monday0.Monday_0_18() && !schedule_boolean_monday0.Monday_0_19() && !schedule_boolean_monday0.Monday_0_20() &&
!schedule_boolean_monday0.Monday_0_21() && !schedule_boolean_monday0.Monday_0_22() && !schedule_boolean_monday0.Monday_0_23() && !schedule_boolean_monday0.Monday_0_24()){
return 0;
}
//0 am - 1 hr.
else if (schedule_boolean_monday0.Monday_0_1() && !schedule_boolean_monday0.Monday_0_2() && !schedule_boolean_monday0.Monday_0_3() && !schedule_boolean_monday0.Monday_0_4() && !schedule_boolean_monday0.Monday_0_5() &&
!schedule_boolean_monday0.Monday_0_6() && !schedule_boolean_monday0.Monday_0_7()&& !schedule_boolean_monday0.Monday_0_8() && !schedule_boolean_monday0.Monday_0_9() && !schedule_boolean_monday0.Monday_0_10() &&
!schedule_boolean_monday0.Monday_0_11() && !schedule_boolean_monday0.Monday_0_12() && !schedule_boolean_monday0.Monday_0_13() && !schedule_boolean_monday0.Monday_0_14() && !schedule_boolean_monday0.Monday_0_15() &&
!schedule_boolean_monday0.Monday_0_16() && !schedule_boolean_monday0.Monday_0_17()&& !schedule_boolean_monday0.Monday_0_18() && !schedule_boolean_monday0.Monday_0_19() && !schedule_boolean_monday0.Monday_0_20() &&
!schedule_boolean_monday0.Monday_0_21() && !schedule_boolean_monday0.Monday_0_22() && !schedule_boolean_monday0.Monday_0_23() && !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() && schedule_boolean_monday0.Monday_0_2() && !schedule_boolean_monday0.Monday_0_3() && !schedule_boolean_monday0.Monday_0_4() && !schedule_boolean_monday0.Monday_0_5() &&
!schedule_boolean_monday0.Monday_0_6() && !schedule_boolean_monday0.Monday_0_7()&& !schedule_boolean_monday0.Monday_0_8() && !schedule_boolean_monday0.Monday_0_9() && !schedule_boolean_monday0.Monday_0_10() &&
!schedule_boolean_monday0.Monday_0_11() && !schedule_boolean_monday0.Monday_0_12() && !schedule_boolean_monday0.Monday_0_13() && !schedule_boolean_monday0.Monday_0_14() && !schedule_boolean_monday0.Monday_0_15() &&
!schedule_boolean_monday0.Monday_0_16() && !schedule_boolean_monday0.Monday_0_17()&& !schedule_boolean_monday0.Monday_0_18() && !schedule_boolean_monday0.Monday_0_19() && !schedule_boolean_monday0.Monday_0_20() &&
!schedule_boolean_monday0.Monday_0_21() && !schedule_boolean_monday0.Monday_0_22() && !schedule_boolean_monday0.Monday_0_23() && !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() && !schedule_boolean_monday0.Monday_0_2() && schedule_boolean_monday0.Monday_0_3() && !schedule_boolean_monday0.Monday_0_4() && !schedule_boolean_monday0.Monday_0_5() &&
!schedule_boolean_monday0.Monday_0_6() && !schedule_boolean_monday0.Monday_0_7()&& !schedule_boolean_monday0.Monday_0_8() && !schedule_boolean_monday0.Monday_0_9() && !schedule_boolean_monday0.Monday_0_10() &&
!schedule_boolean_monday0.Monday_0_11() && !schedule_boolean_monday0.Monday_0_12() && !schedule_boolean_monday0.Monday_0_13() && !schedule_boolean_monday0.Monday_0_14() && !schedule_boolean_monday0.Monday_0_15() &&
!schedule_boolean_monday0.Monday_0_16() && !schedule_boolean_monday0.Monday_0_17()&& !schedule_boolean_monday0.Monday_0_18() && !schedule_boolean_monday0.Monday_0_19() && !schedule_boolean_monday0.Monday_0_20() &&
!schedule_boolean_monday0.Monday_0_21() && !schedule_boolean_monday0.Monday_0_22() && !schedule_boolean_monday0.Monday_0_23() && !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;
}
}
Это класс, который указывает логические переменные
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("");
}
}
В каждом аргументе if / else-if есть 24 булевых переменных. Я думал, что переход на методы переключения может привести к повышению производительности моего приложения, и если у вас есть какие-либо идеи, я хотел бы услышать ваш совет.