@author 许继元
| 11 | * @author 许继元 |
| 12 | */ |
| 13 | public class UsersContainer { |
| 14 | public Map<String, User> users = null; |
| 15 | public MySqlLoader mysqlLoader = null; |
| 16 | public static final UsersContainer INSTANCE = new UsersContainer(); |
| 17 | |
| 18 | private UsersContainer() { |
| 19 | this.init(); |
| 20 | } |
| 21 | |
| 22 | private void init() { |
| 23 | try { |
| 24 | mysqlLoader = new MySqlLoader(); |
| 25 | } catch (ClassNotFoundException | SQLException e) { |
| 26 | e.printStackTrace(); |
| 27 | } |
| 28 | this.clear(); |
| 29 | this.loadData(); |
| 30 | } |
| 31 | |
| 32 | public void clear() { |
| 33 | if (users == null) { |
| 34 | users = new HashMap<>(); |
| 35 | } |
| 36 | users.clear(); |
| 37 | } |
| 38 | |
| 39 | public boolean connectFriend(String srcId, String dstId) { |
| 40 | this.mysqlLoader.connectFriend(srcId, dstId); |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | public boolean deleteFriend(String srcId, String dstId) { |
| 45 | this.mysqlLoader.deleteFriend(srcId, dstId); |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | public ArrayList<String> searchFriend(String srcId) { |
| 50 | return this.mysqlLoader.searchFriend(srcId); |
| 51 | } |
| 52 | |
| 53 | public ArrayList<User> searchFriendAsUser(String srcId) { |
| 54 | ArrayList<User> res = new ArrayList<>(); |
| 55 | |
| 56 | for (String id : this.mysqlLoader.searchFriend(srcId)) { |
| 57 | res.add(this.users.get(id)); |
| 58 | } |
| 59 | return res; |
| 60 | } |
| 61 | |
| 62 | public ArrayList<User> searchApplyFriendAsUser(String srcId) { |
| 63 | ArrayList<User> res = new ArrayList<>(); |
| 64 | |
| 65 | for (String id : this.mysqlLoader.searchApplyFriend(srcId)) { |
| 66 | res.add(this.users.get(id)); |
| 67 | } |
| 68 | return res; |
| 69 | } |
| 70 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…