Created
May 13, 2014 19:34
-
-
Save kornysietsma/e182708fa75eb3b37bb2 to your computer and use it in GitHub Desktop.
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
| (ns foo.badmap | |
| (:import (foo BadMap))) | |
| (def m (BadMap. {"a" "a" "b" "b" "c" "c" "d" "d"})) | |
| (prn (keys m)) | |
| => ("a" "d" "c" "b") | |
| (prn (vals m)) | |
| => ("b" "d" "a" "c") | |
| (= (zipmap (keys m) (vals m)) m) | |
| => false |
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
| package foo; | |
| import java.util.*; | |
| public class BadMap implements Map<String,String> { | |
| private Map<String,String> theMap; | |
| public BadMap(Map<String,String> m) { | |
| theMap = m; | |
| } | |
| @Override | |
| public int size() { | |
| return theMap.size(); | |
| } | |
| @Override | |
| public boolean isEmpty() { | |
| return theMap.isEmpty(); | |
| } | |
| @Override | |
| public boolean containsKey(Object key) { | |
| return theMap.containsKey(key); | |
| } | |
| @Override | |
| public boolean containsValue(Object value) { | |
| return theMap.containsValue(value); | |
| } | |
| @Override | |
| public String get(Object key) { | |
| return theMap.get(key); | |
| } | |
| @Override | |
| public String put(String key, String value) { | |
| return theMap.put(key,value); | |
| } | |
| @Override | |
| public String remove(Object key) { | |
| return theMap.remove(key); | |
| } | |
| @Override | |
| public void putAll(Map<? extends String, ? extends String> m) { | |
| theMap.putAll(m); | |
| } | |
| @Override | |
| public void clear() { | |
| theMap.clear(); | |
| } | |
| @Override | |
| public Set<String> keySet() { | |
| LinkedList<String> keys = new LinkedList<String>(theMap.keySet()); | |
| Collections.shuffle(keys); | |
| return new LinkedHashSet<String>(keys); | |
| } | |
| @Override | |
| public Collection<String> values() { | |
| LinkedList<String> vals = new LinkedList<String>(theMap.values()); | |
| Collections.shuffle(vals); | |
| return vals; | |
| } | |
| @Override | |
| public Set<Entry<String, String>> entrySet() { | |
| LinkedList<Entry<String, String>> entries = new LinkedList<Entry<String, String>>(theMap.entrySet()); | |
| Collections.shuffle(entries); | |
| return new LinkedHashSet<Entry<String, String>>(entries); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment