use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Operation method compareBools.
public static void compareBools(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
MutableBoolean b1 = objectPool.boolPool.get();
MutableBoolean b2 = objectPool.boolPool.get();
boolean compResult = false;
v1.isBooleanValue(b1);
v2.isBooleanValue(b2);
switch(op) {
case OpKind_LESS_THAN_OP:
compResult = (b1.compareTo(b2) < 0);
break;
case OpKind_LESS_OR_EQUAL_OP:
compResult = (b1.compareTo(b2) <= 0);
break;
case OpKind_EQUAL_OP:
compResult = (b1.booleanValue() == b2.booleanValue());
break;
case OpKind_META_EQUAL_OP:
compResult = (b1.booleanValue() == b2.booleanValue());
break;
case OpKind_NOT_EQUAL_OP:
compResult = (b1.booleanValue() != b2.booleanValue());
break;
case OpKind_META_NOT_EQUAL_OP:
compResult = (b1.booleanValue() != b2.booleanValue());
break;
case OpKind_GREATER_THAN_OP:
compResult = (b1.compareTo(b2) > 0);
break;
case OpKind_GREATER_OR_EQUAL_OP:
compResult = (b1.compareTo(b2) >= 0);
break;
default:
// should not get here
throw new HyracksDataException("Should not get here");
}
result.setBooleanValue(compResult);
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Operation method doLogical.
public static int doLogical(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
MutableBoolean b1 = objectPool.boolPool.get();
MutableBoolean b2 = objectPool.boolPool.get();
// first coerece inputs to boolean if they are considered equivalent
if (!v1.isBooleanValue(b1) && v1.isBooleanValueEquiv(b1)) {
v1.setBooleanValue(b1.booleanValue());
}
if (!v2.isBooleanValue(b2) && v2.isBooleanValueEquiv(b2)) {
v2.setBooleanValue(b2);
}
ValueType vt1 = v1.getType();
ValueType vt2 = v2.getType();
if (vt1 != ValueType.UNDEFINED_VALUE && vt1 != ValueType.ERROR_VALUE && vt1 != ValueType.BOOLEAN_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD1.ordinal();
}
if (vt2 != ValueType.UNDEFINED_VALUE && vt2 != ValueType.ERROR_VALUE && vt2 != ValueType.BOOLEAN_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD2.ordinal();
}
// handle unary operator
if (op == OpKind_LOGICAL_NOT_OP) {
if (vt1 == ValueType.BOOLEAN_VALUE) {
result.setBooleanValue(!b1.booleanValue());
} else {
result.setValue(v1);
}
return SigValues.SIG_CHLD1.ordinal();
}
if (op == OpKind_LOGICAL_OR_OP) {
if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
result.setBooleanValue(true);
return SigValues.SIG_CHLD1.ordinal();
} else if (vt1 == ValueType.ERROR_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD1.ordinal();
} else if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
result.setValue(v2);
} else if (vt2 != ValueType.BOOLEAN_VALUE) {
result.setValue(v2);
} else if (b2.booleanValue()) {
result.setBooleanValue(true);
} else {
result.setUndefinedValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
} else if (op == OpKind_LOGICAL_AND_OP) {
if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
result.setBooleanValue(false);
return SigValues.SIG_CHLD1.ordinal();
} else if (vt1 == ValueType.ERROR_VALUE) {
result.setErrorValue();
return SigValues.SIG_CHLD1.ordinal();
} else if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
result.setValue(v2);
} else if (vt2 != ValueType.BOOLEAN_VALUE) {
result.setValue(v2);
} else if (!b2.booleanValue()) {
result.setBooleanValue(false);
} else {
result.setUndefinedValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
throw new HyracksDataException("Shouldn't reach here");
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Value method convertValueToRealValue.
public static boolean convertValueToRealValue(Value value, Value realValue, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean could_convert;
AMutableCharArrayString buf = objectPool.strPool.get();
int endIndex;
char end;
AMutableInt64 ivalue = objectPool.int64Pool.get();
ClassAdTime atvalue = objectPool.classAdTimePool.get();
MutableBoolean bvalue = objectPool.boolPool.get();
double rvalue;
NumberFactor nf = NumberFactor.NO_FACTOR;
switch(value.getType()) {
case UNDEFINED_VALUE:
realValue.setUndefinedValue();
could_convert = false;
break;
case ERROR_VALUE:
case CLASSAD_VALUE:
case LIST_VALUE:
case SLIST_VALUE:
realValue.setErrorValue();
could_convert = false;
break;
case STRING_VALUE:
could_convert = true;
value.isStringValue(buf);
endIndex = buf.fistNonDoubleDigitChar();
if (endIndex < 0) {
// no non digit
String buffString = buf.toString();
if (buffString.contains("INF")) {
buffString = buffString.replace("INF", "Infinity");
}
rvalue = Double.parseDouble(buffString);
nf = NumberFactor.NO_FACTOR;
} else {
rvalue = Double.parseDouble(buf.substr(0, endIndex));
end = buf.charAt(endIndex);
switch(Character.toUpperCase(end)) {
case 'B':
nf = NumberFactor.B_FACTOR;
break;
case 'K':
nf = NumberFactor.K_FACTOR;
break;
case 'M':
nf = NumberFactor.M_FACTOR;
break;
case 'G':
nf = NumberFactor.G_FACTOR;
break;
case 'T':
nf = NumberFactor.T_FACTOR;
break;
case '\0':
nf = NumberFactor.NO_FACTOR;
break;
default:
nf = NumberFactor.NO_FACTOR;
break;
}
}
if (could_convert) {
realValue.setRealValue(rvalue * Value.ScaleFactor[nf.ordinal()]);
}
break;
case BOOLEAN_VALUE:
value.isBooleanValue(bvalue);
realValue.setRealValue(bvalue.booleanValue() ? 1.0 : 0.0);
could_convert = true;
break;
case INTEGER_VALUE:
value.isIntegerValue(ivalue);
realValue.setRealValue(ivalue.getLongValue());
could_convert = true;
break;
case REAL_VALUE:
realValue.setValue(value);
could_convert = true;
break;
case ABSOLUTE_TIME_VALUE:
value.isAbsoluteTimeValue(atvalue);
realValue.setRealValue(atvalue.getTimeInMillis() / 1000.0);
could_convert = true;
break;
case RELATIVE_TIME_VALUE:
value.isRelativeTimeValue(atvalue);
realValue.setRealValue(atvalue.getRelativeTime() / 1000.0);
could_convert = true;
break;
default:
// Make gcc's -Wuninitalized happy
could_convert = false;
throw new HyracksDataException("Should not reach here");
}
return could_convert;
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Value method convertValueToIntegerValue.
public static boolean convertValueToIntegerValue(Value value, Value integerValue, ClassAdObjectPool objectPool) throws HyracksDataException {
boolean could_convert;
AMutableCharArrayString buf = objectPool.strPool.get();
char end;
AMutableInt64 ivalue = objectPool.int64Pool.get();
AMutableDouble rtvalue = objectPool.doublePool.get();
ClassAdTime atvalue = objectPool.classAdTimePool.get();
MutableBoolean bvalue = objectPool.boolPool.get();
NumberFactor nf;
switch(value.getType()) {
case UNDEFINED_VALUE:
integerValue.setUndefinedValue();
could_convert = false;
break;
case ERROR_VALUE:
case CLASSAD_VALUE:
case LIST_VALUE:
case SLIST_VALUE:
integerValue.setErrorValue();
could_convert = false;
break;
case STRING_VALUE:
could_convert = true;
value.isStringValue(buf);
int endIndex = buf.firstNonDigitChar();
if (endIndex < 0) {
// no non digit
ivalue.setValue(Long.parseLong(buf.toString()));
nf = NumberFactor.NO_FACTOR;
break;
} else {
ivalue.setValue(Long.parseLong(buf.substr(0, endIndex)));
end = buf.charAt(endIndex);
switch(Character.toUpperCase(end)) {
case 'B':
nf = NumberFactor.B_FACTOR;
break;
case 'K':
nf = NumberFactor.K_FACTOR;
break;
case 'M':
nf = NumberFactor.M_FACTOR;
break;
case 'G':
nf = NumberFactor.G_FACTOR;
break;
case 'T':
nf = NumberFactor.T_FACTOR;
break;
case '\0':
nf = NumberFactor.NO_FACTOR;
break;
default:
nf = NumberFactor.NO_FACTOR;
break;
}
if (could_convert) {
integerValue.setIntegerValue((long) ((ivalue.getLongValue() * Value.ScaleFactor[nf.ordinal()])));
}
}
break;
case BOOLEAN_VALUE:
value.isBooleanValue(bvalue);
integerValue.setIntegerValue(bvalue.booleanValue() ? 1 : 0);
could_convert = true;
break;
case INTEGER_VALUE:
integerValue.setValue(value);
could_convert = true;
break;
case REAL_VALUE:
value.isRealValue(rtvalue);
integerValue.setIntegerValue((long) rtvalue.getDoubleValue());
could_convert = true;
break;
case ABSOLUTE_TIME_VALUE:
value.isAbsoluteTimeValue(atvalue);
integerValue.setIntegerValue(atvalue.getTimeInMillis() / 1000L);
could_convert = true;
break;
case RELATIVE_TIME_VALUE:
value.isRelativeTimeValue(atvalue);
integerValue.setIntegerValue((atvalue.getTime() / 1000L));
could_convert = true;
break;
default:
// Make gcc's -Wuninitalized happy
could_convert = false;
throw new HyracksDataException("Should not reach here");
}
return could_convert;
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class Operation method doArithmetic.
public static int doArithmetic(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
AMutableInt64 i1 = objectPool.int64Pool.get();
AMutableInt64 i2 = objectPool.int64Pool.get();
ClassAdTime t1 = objectPool.classAdTimePool.get();
AMutableDouble r1 = objectPool.doublePool.get();
MutableBoolean b1 = objectPool.boolPool.get();
// ensure the operands have arithmetic types
if ((!v1.isIntegerValue() && !v1.isRealValue() && !v1.isAbsoluteTimeValue() && !v1.isRelativeTimeValue() && !v1.isBooleanValue()) || (op != OpKind_UNARY_MINUS_OP && !v2.isBooleanValue() && !v2.isIntegerValue() && !v2.isRealValue() && !v2.isAbsoluteTimeValue() && !v2.isRelativeTimeValue())) {
result.setErrorValue();
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
}
// take care of the unary arithmetic operators
if (op == OpKind_UNARY_MINUS_OP) {
if (v1.isIntegerValue(i1)) {
result.setIntegerValue((-1L) * i1.getLongValue());
return SigValues.SIG_CHLD1.ordinal();
} else if (v1.isRealValue(r1)) {
result.setRealValue((-1) * r1.getDoubleValue());
return SigValues.SIG_CHLD1.ordinal();
} else if (v1.isRelativeTimeValue(t1)) {
t1.setValue((-1) * t1.getTimeInMillis());
result.setRelativeTimeValue(t1);
return (SigValues.SIG_CHLD1.ordinal());
} else if (v1.isBooleanValue(b1)) {
result.setBooleanValue(!b1.booleanValue());
} else if (v1.isExceptional()) {
// undefined or error --- same as operand
result.setValue(v1);
return SigValues.SIG_CHLD1.ordinal();
}
// unary minus not defined on any other operand type
result.setErrorValue();
return (SigValues.SIG_CHLD1.ordinal());
}
// perform type promotions and proceed with arithmetic
switch(coerceToNumber(v1, v2, objectPool)) {
case INTEGER_VALUE:
v1.isIntegerValue(i1);
v2.isIntegerValue(i2);
switch(op) {
case OpKind_ADDITION_OP:
result.setIntegerValue(i1.getLongValue() + i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_SUBTRACTION_OP:
result.setIntegerValue(i1.getLongValue() - i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_MULTIPLICATION_OP:
result.setIntegerValue(i1.getLongValue() * i2.getLongValue());
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_DIVISION_OP:
if (i2.getLongValue() != 0L) {
result.setIntegerValue(i1.getLongValue() / i2.getLongValue());
} else {
result.setErrorValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
case OpKind_MODULUS_OP:
if (i2.getLongValue() != 0) {
result.setIntegerValue(i1.getLongValue() % i2.getLongValue());
} else {
result.setErrorValue();
}
return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
default:
// should not reach here
throw new HyracksDataException("Should not get here");
}
case REAL_VALUE:
{
return (doRealArithmetic(op, v1, v2, result, objectPool));
}
case ABSOLUTE_TIME_VALUE:
case RELATIVE_TIME_VALUE:
{
return (doTimeArithmetic(op, v1, v2, result, objectPool));
}
default:
// should not get here
throw new HyracksDataException("Should not get here");
}
}
Aggregations