Last active
August 29, 2015 13:55
-
-
Save nha/8720384 to your computer and use it in GitHub Desktop.
lock-free config file
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 com.github.nha; | |
import java.util.Map; | |
import java.util.concurrent.ConcurrentHashMap; | |
public class Configuration<K, V> { | |
private Map<K, V> map; | |
public Configuration() { | |
this.map = new ConcurrentHashMap<K, V>(); | |
} | |
public void putValue(K key, V string) { | |
this.map.put(key, string); | |
} | |
public V getValue(K key) { | |
return this.map.get(key); | |
} | |
// ... | |
public static void main(String[] args) { | |
Configuration<String, String> config = new Configuration<String, String>(); | |
config.putValue("kikoo", "world!"); | |
config.putValue("fooKey", "fooValue"); | |
config.putValue("barKey", "barValue"); | |
System.out.println("kikoo " + config.getValue("kikoo")); // prints "kikoo world!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment