Re: [java:Conditional Operators]

2006-03-31 Thread Martin Gainty
Agreed..I like to simplify the situation to make it maintainable-
Thanks,
Martin-
- Original Message - 
From: Slattery, Tim - BLS [EMAIL PROTECTED]
To: Struts Users Mailing List user@struts.apache.org
Sent: Thursday, March 30, 2006 3:52 PM
Subject: RE: [java:Conditional Operators]


 I did not understand the following code with multiple 
 conditional operators.
   boolean vIsForm=true;
   String vForwardName = 
 (aActionMapping.findForward(vWorkForwardName) == null)
   ? (vIsForm) ? form : task
   : vWorkForwardName;
   
   Can some body explain me how to read the above code?
   Thanks  Regards

Nasty, nasty. Very terse, but nearly unreadable. Better to untangle it
somewhat and make the code more understantable. I believe it works out
like this:


If (aActionMapping.findForward(vWorkForwardName) == null)
{
   if (vIsForm)
   {
  vForwardName = form;
}
   else
   {
vForwardName = task;
   }
}
else
{
 vForwardName = vWorkForwardName;
}


-
Tim Slattery
[EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [java:Conditional Operators]

2006-03-30 Thread Slattery, Tim - BLS
 I did not understand the following code with multiple 
 conditional operators.
   boolean vIsForm=true;
   String vForwardName = 
 (aActionMapping.findForward(vWorkForwardName) == null)
   ? (vIsForm) ? form : task
   : vWorkForwardName;
   
   Can some body explain me how to read the above code?
   Thanks  Regards

Nasty, nasty. Very terse, but nearly unreadable. Better to untangle it
somewhat and make the code more understantable. I believe it works out
like this:


If (aActionMapping.findForward(vWorkForwardName) == null)
{
   if (vIsForm)
   {
  vForwardName = form;
}
   else
   {
vForwardName = task;
   }
}
else
{
 vForwardName = vWorkForwardName;
}


-
Tim Slattery
[EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [java:Conditional Operators]

2006-03-30 Thread Michael Jouravlev
On 3/30/06, temp temp [EMAIL PROTECTED] wrote:
 I did not understand the following code with multiple conditional operators.
   boolean vIsForm=true;
   String vForwardName = (aActionMapping.findForward(vWorkForwardName) 
 == null)
   ? (vIsForm) ? form : task
   : vWorkForwardName;

   Can some body explain me how to read the above code?

Reformat it like this:

boolean vIsForm=true;
String vForwardName =
(aActionMapping.findForward(vWorkForwardName) == null)
? (vIsForm)
? form
: task
: vWorkForwardName;

or even like this:

boolean vIsForm=true;
String vForwardName =
(aActionMapping.findForward(vWorkForwardName) != null)
? vWorkForwardName
: (vIsForm)
? form
: task

Does it look simpler?

vIsForm does not seem to be changed in this snippet, so you can
simplify the above double ternary operation down to single ternary
operation:

String vForwardName =
(aActionMapping.findForward(vWorkForwardName) == null)
? form
: vWorkForwardName;

Michael.

Java Language Specification, PDF: http://java.sun.com/docs/books/jls/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [java:Conditional Operators]

2006-03-30 Thread Martin Gainty

its a ternary operator e.g. boolean-exp ? value0 : value1

if vIsForm is NOT NULL then vIsForm is form
else  vIsForm is Task

if the result of (aActionMapping.findForward(vWorkForwardName) == null)
then assign vForwardName to vIsForm(from above)
else assign vForwardName to value of variable vWorkForwardName

Nez pas?
Martin--
- Original Message - 
From: temp temp [EMAIL PROTECTED]

To: user@struts.apache.org
Sent: Thursday, March 30, 2006 3:46 PM
Subject: [java:Conditional Operators]


I did not understand the following code with multiple conditional 
operators.

 boolean vIsForm=true;
 String vForwardName = 
(aActionMapping.findForward(vWorkForwardName) == null)

 ? (vIsForm) ? form : task
 : vWorkForwardName;

 Can some body explain me how to read the above code?
 Thanks  Regards



-
New Yahoo! Messenger with Voice. Call regular phones from your PC and save 
big. 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]