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

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. };  

猜你喜欢

转载自yanfant.iteye.com/blog/1807883
今日推荐