论坛首页 Java企业应用论坛

赋值运算符的疑问

浏览 1881 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-02-16  
看温少的fastjson时看到有一段赋值运算符的代码
代码如下:

//省略了部分代码
public static int    DEFAULT_PARSER_FEATURE;
    static {
        int features = 0;
        features |= Feature.AutoCloseSource.getMask();
        features |= Feature.InternFieldNames.getMask();
        features |= Feature.UseBigDecimal.getMask();
        features |= Feature.AllowUnQuotedFieldNames.getMask();
        features |= Feature.AllowSingleQuotes.getMask();
        features |= Feature.AllowArbitraryCommas.getMask();
        features |= Feature.SortFeidFastMatch.getMask();
        features |= Feature.IgnoreNotMatch.getMask();
        DEFAULT_PARSER_FEATURE = features;
    }
// 这里是调用方法
public static final Object parse(String text, int features) {
  //..
}



public enum Feature {
	   
	    AutoCloseSource,
	   
	    AllowComment,
	    
	    AllowUnQuotedFieldNames,
	   
	    AllowSingleQuotes
	    ;

	    private Feature(){
	        mask = (1 << ordinal());
	    }

	    private final int mask;

	    public final int getMask() {
	        return mask;
	    }

	    public static boolean isEnabled(int features, Feature feature) {
	        return (features & feature.getMask()) != 0;
	    }

	    public static int config(int features, Feature feature, boolean state) {
	        if (state) {
	            features |= feature.getMask();
	        } else {
	            features &= ~feature.getMask();
	        }

	        return features;
	}
}


在什么场景使用这类赋值运算符?
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics