Merge pull request #281 from ankurkaushal/master
Reformat according to google style guide
This commit is contained in:
@ -5,34 +5,37 @@ package com.iluwatar.model.view.controller;
|
||||
* Model-View-Controller is a pattern for implementing user interfaces. It divides the application
|
||||
* into three interconnected parts namely the model, the view and the controller.
|
||||
* <p>
|
||||
* The central component of MVC, the model, captures the behavior of the application in terms of its problem
|
||||
* domain, independent of the user interface. The model directly manages the data, logic and rules of the
|
||||
* application. A view can be any output representation of information, such as a chart or a diagram
|
||||
* The third part, the controller, accepts input and converts it to commands for the model or view.
|
||||
* The central component of MVC, the model, captures the behavior of the application in terms of its
|
||||
* problem domain, independent of the user interface. The model directly manages the data, logic and
|
||||
* rules of the application. A view can be any output representation of information, such as a chart
|
||||
* or a diagram The third part, the controller, accepts input and converts it to commands for the
|
||||
* model or view.
|
||||
* <p>
|
||||
* In this example we have a giant ({@link GiantModel}) with statuses for health, fatigue and nourishment. {@link GiantView}
|
||||
* can display the giant with its current status. {@link GiantController} receives input affecting the model and
|
||||
* delegates redrawing the giant to the view.
|
||||
* In this example we have a giant ({@link GiantModel}) with statuses for health, fatigue and
|
||||
* nourishment. {@link GiantView} can display the giant with its current status.
|
||||
* {@link GiantController} receives input affecting the model and delegates redrawing the giant to
|
||||
* the view.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main( String[] args ) {
|
||||
// create model, view and controller
|
||||
GiantModel giant = new GiantModel(Health.HEALTHY, Fatigue.ALERT, Nourishment.SATURATED);
|
||||
GiantView view = new GiantView();
|
||||
GiantController controller = new GiantController(giant, view);
|
||||
// initial display
|
||||
controller.updateView();
|
||||
// controller receives some interactions that affect the giant
|
||||
controller.setHealth(Health.WOUNDED);
|
||||
controller.setNourishment(Nourishment.HUNGRY);
|
||||
controller.setFatigue(Fatigue.TIRED);
|
||||
// redisplay
|
||||
controller.updateView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// create model, view and controller
|
||||
GiantModel giant = new GiantModel(Health.HEALTHY, Fatigue.ALERT, Nourishment.SATURATED);
|
||||
GiantView view = new GiantView();
|
||||
GiantController controller = new GiantController(giant, view);
|
||||
// initial display
|
||||
controller.updateView();
|
||||
// controller receives some interactions that affect the giant
|
||||
controller.setHealth(Health.WOUNDED);
|
||||
controller.setNourishment(Nourishment.HUNGRY);
|
||||
controller.setFatigue(Fatigue.TIRED);
|
||||
// redisplay
|
||||
controller.updateView();
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,16 @@ package com.iluwatar.model.view.controller;
|
||||
*/
|
||||
public enum Fatigue {
|
||||
|
||||
ALERT("alert"), TIRED("tired"), SLEEPING("sleeping");
|
||||
|
||||
private String title;
|
||||
|
||||
Fatigue(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
ALERT("alert"), TIRED("tired"), SLEEPING("sleeping");
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
private String title;
|
||||
|
||||
Fatigue(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -7,39 +7,39 @@ package com.iluwatar.model.view.controller;
|
||||
*/
|
||||
public class GiantController {
|
||||
|
||||
private GiantModel giant;
|
||||
private GiantView view;
|
||||
private GiantModel giant;
|
||||
private GiantView view;
|
||||
|
||||
public GiantController(GiantModel giant, GiantView view) {
|
||||
this.giant = giant;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public Health getHealth() {
|
||||
return giant.getHealth();
|
||||
}
|
||||
public GiantController(GiantModel giant, GiantView view) {
|
||||
this.giant = giant;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void setHealth(Health health) {
|
||||
this.giant.setHealth(health);
|
||||
}
|
||||
public Health getHealth() {
|
||||
return giant.getHealth();
|
||||
}
|
||||
|
||||
public Fatigue getFatigue() {
|
||||
return giant.getFatigue();
|
||||
}
|
||||
public void setHealth(Health health) {
|
||||
this.giant.setHealth(health);
|
||||
}
|
||||
|
||||
public void setFatigue(Fatigue fatigue) {
|
||||
this.giant.setFatigue(fatigue);
|
||||
}
|
||||
public Fatigue getFatigue() {
|
||||
return giant.getFatigue();
|
||||
}
|
||||
|
||||
public Nourishment getNourishment() {
|
||||
return giant.getNourishment();
|
||||
}
|
||||
public void setFatigue(Fatigue fatigue) {
|
||||
this.giant.setFatigue(fatigue);
|
||||
}
|
||||
|
||||
public void setNourishment(Nourishment nourishment) {
|
||||
this.giant.setNourishment(nourishment);
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
this.view.displayGiant(giant);
|
||||
}
|
||||
public Nourishment getNourishment() {
|
||||
return giant.getNourishment();
|
||||
}
|
||||
|
||||
public void setNourishment(Nourishment nourishment) {
|
||||
this.giant.setNourishment(nourishment);
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
this.view.displayGiant(giant);
|
||||
}
|
||||
}
|
||||
|
@ -6,43 +6,43 @@ package com.iluwatar.model.view.controller;
|
||||
*
|
||||
*/
|
||||
public class GiantModel {
|
||||
|
||||
private Health health;
|
||||
private Fatigue fatigue;
|
||||
private Nourishment nourishment;
|
||||
|
||||
GiantModel(Health health, Fatigue fatigue, Nourishment nourishment) {
|
||||
this.health = health;
|
||||
this.fatigue = fatigue;
|
||||
this.nourishment = nourishment;
|
||||
}
|
||||
private Health health;
|
||||
private Fatigue fatigue;
|
||||
private Nourishment nourishment;
|
||||
|
||||
public Health getHealth() {
|
||||
return health;
|
||||
}
|
||||
GiantModel(Health health, Fatigue fatigue, Nourishment nourishment) {
|
||||
this.health = health;
|
||||
this.fatigue = fatigue;
|
||||
this.nourishment = nourishment;
|
||||
}
|
||||
|
||||
public void setHealth(Health health) {
|
||||
this.health = health;
|
||||
}
|
||||
public Health getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public Fatigue getFatigue() {
|
||||
return fatigue;
|
||||
}
|
||||
public void setHealth(Health health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public void setFatigue(Fatigue fatigue) {
|
||||
this.fatigue = fatigue;
|
||||
}
|
||||
public Fatigue getFatigue() {
|
||||
return fatigue;
|
||||
}
|
||||
|
||||
public Nourishment getNourishment() {
|
||||
return nourishment;
|
||||
}
|
||||
public void setFatigue(Fatigue fatigue) {
|
||||
this.fatigue = fatigue;
|
||||
}
|
||||
|
||||
public void setNourishment(Nourishment nourishment) {
|
||||
this.nourishment = nourishment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("The giant looks %s, %s and %s.", health, fatigue, nourishment);
|
||||
}
|
||||
public Nourishment getNourishment() {
|
||||
return nourishment;
|
||||
}
|
||||
|
||||
public void setNourishment(Nourishment nourishment) {
|
||||
this.nourishment = nourishment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("The giant looks %s, %s and %s.", health, fatigue, nourishment);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package com.iluwatar.model.view.controller;
|
||||
*/
|
||||
public class GiantView {
|
||||
|
||||
public void displayGiant(GiantModel giant) {
|
||||
System.out.println(giant);
|
||||
}
|
||||
public void displayGiant(GiantModel giant) {
|
||||
System.out.println(giant);
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ package com.iluwatar.model.view.controller;
|
||||
*
|
||||
*/
|
||||
public enum Health {
|
||||
|
||||
HEALTHY("healthy"), WOUNDED("wounded"), DEAD("dead");
|
||||
|
||||
private String title;
|
||||
|
||||
Health(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
HEALTHY("healthy"), WOUNDED("wounded"), DEAD("dead");
|
||||
|
||||
private String title;
|
||||
|
||||
Health(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,16 @@ package com.iluwatar.model.view.controller;
|
||||
*/
|
||||
public enum Nourishment {
|
||||
|
||||
SATURATED("saturated"), HUNGRY("hungry"), STARVING("starving");
|
||||
|
||||
private String title;
|
||||
|
||||
Nourishment(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
SATURATED("saturated"), HUNGRY("hungry"), STARVING("starving");
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
private String title;
|
||||
|
||||
Nourishment(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import com.iluwatar.model.view.controller.App;
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user