-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCountryService.java
More file actions
59 lines (46 loc) · 1.39 KB
/
CountryService.java
File metadata and controls
59 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.vishal.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.vishal.bean.Country;
public class CountryService {
static HashMap<Integer, Country> countryIdmap= getCountry();
private static HashMap<Integer, Country> getCountry(){
return countryIdmap;
}
public CountryService(){
super();
if(countryIdmap==null){
countryIdmap=new HashMap<Integer, Country>();
countryIdmap.put(1,new Country(01, "India", 2018));
countryIdmap.put(2,new Country(02, "America", 12345));
countryIdmap.put(3,new Country(03, "Australia", 76421));
countryIdmap.put(4,new Country(04, "London", 98765));
countryIdmap.put(5,new Country(05, "Japan", 5678));
}
}
public List<Country> getAllCountries(){
List<Country> countries=new ArrayList<Country>(countryIdmap.values());
return countries;
}
public Country getCountry(int id){
Country country=countryIdmap.get(id);
return country;
}
public Country addCountry(Country country){
country.setId(countryIdmap.size()+1);
countryIdmap.put(country.getId(), country);
return country;
}
public Country updateCountry(Country country){
if(country.getId()<0)
return null;
else{
countryIdmap.put(country.getId(), country);
return country;
}
}
public void deleteCountry(int id){
countryIdmap.remove(id);
}
}