Last active
January 3, 2018 03:07
-
-
Save damby/770a0ca71b449c2ffd66e4f80ab20b89 to your computer and use it in GitHub Desktop.
1 : n - Data Trigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Event{ | |
| int on(String type, String value); | |
| void off(String type, Object object); | |
| void off(String type, int index); | |
| void off(String type); | |
| void off(); | |
| *List<*Object> trigger(String type, Object object); | |
| Object trigger(String type); | |
| } | |
| class EventOccurrence implements Event{ | |
| HashMap<String, ArrayList<Object>> data | |
| = new HashMap<String, ArrayList<Object>>(); | |
| void hasKey(String type){ | |
| return (data.containsKey(type)); | |
| } | |
| int on(String type, String value){ | |
| if(!hasKey(type)) index.put(type, new ArrayList<Object>()); | |
| data.get(type).add(value); | |
| return data.get(type).size(); | |
| } | |
| void off(String type, Object object){ | |
| if(!hasKey(type)) return; | |
| if(data.get(type).isEmpty()) return; | |
| if(!data.get(type).contains(object)) return; | |
| data.get(type).remove(object); | |
| } | |
| void off(String type, int index){ | |
| if(!hasKey(type)) return; | |
| if(data.get(type).isEmpty() or data.get(type).size() ≦ index) return; | |
| data.get(type).remove(index); | |
| } | |
| void off(String type){ | |
| if(!hasKey(type)) return; | |
| if(data.get(type).isEmpty()) return; | |
| data.get(type).clear(); | |
| } | |
| void off(){ | |
| data.clear(); | |
| } | |
| ArrayList<Object> trigger(String type, Object object){ | |
| if(!hasKey(type)) return; | |
| if(!data.get(type).contains(object)) return; | |
| return data.get(type); | |
| } | |
| Object trigger(String type, int index){ | |
| if(!hasKey(type)) return; | |
| if(data.get(type).isEmpty() or data.get(type).size() ≦ index) return; | |
| return data.get(type).get(index); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment