MapMgr

Java code posted
created at 25 Nov 07:11

Edit | Back
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
60
61
package kr.go.incheon.fire.erss.map;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MapMgr {

  private ObjectMapper mapper;

  private HashMap<String, MapInfo> dataMap;
  private List<MapInfo> listMapSearchAll;

  public MapMgr() {
    mapper = new ObjectMapper();
  }

  public MapMgr(String filePath) throws JsonParseException, JsonMappingException, IOException {
    mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);

    TypeReference<HashMap<String, MapInfo>> typeRef = new TypeReference<HashMap<String, MapInfo>>() {};
    dataMap = mapper.readValue(new File(filePath), typeRef);
  }

  public void setMapDataSearchAllPath(String filePath) throws JsonParseException, JsonMappingException, IOException {
    TypeReference<ArrayList<MapInfo>> typeRef = new TypeReference<ArrayList<MapInfo>>() {};
    listMapSearchAll = mapper.readValue(new File(filePath), typeRef);
  }

  public HashMap<String, MapInfo> getDataMap() {
    return this.dataMap;
  }

  public MapInfo getMap(String mapName) {
    if (dataMap.containsKey(mapName)) {
      return dataMap.get(mapName);
    }

    return null;
  }

  public boolean containsMap(String mapName) {
    return dataMap.containsKey(mapName) ? true : false;
  }

  public List<MapInfo> getListMapSearchALl() {
    List<MapInfo> alistRet = new ArrayList<MapInfo>();
    alistRet.addAll(this.listMapSearchAll);
    return alistRet;
  }

}
1.76 KB in 4 ms with coderay