Advertisement
package decodejava;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Utility {
public static void main(String[] args)
{
SpelExpressionParser parser = new SpelExpressionParser();
//Arithmetic operators + - / % with SpEL
System.out.println(parser.parseRaw("'Tho' + 'mas'").getValue());
System.out.println(parser.parseRaw("12 * 4").getValue());
System.out.println(parser.parseRaw("100 - 50").getValue());
System.out.println(parser.parseRaw("10 / 2").getValue());
System.out.println(parser.parseRaw("100 % 10").getValue());
}
}
Thomas
48
50
5
0
Advertisement
package decodejava;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Utility {
public static void main(String[] args)
{
SpelExpressionParser parser = new SpelExpressionParser();
//Logical operators and(&&) or(||) not(!) with SpEL
System.out.println("true && true : " + parser.parseRaw("true and true").getValue());
System.out.println("true && false : " + parser.parseRaw("true && false").getValue());
System.out.println("false && false : " + parser.parseRaw("false and false").getValue());
System.out.println("true || false : " + parser.parseRaw("true or false").getValue());
System.out.println("true || true : " + parser.parseRaw("true || true").getValue());
System.out.println("false || false : " + parser.parseRaw("false or false").getValue());
System.out.println("! false : " + parser.parseRaw("! false").getValue());
System.out.println("! true : " + parser.parseRaw("not true").getValue());
}
}
true && true : true
true && false : false
false && false : false
true || false : true
true || true : true
false || false : false
! false : true
! true : false
package decodejava;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Utility {
public static void main(String[] args)
{
SpelExpressionParser parser = new SpelExpressionParser();
//Relational operators >,<,>=,<=,==,!= with SpEL
System.out.println("100 > 50 : " + parser.parseRaw("100 > 50").getValue());
System.out.println("200 < 100 : " + parser.parseRaw("200 < 100").getValue());
System.out.println("10 >= 10 : " + parser.parseRaw("10 >= 10").getValue());
System.out.println("20 <= 19 : " + parser.parseRaw("20 <= 19").getValue());
System.out.println("9 == 9 : " + parser.parseRaw("9 == 9").getValue());
System.out.println("Thomas == Thomas : " + parser.parseRaw("'Thomas' == 'Thomas'").getValue());
System.out.println("true != false : " + parser.parseRaw("true != false").getValue());
System.out.println("99 != 99.9 : " + parser.parseRaw("99 != 99.9").getValue());
}
}
100 > 50 : true
200 < 100 : false
10 >= 10 : true
20 <= 19 : false
9 == 9 : true
Thomas == Thomas : true
true != false : true
99 != 99.9 : true
package decodejava;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Utility {
public static void main(String[] args)
{
SpelExpressionParser parser = new SpelExpressionParser();
//Ternary operator ?: with SpEL
System.out.println("100 > 50 : " + parser.parseRaw("100 > 50 ? true:false").getValue());
System.out.println("200 < 100 : " + parser.parseRaw("200 < 100 ? true:false").getValue());
System.out.println("100 == 99.9 : " + parser.parseRaw("100 == 100 ? true:false").getValue());
System.out.println("Adam == Adam : " + parser.parseRaw("'Adam' == 'Adam' ? true:false").getValue());
System.out.println("Moon == Moons : " + parser.parseRaw("'Moon' == 'Moons' ? true:false").getValue());
//Type operator used to invoke static methods of references type String and Wrapper Classes
System.out.println(parser.parseRaw("T(String).valueOf(10)").getValue());
System.out.println(parser.parseRaw("T(Integer).parseInt(1001,2)").getValue());
System.out.println(parser.parseRaw("T(Double).parseDouble('99.9')").getValue());
System.out.println("Minimum value between 99.2 and 99.9 : " + parser.parseRaw("T(Math).min(99.2, 99.9)").getValue());
System.out.println("Maximum value between 99.2 and 99.9 : " + parser.parseRaw("T(Math).max(99.2, 99.9)").getValue());
//instanceOf operator
System.out.println("Is Hello an instance of String : " + parser.parseRaw("'Hello' instanceOf T(String)").getValue());
System.out.println("Does new String() creates an Instance of String : " + parser.parseRaw("new String() instanceOf T(String)").getValue());
System.out.println("Is 10 an object of Integer : " + parser.parseRaw("10 instanceOf T(Integer)").getValue());
System.out.println("Is 6.5 an object of Double : " + parser.parseRaw("6.5 instanceOf T(Float)").getValue());
System.out.println("Is 9.9 an object of Double : " + parser.parseRaw("9.9 instanceOf T(Double)").getValue());
}
}
100 > 50 : true
200 < 100 : false
100 == 99.9 : true
Adam == Adam : true
Moon == Moons : false
10
9
99.9
Minimum value between 99.2 and 99.9 : 99.2
Maximum value between 99.2 and 99.9 : 99.9
Is Hello an instance of String : true
Does new String() creates an Instance of String : true
Is 10 an object of Integer : true
Is 6.5 an object of Double : false
Is 9.9 an object of Double : true
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement