Last active
August 29, 2015 14:07
-
-
Save up1/bb288d1e52945cba7220 to your computer and use it in GitHub Desktop.
Conditional Branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Data { | |
public String format(List<String> datas) { | |
StringBuilder result = new StringBuilder(); | |
boolean first = true; | |
for(String data : datas) { | |
if(first) { | |
first = false; | |
} else { | |
result.append(", "); | |
} | |
result.append(data); | |
} | |
return result.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee { | |
private int _type; | |
static final int ENGINEER = 0; | |
static final int SALESMAN = 1; | |
static final int MANAGER = 2; | |
Employee (int type) { | |
_type = type; | |
} | |
int payAmount() { | |
switch (_type) { | |
case ENGINEER: | |
return _monthlySalary; | |
case SALESMAN: | |
return _monthlySalary + _commission; | |
case MANAGER: | |
return _monthlySalary + _bonus; | |
default: | |
throw new RuntimeException("Incorrect Employee"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example2 { | |
public void create(boolean flag) { | |
if(flag) { | |
//TODO | |
} else { | |
//TODO | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserDAO { | |
public void create() { | |
if( data not found ) { | |
throw new DataNotFoundException(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserService { | |
public void createNewUser() { | |
User user = userDao.create(); | |
if(user != null) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment