List of usage examples for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean
public MutableBoolean()
From source file:com.mgmtp.perfload.agent.Transformer.java
@Override public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) throws IllegalClassFormatException { final String classNameWithDots = className.replace('/', '.'); EntryPoints entryPoints = config.getEntryPoints(); final Map<String, MethodInstrumentations> methodsConfig = config.getInstrumentations() .get(classNameWithDots);//from ww w . ja v a 2 s . c o m final boolean isFilter = entryPoints.hasFilter(classNameWithDots); final boolean isServlet = entryPoints.hasServlet(classNameWithDots); if (methodsConfig == null && !isFilter && !isServlet) { // no instrumentation configured for this class // return null, so no transformation is done return null; } logger.writeln("Transforming class: " + classNameWithDots); // flag for storing if at least one hook is weaved in final MutableBoolean weaveFlag = new MutableBoolean(); ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); ClassVisitor cv = new ClassVisitor(Opcodes.ASM4, cw) { @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv != null) { if (isFilter && "doFilter".equals(name) || isServlet && "service".equals(name) && SERVLET_SERVICE_DESC.equals(desc)) { mv = createServletApiHookVisitor(access, name, desc, mv); } if (methodsConfig != null) { MethodInstrumentations methodInstrumentations = methodsConfig.get(name); if (methodInstrumentations != null) { mv = createMeasuringHookVisitor(access, name, desc, mv, methodInstrumentations); } } } return mv; } private MethodVisitor createMeasuringHookVisitor(final int access, final String methodName, final String desc, final MethodVisitor mv, final MethodInstrumentations methodInstrumentations) { boolean weave = false; if (methodInstrumentations.isEmpty()) { // no params configured, so we just weave the hook into any method with this name weave = true; } else { // weave if params match for (List<String> paramClassNames : methodInstrumentations) { Type[] argumentTypes = Type.getArgumentTypes(desc); List<String> classNames = newArrayListWithCapacity(argumentTypes.length); for (Type argumentType : argumentTypes) { classNames.add(argumentType.getClassName()); } if (classNames.equals(paramClassNames)) { weave = true; break; } } } if (weave) { logger.writeln("Instrumenting method: " + classNameWithDots + "." + methodName); weaveFlag.setValue(true); return new MeasuringHookMethodVisitor(access, classNameWithDots, methodName, desc, mv); } return mv; } private MethodVisitor createServletApiHookVisitor(final int access, final String methodName, final String desc, final MethodVisitor mv) { logger.writeln("Adding servlet api hook: " + classNameWithDots + "." + methodName); weaveFlag.setValue(true); return new ServletApiHookMethodVisitor(access, methodName, desc, mv); } }; // accept the visitor in order to perform weaving cr.accept(cv, ClassReader.EXPAND_FRAMES); if (weaveFlag.isTrue()) { byte[] transformedclassBytes = cw.toByteArray(); dumpTransformedClassFile(className, transformedclassBytes); return transformedclassBytes; } // no transformation return null; }
From source file:asterix.parser.classad.ClassAdUnParser.java
/** * Unparse a value//from w w w . j ava2 s.c om * * @param buffer * The string to unparse to * @param val * The value to unparse * @throws HyracksDataException */ public void unparse(AMutableCharArrayString buffer, Value val) throws HyracksDataException { switch (val.getType()) { case NULL_VALUE: buffer.appendString("(null-value)"); break; case STRING_VALUE: { AMutableCharArrayString s = new AMutableCharArrayString(); val.isStringValue(s); buffer.appendChar('"'); for (int i = 0; i < s.getLength(); i++) { char ch = s.charAt(i); if (ch == delimiter) { if (delimiter == '\"') { buffer.appendString("\\\""); continue; } else { buffer.appendString("\\\'"); continue; } } switch (ch) { case '\b': buffer.appendString("\\b"); continue; case '\f': buffer.appendString("\\f"); continue; case '\n': buffer.appendString("\\n"); continue; case '\r': buffer.appendString("\\r"); continue; case '\t': buffer.appendString("\\t"); continue; case '\\': buffer.appendString("\\\\"); continue; case '\'': buffer.appendString("\'"); continue; case '\"': buffer.appendString("\""); continue; default: if (Character.isISOControl(ch)) { // print octal representation buffer.appendString(String.format("\\%03o", ch)); continue; } break; } buffer.appendChar(ch); } buffer.appendChar('"'); return; } case INTEGER_VALUE: { AMutableInt64 i = new AMutableInt64(0); val.isIntegerValue(i); buffer.appendString(String.valueOf(i.getLongValue())); return; } case REAL_VALUE: { AMutableDouble real = new AMutableDouble(0); val.isRealValue(real); if (real.getDoubleValue() == 0.0) { // It might be positive or negative and it's // hard to tell. printf is good at telling though. // We also want to print it with as few // digits as possible, which is why we don't use the // case below. buffer.appendString(String.valueOf(real.getDoubleValue())); } else if (Util.isNan(real.getDoubleValue())) { buffer.appendString("real(\"NaN\")"); } else if (Util.isInf(real.getDoubleValue()) == -1) { buffer.appendString("real(\"-INF\")"); } else if (Util.isInf(real.getDoubleValue()) == 1) { buffer.appendString("real(\"INF\")"); } else { buffer.appendString(String.format("%1.15E", real.getDoubleValue())); } return; } case BOOLEAN_VALUE: { MutableBoolean b = new MutableBoolean(); val.isBooleanValue(b); buffer.appendString(b.booleanValue() ? "true" : "false"); return; } case UNDEFINED_VALUE: { buffer.appendString("undefined"); return; } case ERROR_VALUE: { buffer.appendString("error"); return; } case ABSOLUTE_TIME_VALUE: { ClassAdTime asecs = new ClassAdTime(); val.isAbsoluteTimeValue(asecs); buffer.appendString("absTime(\""); Util.absTimeToString(asecs, buffer); buffer.appendString("\")"); return; } case RELATIVE_TIME_VALUE: { ClassAdTime rsecs = new ClassAdTime(); val.isRelativeTimeValue(rsecs); buffer.appendString("relTime(\""); Util.relTimeToString(rsecs.getRelativeTime(), buffer); buffer.appendString("\")"); return; } case CLASSAD_VALUE: { ClassAd ad = new ClassAd(); Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>(); val.isClassAdValue(ad); ad.getComponents(attrs); unparseAux(buffer, attrs); return; } case SLIST_VALUE: case LIST_VALUE: { ExprList el = new ExprList(); val.isListValue(el); unparseAux(buffer, el); return; } } }
From source file:de.uni_potsdam.hpi.asg.logictool.synthesis.CElementSynthesis.java
@Override public boolean doComplementaryCheck(Reset reset) { for (Signal sig : stateGraph.getAllSignals()) { if (sig.isInternalOrOutput()) { Set<NetlistVariable> ands_set = syn2.getSetnetworkMap().get(sig); Set<NetlistVariable> ands_reset = syn2.getResetnetworkMap().get(sig); BDD setbdd = null;//from www . j a v a 2 s. c o m if (!ands_set.isEmpty()) { setbdd = netlist.getFac().zero(); for (NetlistVariable var : ands_set) { setbdd = setbdd.or(var.getDriver().getBdd()); } } BDD resetbdd = null; if (!ands_reset.isEmpty()) { resetbdd = netlist.getFac().zero(); for (NetlistVariable var : ands_reset) { resetbdd = resetbdd.or(var.getDriver().getBdd()); } } if (setbdd == null && resetbdd == null) { logger.error("Both networks are empty"); return false; } else if (setbdd == null) { networksComplementaryMap.put(sig, ComplementaryDecision.RESETANDC); } else if (resetbdd == null) { networksComplementaryMap.put(sig, ComplementaryDecision.SETANDC); } else { MutableBoolean setresult = new MutableBoolean(); MutableBoolean resetresult = new MutableBoolean(); boolean complementary = true; boolean onsetfull = true; boolean offsetfull = true; for (State s : stateGraph.getStates()) { if (!BDDHelper.evaluateBDD(setresult, setbdd, s, netlist)) { logger.error("Coult not eval set network for " + sig.getName()); } if (!BDDHelper.evaluateBDD(resetresult, resetbdd, s, netlist)) { logger.error("Coult not eval reset network for " + sig.getName()); } switch (s.getStateValues().get(sig)) { case rising: case high: if (!setresult.booleanValue()) { onsetfull = false; } break; case low: case falling: if (!resetresult.booleanValue()) { offsetfull = false; } break; } if (!setresult.booleanValue() && !resetresult.booleanValue()) { //set=0, reset=0 // => no complementary mapping complementary = false; } if (!complementary && !onsetfull && !offsetfull) { break; } } Map<Signal, ResetDecision> resetDecision = reset.getDecision(); NetlistVariable var = netlist.getNetlistVariableBySignal(sig); NetlistTerm celemterm = var.getDriver(); if (!(celemterm instanceof NetlistCelem)) { logger.error("Signal " + sig.getName() + " is not driven by an Celem"); return false; } NetlistCelem celem = (NetlistCelem) celemterm; InternalArch arch = celem.getArch(); if (complementary) { networksComplementaryMap.put(sig, ComplementaryDecision.BOTH); } else if (onsetfull) { networksComplementaryMap.put(sig, ComplementaryDecision.SETONLY); } else if (offsetfull) { networksComplementaryMap.put(sig, ComplementaryDecision.RESETONLY); } else { networksComplementaryMap.put(sig, ComplementaryDecision.NONE); switch (resetDecision.get(sig)) { case NORST: break; case RESETRST: switch (arch) { case standardC: case generalisedCreset: break; case generalisedCset: resetDecision.put(sig, ResetDecision.NORST); break; } break; case SETRST: switch (arch) { case standardC: case generalisedCset: break; case generalisedCreset: resetDecision.put(sig, ResetDecision.NORST); break; } break; case BOTHRST: switch (arch) { case generalisedCreset: resetDecision.put(sig, ResetDecision.RESETRST); break; case generalisedCset: resetDecision.put(sig, ResetDecision.SETRST); break; case standardC: break; } break; } } } } } return true; }
From source file:asterix.parser.classad.ClassAdUnParser.java
/** * Unparse an expression//from w ww .j a va 2s .c om * * @param buffer * The string to unparse to * @param expr * The expression to unparse * @throws HyracksDataException */ public void unparse(AMutableCharArrayString buffer, ExprTree tree) throws HyracksDataException { if (tree == null) { buffer.appendString("<error:null expr>"); return; } switch (tree.getKind()) { case LITERAL_NODE: { // value Value val = new Value(); AMutableNumberFactor factor = new AMutableNumberFactor(); ((Literal) tree.self()).getComponents(val, factor); unparseAux(buffer, val, factor.getFactor()); return; } case ATTRREF_NODE: { // string ExprTreeHolder expr = new ExprTreeHolder(); //needs initialization AMutableCharArrayString ref = new AMutableCharArrayString(); MutableBoolean absolute = new MutableBoolean(); ((AttributeReference) tree.self()).getComponents(expr, ref, absolute); unparseAux(buffer, expr, ref, absolute.booleanValue()); return; } case OP_NODE: { //string AMutableInt32 op = new AMutableInt32(0); ExprTreeHolder t1 = new ExprTreeHolder(); ExprTreeHolder t2 = new ExprTreeHolder(); ExprTreeHolder t3 = new ExprTreeHolder(); ((Operation) tree.self()).getComponents(op, t1, t2, t3); unparseAux(buffer, op.getIntegerValue().intValue(), t1, t2, t3); return; } case FN_CALL_NODE: { // string AMutableCharArrayString fnName = new AMutableCharArrayString(); ExprList args = new ExprList(); ((FunctionCall) tree.self()).getComponents(fnName, args); unparseAux(buffer, fnName, args); return; } case CLASSAD_NODE: { // nested record Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>(); ((ClassAd) tree.self()).getComponents(attrs); unparseAux(buffer, attrs); return; } case EXPR_LIST_NODE: { // list ExprList exprs = new ExprList(); ((ExprList) tree.self()).getComponents(exprs); unparseAux(buffer, exprs); return; } default: // I really wonder whether we should except here, but I // don't want to do that without further consultation. // wenger 2003-12-11. buffer.setValue(""); throw new HyracksDataException("unknown expression type"); } }
From source file:asterix.parser.classad.FunctionCall.java
public boolean privateEvaluate(EvalState state, Value value, ExprTreeHolder tree) throws HyracksDataException { FunctionCall tmpSig = new FunctionCall(); Value tmpVal = new Value(); ExprTreeHolder argSig = new ExprTreeHolder(); MutableBoolean rval = new MutableBoolean(); if (!privateEvaluate(state, value)) { return false; }//ww w.j av a2s . co m tmpSig.functionName = functionName; rval.setValue(true); for (ExprTree i : arguments.getExprList()) { rval.setValue(i.publicEvaluate(state, tmpVal, argSig)); if (rval.booleanValue()) tmpSig.arguments.add(argSig.getInnerTree()); } tree.setInnerTree(tmpSig); return rval.booleanValue(); }
From source file:asterix.parser.classad.test.ClassAdUnitTester.java
/********************************************************************* * Function: test_classad//ww w . ja v a2s . c o m * Purpose: Test the ClassAd class. * * @throws IOException *********************************************************************/ public static void testClassad(Parameters parameters, Results results) throws IOException { ClassAdParser parser = new ClassAdParser(); boolean haveAttribute; boolean success; System.out.println("Testing the ClassAd class..."); String input_basic = "[ A = 3; B = 4.0; C = \"babyzilla\"; D = true; E = {1}; F = [ AA = 3; ]; G =\"deleteme\";]"; ClassAd basic = new ClassAd(); AMutableInt64 i = new AMutableInt64(0); MutableBoolean b = new MutableBoolean(); AMutableDouble r = new AMutableDouble(0); AMutableCharArrayString s = new AMutableCharArrayString(); ClassAd c = new ClassAd(); //ExprList *l; basic = parser.parseClassAd(input_basic); /* ----- Test EvaluateAttr* ----- */ haveAttribute = basic.evaluateAttrInt("A", i); test("Have attribute A", (haveAttribute == true), "test_classad 1", results); test("A is 3", (i.getLongValue() == 3), "test_classad 2", results); haveAttribute = basic.evaluateAttrReal("B", r); test("Have attribute B", (haveAttribute == true), "test_classad 3", results); test("B is 4.0", (r.getDoubleValue() == 4.0), "test_classad 4", results); haveAttribute = basic.evaluateAttrString("C", s); test("Have attribute C", (haveAttribute == true), "test_classad 5", results); test("C is 'babyzilla'", (s.compareTo("babyzilla") == 0), "test_classad 6", results); haveAttribute = basic.evaluateAttrBool("D", b); test("Have attribute D", (haveAttribute == true), "test_classad 7", results); test("D is true", (b.booleanValue() == true), "test_classad 8", results); /* ----- Test basic insert and delete ----- */ success = basic.insertAttr("new", 4); test("InsertAttr claims to have worked", (success == true), "test_classad 9", results); haveAttribute = basic.evaluateAttrInt("new", i); test("Have new attribute", (haveAttribute == true), "test_classad 10", results); test("new attribute is 4", i.getLongValue() == 4, "test_classad 11", results); success = basic.delete("new"); test("Delete claims to have worked", (success == true), "test_classad 12", results); haveAttribute = basic.evaluateAttrInt("new", i); test("New attribute was deleted", (haveAttribute == false), "test_classad 13", results); success = basic.delete("G"); test("DELETE claims to have worked", (success == true), "test_classad 14", results); haveAttribute = basic.evaluateAttrString("G", s); test("Attribute G was deleted", (haveAttribute == false), "test_classad 15", results); basic = null; /* ----- Test GetExternalReferences ----- */ String inputRef = "[ Rank=Member(\"LCG-2_1_0\",other.Environment) ? other.Time/seconds : other.Time/minutes; minutes=60; ]"; TreeSet<String> refs = new TreeSet<String>(); ExprTree rank; c = parser.parseClassAd(inputRef); test("Made classad_ref", (c != null), "Test GetExternalReferences 1", results); if (c != null) { rank = c.lookup("Rank"); test("Rank exists", (rank != null), "Test GetExternalReferences 2", results); if (rank != null) { boolean haveReferences; if ((haveReferences = c.getExternalReferences(rank, refs, true))) { test("have_references", (haveReferences == true), "Test GetExternalReferences 3", results); if (haveReferences) { boolean haveEnvironment; boolean haveTime; boolean haveSeconds; boolean haveOther; haveEnvironment = false; haveTime = false; haveSeconds = false; haveOther = false; for (String entry : refs) { System.out.println(entry); if (entry.compareTo("other.Environment") == 0) { haveEnvironment = true; } else if (entry.compareTo("other.Time") == 0) { haveTime = true; } else if (entry.compareTo("seconds") == 0) { haveSeconds = true; } else { haveOther = true; } } test("Have external reference to Environment", (haveEnvironment == true), "Test GetExternalReferences 4", results); test("Have external reference to Time", (haveTime == true), "Test GetExternalReferences 5", results); test("Have external reference to seconds", (haveSeconds == true), "Test GetExternalReferences 6", results); test("Have no other external references", (haveOther != true), "Test GetExternalReferences 7", results); } } } c = null; } // This ClassAd may cause problems. Perhaps a memory leak. // This test is only useful when run under valgrind. String memoryProblemClassad = "[ Updates = [status = \"request_completed\"; timestamp = absTime(\"2004-12-16T18:10:59-0600]\")] ]"; c = parser.parseClassAd(memoryProblemClassad); /* ----- Test Parsing multiple ClassAds ----- */ String twoClassads = "[ a = 3; ][ b = 4; ]"; ClassAd classad1 = new ClassAd(); ClassAd classad2 = new ClassAd(); AMutableInt32 offset = new AMutableInt32(0); parser.parseClassAd(twoClassads, classad1, offset); test("Have good offset #1", offset.getIntegerValue().intValue() == 10, "Test Parsing multiple ClassAds 1", results); parser.parseClassAd(twoClassads, classad2, offset); test("Have good offset #2", offset.getIntegerValue().intValue() == 20, "Test Parsing multiple ClassAds 2", results); /* ----- Test chained ClassAds ----- */ //classad1 and classad2 from above test are used. ClassAd classad3 = new ClassAd(); classad1.chainToAd(classad2); test("classad1's parent is classad2", classad1.getChainedParentAd().equals(classad2), "Test chained ClassAds 1", results); haveAttribute = classad1.evaluateAttrInt("b", i); test("chain has attribute b from parent", (haveAttribute == true), "Test chained ClassAds 2", results); test("chain attribute b from parent is 4", (i.getLongValue() == 4), "Test chained ClassAds 3", results); haveAttribute = classad1.evaluateAttrInt("a", i); test("chain has attribute a from self", (haveAttribute == true), "Test chained ClassAds 4", results); test("chain attribute a is 3", (i.getLongValue() == 3), "Test chained ClassAds 5", results); // Now we modify classad2 (parent) to contain "a". success = classad2.insertAttr("a", 7); test("insert a into parent", (success == true), "Test chained ClassAds 6", results); haveAttribute = classad1.evaluateAttrInt("a", i); test("chain has attribute a from self (overriding parent)", (haveAttribute == true), "Test chained ClassAds 7", results); test("chain attribute a is 3 (overriding parent)", (i.getLongValue() == 3), "Test chained ClassAds 8", results); haveAttribute = classad2.evaluateAttrInt("a", i); test("chain parent has attribute a", (haveAttribute == true), "Test chained ClassAds 9", results); test("chain parent attribute a is 7", (i.getLongValue() == 7), "Test chained ClassAds 10", results); success = classad3.copyFromChain(classad1); test("copy from chain succeeded", (success == true), "Test chained ClassAds 11", results); haveAttribute = classad3.evaluateAttrInt("b", i); test("copy of chain has attribute b", (haveAttribute == true), "Test chained ClassAds 12", results); test("copy of chain has attribute b==4", (i.getLongValue() == 4), "Test chained ClassAds 13", results); success = classad3.insertAttr("c", 6); test("insert into copy of chain succeeded", (success == true), "Test chained ClassAds 14", results); classad3.copyFromChain(classad1); haveAttribute = classad3.evaluateAttrInt("c", i); test("copy of chain is clean", (haveAttribute == false), "Test chained ClassAds 15", results); classad3.insertAttr("c", 6); success = classad3.updateFromChain(classad1); test("update from chain succeeded", (success == true), "Test chained ClassAds 16", results); haveAttribute = classad3.evaluateAttrInt("c", i); test("update from chain is merged", (haveAttribute == true), "Test chained ClassAds 17", results); test("update from chain has attribute c==6", (i.getLongValue() == 6), "Test chained ClassAds 18", results); }
From source file:asterix.parser.classad.Value.java
public static boolean convertValueToRealValue(Value value, Value realValue) throws HyracksDataException { boolean could_convert; AMutableCharArrayString buf = new AMutableCharArrayString(); int endIndex; char end;//from w w w. j a va2 s. co m AMutableInt64 ivalue = new AMutableInt64(0); ClassAdTime atvalue = new ClassAdTime(); MutableBoolean bvalue = new MutableBoolean(); 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((double) ivalue.getLongValue()); could_convert = true; break; case REAL_VALUE: realValue.copyFrom(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: could_convert = false; // Make gcc's -Wuninitalized happy throw new HyracksDataException("Should not reach here"); } return could_convert; }
From source file:asterix.parser.classad.Value.java
public static boolean convertValueToIntegerValue(Value value, Value integerValue) throws HyracksDataException { boolean could_convert; AMutableCharArrayString buf = new AMutableCharArrayString(); char end;/* w ww . j a v a 2 s . c o m*/ AMutableInt64 ivalue = new AMutableInt64(0); AMutableDouble rtvalue = new AMutableDouble(0); ClassAdTime atvalue = new ClassAdTime(); MutableBoolean bvalue = new MutableBoolean(); 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.fistNonDigitChar(); 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.copyFrom(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: could_convert = false; // Make gcc's -Wuninitalized happy throw new HyracksDataException("Should not reach here"); } return could_convert; }
From source file:asterix.parser.classad.Operation.java
public boolean shortCircuit(EvalState state, Value arg1, Value result) throws HyracksDataException { MutableBoolean arg1_bool = new MutableBoolean(); switch (opKind) { case OpKind_LOGICAL_OR_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && arg1_bool.booleanValue()) { result.setBooleanValue(true); return true; }//from w w w . j a v a2s .com break; case OpKind_LOGICAL_AND_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && !arg1_bool.booleanValue()) { result.setBooleanValue(false); return true; } break; case OpKind_TERNARY_OP: if (arg1.isBooleanValueEquiv(arg1_bool)) { if (arg1_bool.booleanValue()) { if (child2 != null) { return child2.publicEvaluate(state, result); } } else { if (child3 != null) { return child3.publicEvaluate(state, result); } } } break; default: // no-op break; } return false; }
From source file:asterix.parser.classad.test.ClassAdUnitTester.java
/********************************************************************* * Function: test_exprlist/*from w w w .jav a2 s .c om*/ * Purpose: Test the ExprList class. * * @throws IOException *********************************************************************/ public static void testExprList(Parameters parameters, Results results) throws IOException { System.out.println("Testing the ExprList class..."); Literal literal10; Literal literal20; Literal literal21; List<ExprTree> vector1 = new ArrayList<ExprTree>(); List<ExprTree> vector2 = new ArrayList<ExprTree>(); ExprList list0; ExprList list0Copy; ExprList list1; ExprList list1Copy; ExprList list2; ExprList list2Copy; /* ----- Setup Literals, the vectors, then ExprLists ----- */ literal10 = Literal.createReal("1.0"); literal20 = Literal.createReal("2.0"); literal21 = Literal.createReal("2.1"); vector1.add(literal10); vector2.add(literal20); vector2.add(literal21); list0 = new ExprList(); list1 = new ExprList(vector1); list2 = new ExprList(vector2); /* ----- Did the lists get made? ----- */ test("Made list 0", (list0 != null), "Did the lists get made? 0", results); test("Made list 1", (list1 != null), "Did the lists get made? 1", results); test("Made list 2", (list2 != null), "Did the lists get made? 2", results); /* ----- Are these lists identical to themselves? ----- */ test("ExprList identical 0", list0.sameAs(list0), "Are these lists identical to themselves? 0", results); test("ExprList identical 1", list1.sameAs(list1), "Are these lists identical to themselves? 1", results); test("ExprList identical 2", list2.sameAs(list2), "Are these lists identical to themselves? 2", results); /* ----- Are they different from each other? ----- */ test("ExprLists different 0-1", !(list0.sameAs(list1)), "Are these lists different from each other? 0", results); test("ExprLists different 1-2", !(list1.sameAs(list2)), "Are these lists identical from each other? 1", results); test("ExprLists different 0-2", !(list0.sameAs(list2)), "Are these lists identical from each other? 2", results); /* ----- Check the size of the ExprLists to make sure they are ok ----- */ test("ExprList size 0", (list0.size() == 0), "check list size? 0", results); test("ExprList size 1", (list1.size() == 1), "check list size? 1", results); test("ExprList size 2", (list2.size() == 2), "check list size? 2", results); /* ----- Make copies of the ExprLists ----- */ list0Copy = (ExprList) list0.copy(); list1Copy = (ExprList) list1.copy(); list2Copy = (ExprList) list2.copy(); /* ----- Did the copies get made? ----- */ test("Made copy of list 0", (list0Copy != null), "Did the copies get made? 0", results); test("Made copy of list 1", (list1Copy != null), "Did the copies get made? 1", results); test("Made copy of list 2", (list2Copy != null), "Did the copies get made? 2", results); /* ----- Are they identical to the originals? ----- */ test("ExprList self-identity 0", (list0.sameAs(list0Copy)), "Are they identical to the originals? 0", results); test("ExprList self-identity 1", (list1.sameAs(list1Copy)), "Are they identical to the originals? 1", results); test("ExprList self-identity 2", (list2.sameAs(list2Copy)), "Are they identical to the originals? 2", results); /* ----- Test adding and deleting from a list ----- */ Literal add; add = Literal.createReal("2.2"); if (list2Copy != null) { list2Copy.insert(add); test("Edited list is different", !(list2.sameAs(list2Copy)), "Test adding and deleting from a list 0", results); list2Copy.erase(list2Copy.size() - 1); test("Twice Edited list is same", (list2.sameAs(list2Copy)), "Test adding and deleting from a list 1", results); } // Note that we do not delete the Literals that we created, because // they should have been deleted when the list was deleted. /* ----- Test an ExprList bug that Nate Mueller found ----- */ ClassAd classad; ClassAdParser parser = new ClassAdParser(); MutableBoolean b = new MutableBoolean(); boolean haveAttribute; boolean canEvaluate; Value value = new Value(); String listClassadText = "[foo = 3; have_foo = member(foo, {1, 2, 3});]"; classad = parser.parseClassAd(listClassadText); haveAttribute = classad.evaluateAttrBool("have_foo", b); test("Can evaluate list in member function", (haveAttribute == true && b.booleanValue() == true), "Test an ExprList bug that Nate Mueller found 0", results); canEvaluate = classad.evaluateExpr("member(foo, {1, 2, blah, 3})", value); test("Can evaluate list in member() outside of ClassAd", canEvaluate == true, "Test an ExprList bug that Nate Mueller found 1", results); return; }