ternary

XSLT 1.0 Idiom for ternary if?

﹥>﹥吖頭↗ 提交于 2019-12-01 16:11:57
This Java program makes use of a Ternary if, to map booleans to output strings: (a "*" for true, an empty string for false). public class ternary { public static void main(String[] args) { boolean flags[]={true,false,true}; for (boolean f : flags) { System.out.println(f?"*":""); } } } So the output is *, [empty], *. I have an input XML document, something like: <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="change.xsl"?> <root> <change flag="true"/> <change flag="false"/> <change flag="true"/> </root> And I have the following XSLT template which maps true to '*' and false to ''

XSLT 1.0 Idiom for ternary if?

不想你离开。 提交于 2019-12-01 16:05:09
问题 This Java program makes use of a Ternary if, to map booleans to output strings: (a "*" for true, an empty string for false). public class ternary { public static void main(String[] args) { boolean flags[]={true,false,true}; for (boolean f : flags) { System.out.println(f?"*":""); } } } So the output is *, [empty], *. I have an input XML document, something like: <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="change.xsl"?> <root> <change flag="true"/> <change flag="false"/>

Java return null for primitive in ternary [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-01 09:06:23
This question already has an answer here: Returning null as an int permitted with ternary operator but not if statement 8 answers The following (logically) is a compile-time error: public int myMethod(MyObject input) { if (input == null) { return null; // compiler says I cannot return null for primitive type } else { return 1; } } So far so good. What I don't understand, that the following is allowed: public int myMethod(MyObject input) { return input == null ? null : 1; } Why? Recognising this should be straightforward for the compiler, or do I miss some crucial point here? (And of course if

Construct ternary grid, evaluate a function on the grid and contour plot in Matlab

你说的曾经没有我的故事 提交于 2019-12-01 01:36:42
I need to evaluate a function (say) Fxy = 2*x.^2 +3 *y.^2; on a ternary grid x-range (0 - 1), y-range (0-1) and 1-x-y (0 - 1). I am unable to construct the ternary grid on which I need to evaluate the above function. Also, once evaluated I need to plot the function in a ternary contour plot. Ideally, I need the axes to go counter clockwise in the sense (x -> y--> (1-x-y)). I have tried the function function tg = triangle_grid ( n, t ) ng = ( ( n + 1 ) * ( n + 2 ) ) / 2; tg = zeros ( 2, ng ); p = 0; for i = 0 : n for j = 0 : n - i k = n - i - j; p = p + 1; tg(1:2,p) = ( i * t(1:2,1) + j * t(1:2

Javascript Ternary operator with empty else

跟風遠走 提交于 2019-12-01 01:08:51
I'm trying to convert the following if-else to it's ternary operator representation in javascript as follows var x = 2; if (x === 2) {alert("2");} else { //do nothing} But when I do this: (t==2)?(alert("1")):(); Chrome throws a SyntaxError. My question is - How to have a ternary operator in javascript with an empty "else" branch - i.e the part that comes after ":". Also, is this allowed- using a ternary operator in javascript to execute statements - NOT do assignment. Also: the above code was just a base case. I'm actually trying to get all the DOM elements of the page as an array (called all2

String concatenation does not work properly in Java when concatenating 2 results of ternary operators

我是研究僧i 提交于 2019-11-30 23:29:26
Dear Java guru 's! Can you, please, explain me, why String concatenation does not work properly in Java when concatenating 2 results of ternary operators? Example: String str = null; String x = str != null ? "A" : "B" + str == null ? "C" : "D"; System.out.println(x); Output is "D", but I expected "BC". I am suspecting that it works like so because of operators priorities, but I am not sure, about how we exactly we get "D" for case above. What calculation algorithm takes place for this case? It's interpreted as following code: String x = str != null ? "A" : ("B" + str == null ? "C" : "D"); "B"

UML ternary association

北城余情 提交于 2019-11-30 18:44:10
I'm currently having some trouble understanding ternary associations in UML. I get the binary ones, but I am unsure how to multiplicity works on ternary. I'm doing exercises that I got from my university, the current one goes like this: One department may sell many products, but only to one market. On a market one product may only be sold by one department. I've read on different sources about how I'm supposed to think about a pair of the two classes I'm not trying to figure out the multiplicity for, but my brain just isn't getting it. Help me Overflow Kenobi, you're my only hope. There seems

Using statements on either side of a python ternary conditional

て烟熏妆下的殇ゞ 提交于 2019-11-30 09:05:15
Why is it prohibited to use statements on either side of python's ternary conditional? I can't see any obvious reason how a few of the following naive syntax examples could be ambiguous or broken - but I'm sure there must be a good reason why it's disallowed! >>> x, y = 0, 0 >>> (x += 1) if random.choice([0, 1]) else (y += 1) ^ SyntaxError: invalid syntax >>> (x if random.choice([0, 1]) else y) += 1 SyntaxError: can't assign to conditional expression >>> print 'hello world' if random.choice([0, 1]) else raise StandardError() File "<stdin>", line 1 print 'hello world' if random.choice([0, 1])

How to write ternary operator condition in jQuery?

北城余情 提交于 2019-11-30 05:41:59
In this fiddle http://jsfiddle.net/mjmitche/6nar4/3/ , if you drag, for example, the little blue box into the yellow box, then the big black box will turn pink. All of the 4 boxes along the left can be dragged into the boxes inside the black box. At the end of the fiddle, you see the code that changes the black box to pink. However, I want to make that a ternary operator, so that if the box is black, then it turns pink, but if it's been turned pink, then I want it to go back to black. I know the ternary is like this x ? y: z So I tried this, even though I knew it wasn't probably right $("

Using statements on either side of a python ternary conditional

拜拜、爱过 提交于 2019-11-29 12:44:31
问题 Why is it prohibited to use statements on either side of python's ternary conditional? I can't see any obvious reason how a few of the following naive syntax examples could be ambiguous or broken - but I'm sure there must be a good reason why it's disallowed! >>> x, y = 0, 0 >>> (x += 1) if random.choice([0, 1]) else (y += 1) ^ SyntaxError: invalid syntax >>> (x if random.choice([0, 1]) else y) += 1 SyntaxError: can't assign to conditional expression >>> print 'hello world' if random.choice(