Created
November 20, 2015 11:24
-
-
Save serhii-shnurenko/0eec3ecd8a4ad24e8203 to your computer and use it in GitHub Desktop.
ObjectHolder to get out assoiciated with strings objects from tagged map
This file contains 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 commandline.commands; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Created by Сергій Шнуренко on 15.11.2015. | |
*/ | |
public class ObjectsHolder { | |
private Map<String,Object> pairs; | |
private static ObjectsHolder instance = new ObjectsHolder(); | |
private ObjectsHolder(){ | |
pairs = new HashMap<String,Object>(); | |
} | |
public static ObjectsHolder getInstance(){ | |
return instance; | |
} | |
public void put(String key, Object value){ | |
pairs.put(key,value); | |
} | |
public Object get(String key){ | |
for(Map.Entry<String,Object> entry:pairs.entrySet()) { | |
if (entry.getKey().equals(key)) { | |
return entry.getValue(); | |
} | |
} | |
//if no associated with this key value | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment