我有一个问题,我需要考虑4个布尔值的每个可能选项的组合。例如:
我有4个布尔值,useFeatured,groupBy,orderBy &递增。可能的组合是..
featured.
featured & orderby.
featured & orderby & groupby.
featured & orderby & groupby & ascending.
featured & groupby.
featured & groupby & ascending.
featured & ascending
featured & ascedning & orderby
orderby
orderby & groupby
orderby & groupby & ascending
groupby
groupby & ascending
ascending
ascending & orderby
目前,我有一个巨大的if else树,用于这些选项,我发现很难相信这是唯一的解决方案,但我想不出其他的解决方案。
下面是if else树的链接。
if(featured){
if(orderby){
if(groupby){
if(ascedning){
//featured orderby groupby ascending
}else{
//featured orderby groupby
}
}else{
//featured orderby
}
}else if(groupby){
if(ascedning){
//featured groupby ascending
}else{
//featured groupby
}
}else if(ascending){
if(orderby){
//featured ascending orderby
}else{
//featured ascending
}
}else{
//featured
}
}else if(orderby){
if(groupby){
if(ascending){
//orderby groupby ascending
}else{
//orderby groupby
}
}
}else if(groupby){
if(ascending){
//groupby ascending
}else{
//groupvy
}
}else if(ascending){
if(orderby){
//ascending & orderby
}else{
//ascending
}
}else{
//orderby
}
Pastebin如果格式化混乱。http://pastebin.com/ECgASU3C
谁有更好的解决方案,我可以采用?请救救我!
发布于 2013-04-10 09:24:37
您可以将交换机机箱用于this...but ,否则是更好的选项
https://stackoverflow.com/questions/15921731
复制相似问题