
com.sghd.logging.query.AwkParam Maven / Gradle / Ivy
The newest version!
package com.sghd.logging.query;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author solq log 查询参数对象
*/
public class AwkParam {
private static final String DOUBLE_QUOTATION = "\\\"";
/**
* 查询KEY name
*/
private String name;
/**
* 比较KEY value
*/
private Object value;
/**
* 运算操作符
*/
private AwkOperateType operate;
/**
* command 查询相应的索引
*/
private int index;
/**
* 逻辑运算 and or 默认 true 为 and
*/
private boolean hasAnd = true;
public String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
protected void setValue(Object value) {
this.value = value;
}
public AwkOperateType getOperate() {
return operate;
}
protected void setOperate(AwkOperateType operate) {
this.operate = operate;
}
public int getIndex() {
return index;
}
protected void setIndex(int index) {
this.index = index;
}
public boolean isHasAnd() {
return hasAnd;
}
protected void setHasAnd(boolean hasAnd) {
this.hasAnd = hasAnd;
}
@Override
public String toString() {
// return "$" + index + " " + operateType.operate + " " +
// DOUBLE_QUOTATION + value + DOUBLE_QUOTATION;
final boolean isIn = AwkOperateType.IN.equals(this.operate);
final boolean isEqual = AwkOperateType.EQ.equals(this.operate);
Object v = value;
// 数组IN 取 awk var
if (isIn) {
v = name;
}
final StringBuffer stringBuffer = new StringBuffer();
if(GrepUtil.isLinuxOS) {
stringBuffer.append("( \\$");
} else {
stringBuffer.append("( $");
}
stringBuffer.append(index);
stringBuffer.append(" ");
stringBuffer.append(operate.getOperate());
stringBuffer.append(" ");
if (isEqual && v instanceof String) {
stringBuffer.append(DOUBLE_QUOTATION);
}
stringBuffer.append(v);
if (isEqual && v instanceof String) {
stringBuffer.append(DOUBLE_QUOTATION);
}
stringBuffer.append(" )");
return stringBuffer.toString();
}
/**
* 生成 awk 数组变量
* xxxx[value1] = 1 ;xxxx[value2] = 1
* @return 返回 null 代表没有 awk var
*/
public String getAwkVar() {
if (!AwkOperateType.IN.equals(this.operate)) {
return null;
// new RuntimeException("AwkOperateType not is IN :"+ name);
}
final StringBuffer stringBuffer = new StringBuffer();
int i = 0;
if (value.getClass().isArray()) {
int len = Array.getLength(value);
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy