I try to write a condition in thymeleaf with OR - thymeleaf

I need to have a condition with logical operator OR. I try to do in this way but it seem doesn't work :
<div th:if="${(fingerprints.totalPages != 0) or (fingerprints.totalPages != 1)}"
How I suppose to do ? :)

Both or and || work. In this case, your logic is wrong. I think your expression should be:
th:if="${(fingerprints.totalPages != 0) and (fingerprints.totalPages != 1)}"
Your original expression is always true. (Since fingerprints.totalPages is always going to be either != 1 or != 0.

Related

Process user-inputted conditions (==, &&) inside app

I have the task, and I can understand how to deal with it (in what direction I need to start). Application need to understand user-inputted condition like that:
((VAR1 != 1 && VAR2 == 2) OR (VAR3 != 1 && VAR4 == 2)) AND (VAR5 = 2)
I have that variables inside my database, so it's no problem to replace VAR1 with real data. How in what way I can process that condition inside application. I thought about separating full condition to little blocks, but I don't understand yet how to separate, there is no symbol that I can split string.
So can you help in what direction I need to start working to process such conditions in Swift app?
Thanks to #Sulthan, NSPredicate is solution.
let expressionString = "((1 == 1) or (1 == 2)) and (1 == 2)"
let predicate = NSPredicate(format: expressionString)
print(predicate.evaluateWithObject(nil))
// Output: false

Freemarker: comparing against a default value

I have this condition:
<#if tag.level?? && tag.level == "IMPORTANT">
Is it possible to shorten it to something like this?
<#if tag.level!"" == "IMPORTANT">
If I try this
<#assign tag = {"bar": "AA"} >
${ ((tag.bar)!"x") = "x" }
I get
Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false", which is the legacy default computer-language format, and hence isn't accepted.
See http://freemarker-online.kenshoo.com/
1) ${ ((tag.bar)!"x") = "x" } should be probably ${ ((tag.bar)!"x") == "x" }.
2) Use a built-in to display boolean, either ${ (((tag.bar)!"x") = "x")?c } (if your Freemarker is newer than 2.3.20), or ${ (((tag.bar)!"x") = "x")?string("true", "false") }
It's a precedence issue that you run into. This works:
<#if (tag.level!"") == "IMPORTANT">
but for this kind of default there's a shorter form:
<#if tag.level! == "IMPORTANT">

Inverse if statement

I have a question about Objective C
I want an inverted if statement. Like: if (!example.hidden == YES) {
Here's my code:
if ((randomBallTouch.x>_randomColorBall.center.x-(_randomColorBall.frame.size.width)/2) &&
(randomBallTouch.x<_randomColorBall.center.x+(_randomColorBall.frame.size.width)/2) &&
(randomBallTouch.y>_randomColorBall.center.y-(_randomColorBall.frame.size.height)/2) &&
(randomBallTouch.y<_randomColorBall.center.y+(_randomColorBall.frame.size.height)/2)) {
_randomColorBall.center = CGPointMake(randomBallTouch.x, randomBallTouch.y);
if (_randomColorBall.hidden == NO) {
_redBall.center = CGPointMake(_redBall.center.x, _redBall.center.y - 200);
}
}
But when i do: if(!(randomBallTouch.x>_randomColorBall.center.x)) etc. It does not work.
And I can't do else because that will bug with the other two if statements.
Any help?? I am using Xcode 5.1.
You can't just add an ! at the beginning to invert the condition. You need to wrap the whole expression in a set of parentheses first.
If you have:
if (a && b) {
then the inversion is:
if (!(a && b)) {
You didn't add those parentheses.
Try this, just replace your if with this one.
if(!((randomBallTouch.x > (_randomColorBall.center.x-(_randomColorBall.frame.size.width)/2)) && (randomBallTouch.x < (_randomColorBall.center.x+(_randomColorBall.frame.size.width)/2)) && (randomBallTouch.y > (_randomColorBall.center.y-(_randomColorBall.frame.size.height)/2)) &&(randomBallTouch.y < (_randomColorBall.center.y+(_randomColorBall.frame.size.height)/2)))) {
You are missing a lot of parenthesis to make your statement a valid boolean.

what would the purpose of the '!' be in a statement

I am reviewing scripts written by differenct coders and see many statement like:
((patindex('%,'+rtrim(ad.Dept)+',%', #vcP1Input) != 0) .
and I am wondering what the '!' is being used for.
! means not in this case.
So the != means not equal.
It means inequality.
Left side (patindex('%,'+rtrim(ad.Dept)+',%', #vcP1Input) is not equal to right side (0)
!= is the negation of ==
for example
if(obj == null)
{
// do stuff1
}
else
{
// do stuff2
}
is the same like
if(obj != null)
{
// do stuff2
}
else
{
// do stuff1
}
In TSQL, != means not equal to.
Your expression
((PATINDEX('%,' + RTRIM(ad.Dept)+',%', #vcP1Input) != 0)
is true if it can find the the trimmed value of ad.Dept in the string #vcP1Input, that is if PATINDEX returns anything else than 0.

Lua = operator as print

In Lua, using the = operator without an l-value seems to be equivalent to a print(r-value), here are a few examples run in the Lua standalone interpreter:
> = a
nil
> a = 8
> = a
8
> = 'hello'
hello
> = print
function: 003657C8
And so on...
My question is : where can I find a detailed description of this use for the = operator? How does it work? Is it by implying a special default l-value? I guess the root of my problem is that I have no clue what to type in Google to find info about it :-)
edit:
Thanks for the answers, you are right it's a feature of the interpreter. Silly question, for I don't know which reason I completely overlooked the obvious. I should avoid posting before the morning coffee :-) For completeness, here is the code dealing with this in the interpreter:
while ((status = loadline(L)) != -1) {
if (status == 0) status = docall(L, 0, 0);
report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print");
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
l_message(progname, lua_pushfstring(L,
"error calling " LUA_QL("print") " (%s)",
lua_tostring(L, -1)));
}
}
edit2:
To be really complete, the whole trick about pushing values on the stack is in the "pushline" function:
if (firstline && b[0] == '=') /* first line starts with `=' ? */
lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
Quoting the man page:
In interactive mode ... If a line starts with '=', then lua displays the values of all the expressions in the remainder of the line. The expressions must be separated by commas.
I think that must be a feature of the stand alone interpreter. I can't make that work on anything I have compiled lua into.
I wouldn't call it a feature - the interpreter just returns the result of the statement. It's his job, isn't it?
Assignment isn't an expression that returns something in Lua like it is in C.

Resources