@Test
public void moreTernary(){
String url = "www.eviltester.com";
url = url.startsWith("http") ? url : addHttp(url);
assertTrue(url.startsWith("http://"));
assertEquals("http://www.eviltester.com", url);
}
private String addHttp(String url) { <------------- funkce addHttp
return "http://" + url; <------ co ta fukne dela s promenou, prida k ni https
//url = url.startsWith("http") ? url : addHttp(url);
url = url.startsWith("http") ? url : "http://" + url; <--- tak si to klidne napis takto
if (url.startsWith("http")) <--- nebo takto s ifem
{
url = url;
}
else
{
// url = addHttp(url);
url = "http://" + url
}
Ten zapis je stejny. If je jen vyhodnejsi pro vic akci najednou.
Ten zapis druhy zapis, podminka ? value_true : value_false, by mel casove byt rychlejsi a take se setri misto a pismenka kodu. Vetsinou je lepe citelny. Ale, to zalezi na tom, jak slozite za napise. Ja treba v jednom html/js/css programu pouzivam
function cmp(a,b) { return a==b ? 0 : a<b ? -1 : 1; }
c[3] = c[1]==0 ? c[2] : (c[2]==0 ? -c[1] : cmp(arr[n][i+2],arr[n][i+3]));
---
Tohle cele napsat html/js ifami (v jave se to mozna da elegantneji,
nevim, neprogramuji v jave), tak se zcvoknes :) Asi.
function cmp(a,b) { if (a==b) {return 0;} if (a<b) {return -1;} return 1; }
if (c[1]==0} {c[3] = c[2];}
else { if (c[2]==0) {c[3] = -c[1];}
else {c[3] = cmp(arr[n][i+2],arr[n][i+3]));} }