-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.java
More file actions
121 lines (113 loc) · 3.51 KB
/
Copy pathHelpers.java
File metadata and controls
121 lines (113 loc) · 3.51 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.HashMap;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.io.File;
import java.io.InputStream;
/**
* A class of static helper methods that involve either reading or writing local data files
* as well as combineAlphabetical which creates an alphabetized key to be used in the History maps
*/
public class Helpers {
public static String combineAlphabetical(String s1, String s2) {
if (s1.compareTo(s2) < 0) {
return s1 + "," + s2;
}
return s2 + "," + s1;
}
public static HashMap<String, History> loadHistMap(boolean ally) {
try {
InputStream fis = null;
if (ally) {
fis = Helpers.class.getResourceAsStream(".coredata/history data/.allyHistMap.ser");
} else {
fis = Helpers.class.getResourceAsStream(".coredata/history data/.enemyHistMap.ser");
}
ObjectInputStream ois = new ObjectInputStream(fis);
HashMap<String, History> map = (HashMap<String, History>) ois.readObject();
ois.close();
fis.close();
return map;
} catch (Exception e) {
return null;
}
}
public static HashMap<String, Double> loadUserData(String summonerName, String region) {
try {
FileInputStream fis = new FileInputStream(".data/user/" + region + "/" + summonerName + ".ser");
ObjectInputStream ois = new ObjectInputStream(fis);
HashMap<String, Double> map = (HashMap<String, Double>) ois.readObject();
ois.close();
fis.close();
return map;
} catch (Exception e) {
return null;
}
}
public static HashMap<String, Double> loadGlobalData(String region) {
try {
FileInputStream fis = new FileInputStream(".data/global/" + region + ".ser");
ObjectInputStream ois = new ObjectInputStream(fis);
HashMap<String, Double> map = (HashMap<String, Double>) ois.readObject();
ois.close();
fis.close();
return map;
} catch (Exception e) {
return null;
}
}
public static void saveUserData(HashMap<String, Double> map, String summonerName, String region) {
try {
File dir = new File(".data/user/" + region);
if (!dir.isDirectory()) {
dir.mkdirs();
}
FileOutputStream fos = new FileOutputStream(".data/user/" + region + "/" + summonerName + ".ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(map);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void saveGlobalData(HashMap<String, Double> map, String region) {
try {
File dir = new File(".data/global");
if (!dir.isDirectory()) {
dir.mkdirs();
}
FileOutputStream fos = new FileOutputStream(".data/global/" + region + ".ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(map);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void saveUserUpdateTime(String summonerName, String region, Date d) {
try {
FileOutputStream fos = new FileOutputStream(".data/user/" + region + "/" + summonerName + "updatetime.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(d);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void saveGlobalUpdateTime(String region, Date d) {
try {
FileOutputStream fos = new FileOutputStream(".data/global/" + region + "updatetime.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(d);
oos.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}