首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

用以加强代码流程可读性的工具类

2013-02-24 
用于加强代码流程可读性的工具类Java Language:public?class?LayerResult?{??????private?ListBoolean?r

用于加强代码流程可读性的工具类
Java Language:

  1. public?class?LayerResult?{??
  2. ????private?List<Boolean>?results?=?new?ArrayList<Boolean>();??
  3. ????private?int?layer?=?-1;??
  4. ??????
  5. ????public?boolean?get(){??
  6. ????????return?results.get(layer);??
  7. ????}??
  8. ??????
  9. ????public?boolean?set(boolean?result){??
  10. ????????results.set(layer,?result);??
  11. ????????return?result;??
  12. ????}??
  13. ??????
  14. ????public?boolean?and(boolean?value){??
  15. ????????return?set(get()?&&?value);??
  16. ????}??
  17. ??????
  18. ????public?boolean?or(boolean?value){??
  19. ????????return?set(get()?||?value);??
  20. ????}??
  21. ??????
  22. ????public?void?in(boolean?defaultValue){??
  23. ????????results.add(defaultValue);??
  24. ????????layer?++;??
  25. ????}??
  26. ??????
  27. ????public?boolean?out(){??
  28. ????????layer?--;??
  29. ????????return?results.remove(layer?+?1);??
  30. ????}??
  31. }
?Javascript Language:
  1. var?LayerResult?=?function(){??
  2. };??
  3. LayerResult.prototype?=?{??
  4. ????results?:?[],??
  5. ????layer?:?-1,??
  6. ????get?:?function(){??
  7. ????????return?results[layer]??
  8. ????},??
  9. ????set?:?function(value){??
  10. ????????results[layer]?=?value;??
  11. ????????return?value;??
  12. ????},??
  13. ????and?:?function(value){??
  14. ????????return?this.set(this.get()?&&?value);??
  15. ????},??
  16. ????or?:?function(value){??
  17. ????????return?this.set(this.get()?||?value);??
  18. ????},??
  19. ????in?:?function(defaultValue){??
  20. ????????results.push(defaultValue);??
  21. ????},??
  22. ????out?:?function(){??
  23. ????????return?results.pop();??
  24. ????}??
  25. }; ?

热点排行