gu.sql2java.ColumnVisibility Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-base Show documentation
Show all versions of sql2java-base Show documentation
sql2java common class package
package gu.sql2java;
import java.util.BitSet;
/**
* 字段可见度定义
* @author guyadong
* @since 3.32.0
*/
public enum ColumnVisibility {
/** 默认:全可见 */DEFAULT(0b11),
/** 只本地可见 */LOCAL(0b00),
/** THRIFT RPC 传输时可见 */THRIFT(0b10),
/** JSON序列化/反序列化时可见 */JSON(0b01);
private final BitSet bitSet;
private ColumnVisibility(int bit) {
this.bitSet = BitSet.valueOf(new byte[] {(byte)bit});
}
public boolean singleVisibility() {
return bitSet.cardinality()==1;
}
/**
* 判断目标 {@code target} 枚举变量的可见范围是否匹配当前枚举变量要求的可见范围
* @param target
*/
public boolean match(ColumnVisibility target) {
if(null == target) {
return false;
}
for(int i = bitSet.length();(i = bitSet.previousSetBit(i-1)) >= 0;) {
if(!target.bitSet.get(i)) {
return false;
}
}
return true;
}
/** 是否JSON序列化/反序列化时可见 */
public boolean isJsonVisiable(){
return bitSet.get(0);
}
/** 是否THRIFT RPC 传输时可见 */
public boolean isThriftVisiable() {
return bitSet.get(1);
}
}