赋值运算符的疑问_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 赋值运算符的疑问

赋值运算符的疑问

 2012/2/17 9:26:20  wnick  程序员俱乐部  我要评论(0)
  • 摘要:看温少的fastjson时看到有一段赋值运算符的代码代码如下://省略了部分代码publicstaticintDEFAULT_PARSER_FEATURE;static{intfeatures=0;features|=Feature.AutoCloseSource.getMask();features|=Feature.InternFieldNames.getMask();features|=Feature.UseBigDecimal.getMask();features|=Feature
  • 标签:
看温少的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;
	}
}


在什么场景使用这类赋值运算符?
  • 相关文章
发表评论
用户名: 匿名