List of usage examples for org.apache.commons.lang3.mutable MutableBoolean booleanValue
public boolean booleanValue()
From source file:asterix.parser.classad.test.ClassAdUnitTester.java
/********************************************************************* * Function: test_exprlist// w w w . ja v a 2 s . co m * 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; }
From source file:asterix.parser.classad.test.ClassAdUnitTester.java
/********************************************************************* * Function: test_value//w ww . j a v a 2 s .c o m * Purpose: Test the Value class. * * @throws HyracksDataException *********************************************************************/ public static void testValue(Parameters parameters, Results results) throws HyracksDataException { Value v = new Value(); boolean isExpectedType; System.out.println("Testing the Value class..."); test("New value is undefined", (v.isUndefinedValue()), "test_value 1", results); test("New value isn't boolean", !(v.isBooleanValue()), "test_value 2", results); test("GetType gives UNDEFINED_VALUE", (v.getType() == ValueType.UNDEFINED_VALUE), "test_value 3", results); v.setErrorValue(); test("Is error value", (v.isErrorValue()), "test_value 4", results); test("GetType gives ERROR_VALUE", (v.getType() == ValueType.ERROR_VALUE), "test_value 5", results); MutableBoolean b = new MutableBoolean(); v.setBooleanValue(true); isExpectedType = v.isBooleanValue(b); test("Value is not undefined", !(v.isUndefinedValue()), "Value is not undefined", results); test("Value is boolean", (v.isBooleanValue()), "Value is boolean", results); test("Try 2: New value is boolean", (isExpectedType == true), "Try 2: New value is boolean", results); test("Boolean is true", (b.booleanValue() == true), "Boolean is true", results); test("GetType gives BOOLEAN_VALUE", (v.getType() == ValueType.BOOLEAN_VALUE), "GetType gives BOOLEAN_VALUE", results); AMutableDouble r = new AMutableDouble(0.0); v.setRealValue(1.0); isExpectedType = v.isRealValue(r); test("Value is real", isExpectedType, results); test("Real is 1.0", (r.getDoubleValue() == 1.0), results); test("GetType gives REAL_VALUE", (v.getType() == ValueType.REAL_VALUE), results); test("Real is a number", v.isNumber(), results); AMutableInt64 i = new AMutableInt64(0); v.setIntegerValue(1); isExpectedType = v.isIntegerValue(i); test("Value is integer", isExpectedType, results); test("Integer is 1", (i.getLongValue() == 1), results); test("GetType gives INTEGER_VALUE", (v.getType() == ValueType.INTEGER_VALUE), results); test("Integer is a number", v.isNumber(), results); AMutableCharArrayString s = new AMutableCharArrayString(); v.setStringValue("Robert-Houdin"); isExpectedType = v.isStringValue(s); test("Value is String", isExpectedType, results); test("String is 'Robert-Houdin'", (0 == s.compareTo("Robert-Houdin")), results); test("GetType gives STRING_VALUE", (v.getType() == ValueType.STRING_VALUE), results); ClassAdTime at = new ClassAdTime(10, 36000000); v.setAbsoluteTimeValue(at); at.setValue(0); at.setTimeZone(0); isExpectedType = v.isAbsoluteTimeValue(at); test("Value is absolute time", isExpectedType, results); test("Absolute time is 10, 0", (10 == at.getTime() && 36000000 == at.getOffset()), results); test("GetType gives ABSOLUTE_TIME_VALUE", (v.getType() == ValueType.ABSOLUTE_TIME_VALUE), results); ClassAdTime rt = new ClassAdTime(10, false); v.setRelativeTimeValue(10); isExpectedType = v.isRelativeTimeValue(rt); test("Value is relative time", isExpectedType, results); test("Relative time is 10", (10 == rt.getRelativeTime()), results); test("GetType gives RELATIVE_TIME_VALUE", (v.getType() == ValueType.RELATIVE_TIME_VALUE), results); ExprList l = new ExprList(); ExprList ll = new ExprList(); v.setListValue(l); isExpectedType = v.isListValue(ll); test("Value is list value", isExpectedType, results); test("List value is correct", l.equals(ll), results); test("GetType gives LIST_VALUE", (v.getType() == ValueType.LIST_VALUE), results); ExprList sl = new ExprList(true); ll = new ExprList(true); v.setListValue(sl); isExpectedType = v.isListValue(ll); test("Value is list value", isExpectedType, results); test("List value is correct", sl.equals(ll), results); test("GetType gives SLIST_VALUE", (v.getType() == ValueType.SLIST_VALUE), results); ClassAd c = new ClassAd(); c.insertAttr("test_int", 10); ClassAd cc = new ClassAd(); v.setClassAdValue(c); isExpectedType = v.isClassAdValue(cc); test("Value is ClassAd value", isExpectedType, results); test("ClassAd value is correct", c.equals(cc), results); test("GetType gives CLASSAD_VALUE", (v.getType() == ValueType.CLASSAD_VALUE), results); return; }
From source file:bwem.MapDrawer.java
private boolean processCommandVariants(String command, String attributName, MutableBoolean attribut) { if (command.equals("show " + attributName)) { attribut.setTrue();//w w w.j a va 2 s. com return true; } if (command.equals("hide " + attributName)) { attribut.setFalse(); return true; } if (command.equals(attributName)) { attribut.setValue(!attribut.booleanValue()); return true; } return false; }
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; }//from w ww . j a va 2s . com 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.ClassAdUnParser.java
/** * Unparse an expression//w ww . j a va 2 s .c o m * * @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.ClassAdUnParser.java
/** * Unparse a value/*from ww w .ja va 2s. c o m*/ * * @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:io.codis.nedis.handler.RedisResponseDecoder.java
private Long decodeLong(ByteBuf in) throws ProtocolException { byte sign = in.readByte(); final MutableLong l; boolean negative; if (sign == '-') { negative = true;// w w w. j a v a 2 s . c o m l = new MutableLong(0); } else { negative = false; l = new MutableLong(toDigit(sign)); } final MutableBoolean reachCR = new MutableBoolean(false); setReaderIndex(in, in.forEachByte(new ByteBufProcessor() { @Override public boolean process(byte value) throws Exception { if (value == '\r') { reachCR.setTrue(); return false; } else { if (value >= '0' && value <= '9') { l.setValue(l.longValue() * 10 + toDigit(value)); } else { throw new ProtocolException("Response is not ended by CRLF"); } return true; } } })); if (!reachCR.booleanValue()) { return null; } if (!in.isReadable()) { return null; } if (in.readByte() != '\n') { throw new ProtocolException("Response is not ended by CRLF"); } return negative ? -l.longValue() : l.longValue(); }
From source file:asterix.parser.classad.Value.java
public void setBooleanValue(MutableBoolean b) { valueType = ValueType.BOOLEAN_VALUE; boolVal = b.booleanValue(); }
From source file:io.codis.nedis.handler.RedisResponseDecoder.java
private String decodeString(ByteBuf in) throws ProtocolException { final StringBuilder buffer = new StringBuilder(); final MutableBoolean reachCRLF = new MutableBoolean(false); setReaderIndex(in, in.forEachByte(new ByteBufProcessor() { @Override/*from w w w .j ava 2 s.c o m*/ public boolean process(byte value) throws Exception { if (value == '\n') { if ((byte) buffer.charAt(buffer.length() - 1) != '\r') { throw new ProtocolException("Response is not ended by CRLF"); } else { buffer.setLength(buffer.length() - 1); reachCRLF.setTrue(); return false; } } else { buffer.append((char) value); return true; } } })); return reachCRLF.booleanValue() ? buffer.toString() : null; }
From source file:enumj.Enumerator.java
/** * Returns an infinite enumerator obtained by applying repeatedly the * provided unary operator./*from w w w . jav a 2 s .com*/ * <p> * The resulted enumerator returns <code>seed</code>, * <code>f(seed)</code>, <code>f(f(seed))</code> ... * </p> * * @param <E> the type of enumerated elements * @param seed the initial element * @param f state-less {@link Function} instance to apply on the previous * element to obtain the next element * @return the iterated enumerator * @exception IllegalArgumentException <code>f</code> is null. */ public static <E> Enumerator<E> iterate(E seed, UnaryOperator<E> f) { Checks.ensureNotNull(f, Messages.NULL_ENUMERATOR_GENERATOR); final Mutable<E> result = new MutableObject(seed); final MutableBoolean first = new MutableBoolean(true); return of(() -> { if (first.booleanValue()) { first.setValue(false); } else { result.setValue(f.apply(result.getValue())); } return Optional.of(result.getValue()); }); }