-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrencyManipulatorFactory.java
More file actions
39 lines (27 loc) · 1.49 KB
/
CurrencyManipulatorFactory.java
File metadata and controls
39 lines (27 loc) · 1.49 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
package com.javarush.task.task26.task2613;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class CurrencyManipulatorFactory {
private static CurrencyManipulatorFactory currencyManipulatorFactory;
private static Map<String, CurrencyManipulator> map = new HashMap<>();
private CurrencyManipulatorFactory() {
}
public static CurrencyManipulatorFactory getCurrencyManipulatorFactory() {
if (currencyManipulatorFactory == null) currencyManipulatorFactory = new CurrencyManipulatorFactory();
return currencyManipulatorFactory;
}
//В этом методе будем создавать нужный манипулятор, если он еще не существует, либо возвращать ранее созданный.
public static CurrencyManipulator getManipulatorByCurrencyCode(String currencyCode) {
currencyCode=currencyCode.toUpperCase();// не дложно быть чувствительно к регистру
map.putIfAbsent(currencyCode, new CurrencyManipulator(currencyCode));// если такой валюты не
// было она добавится в map
return map.get(currencyCode);
}
public static Collection<CurrencyManipulator> getAllCurrencyManipulators(){
return map.values();
}
public static boolean isCurrencyCodeExist(String currencyCode){
return map.containsKey(currencyCode);
}
}