use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class SeekCursorTest method shouldCatchupRootWhenRootNodeHasTooNewGeneration.
@Test
public void shouldCatchupRootWhenRootNodeHasTooNewGeneration() throws Exception {
// given
long id = cursor.getCurrentPageId();
long generation = node.generation(cursor);
MutableBoolean triggered = new MutableBoolean(false);
Supplier<Root> rootCatchup = () -> {
triggered.setTrue();
return new Root(id, generation);
};
// when
try (SeekCursor<MutableLong, MutableLong> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, generation - 1)) {
// do nothing
}
// then
assertTrue(triggered.getValue());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class QueryTranslator method asyncCreateAndRunJob.
private void asyncCreateAndRunJob(IHyracksClientConnection hcc, IStatementCompiler compiler, IMetadataLocker locker, ResultDelivery resultDelivery, String clientContextId, IStatementExecutorContext ctx, ResultSetId resultSetId, MutableBoolean printed) {
Mutable<JobId> jobId = new MutableObject<>(JobId.INVALID);
try {
createAndRunJob(hcc, jobId, compiler, locker, resultDelivery, id -> {
final ResultHandle handle = new ResultHandle(id, resultSetId);
ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.RUNNING);
ResultUtil.printResultHandle(sessionOutput, handle);
synchronized (printed) {
printed.setTrue();
printed.notify();
}
}, clientContextId, ctx);
} catch (Exception e) {
if (JobId.INVALID.equals(jobId.getValue())) {
// compilation failed
ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.FAILED);
ResultUtil.printError(sessionOutput.out(), e);
} else {
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, resultDelivery.name() + " job with id " + jobId.getValue() + " " + "failed", e);
}
} finally {
synchronized (printed) {
if (printed.isFalse()) {
printed.setTrue();
printed.notify();
}
}
}
}
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;
}
Aggregations