Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 27 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
# Jetbrains IntelliJ Idea
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml

# Linux
# backup files
*~

# Windows
# thumbnails
Thumbs.db

# Mac OS X
# metadata
.DS_Store
# thumbnails
._*

# GIT
.git/

# Java
*.class

# packages
*.jar
*.war
*.ear

# Logging
*.log

# jME (binaries)
*.so
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

### VS Code ###
.vscode/
6 changes: 6 additions & 0 deletions src/main/java/com/shoon/javacountries/CheckCountry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.shoon.javacountries;

public interface CheckCountry {

boolean test(Country e);
}
59 changes: 59 additions & 0 deletions src/main/java/com/shoon/javacountries/Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.shoon.javacountries;

import java.util.concurrent.atomic.AtomicInteger;

public class Country {
private static final AtomicInteger iCounter = new AtomicInteger();
private int iID;
private String strName;
private int iPopulation;

private int iSize;
private int iMedianAge;

public Country(String strName, int iPopulation, int iSize, int iMedianAge) {
this.iID = iCounter.incrementAndGet();
this.strName = strName;
this.iPopulation = iPopulation;
this.iSize = iSize;
this.iMedianAge = iMedianAge;
}

public int getID() {
return iID;
}



public String getName() {
return strName;
}

public void setName(String strName) {
this.strName = strName;
}

public int getPopulation() {
return iPopulation;
}

public void setPopulation(int iPopulation) {
this.iPopulation = iPopulation;
}

public int getSize() {
return iSize;
}

public void setSize(int iSize) {
this.iSize = iSize;
}

public int getMedianAge() {
return iMedianAge;
}

public void setMedianAge(int iMedianAge) {
this.iMedianAge = iMedianAge;
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/shoon/javacountries/CountryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.shoon.javacountries;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("/data")
public class CountryController
{
//localhost:8080/data/allCountries
@RequestMapping(value = "/allCountries",
produces = {"application/json"})
public ResponseEntity<?> getAllCountrys()
{
JavaCountriesApplication.countryList.countryList.sort((e1, e2) -> e1.getName().compareToIgnoreCase(e2.getName()));
return new ResponseEntity<>(JavaCountriesApplication.countryList.countryList, HttpStatus.OK);
}


// the web way
// localhost:8080/data/Country?id=2
@RequestMapping(value = "/Country",
method = RequestMethod.GET,
produces = {"application/json"})
public ResponseEntity<?> getCountryDetail(
@RequestParam("id")
long id)
{
Country rtnCountry = JavaCountriesApplication.countryList.findCountry(e -> (e.getID() == id));
return new ResponseEntity<>(rtnCountry, HttpStatus.OK);
}


// the restful way
// localhost:8080/data/Country/2
@GetMapping(value = "/Country/{id}",
produces = {"application/json"})
public ResponseEntity<?> getEmpDetail(
@PathVariable
long id)
{
Country rtnCountry = JavaCountriesApplication.countryList.findCountry(e -> (e.getID() == id));
return new ResponseEntity<>(rtnCountry , HttpStatus.OK);
}

// localhost:8080/data/Countrys/s
@GetMapping(value = "/Countrys/{letter}",
produces = {"application/json"})
public ResponseEntity<?> getCountrys(
@PathVariable
char letter)
{
ArrayList<Country> rtnEmps = JavaCountriesApplication.countryList.
findCountrys(e -> e.getName().toUpperCase().charAt(0) == Character.toUpperCase(letter));
return new ResponseEntity<>(rtnEmps, HttpStatus.OK);
}


}
Loading