mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
Former-commit-id: 890f8a703f9f9f5a6b6a7c26b2f5d9928d63cf40 Former-commit-id: 9b9d5afd32871cc791d525ff2aafe693205d8c54
65 lines
1.4 KiB
Java
65 lines
1.4 KiB
Java
package com.Torvald.Terrarum;
|
|
|
|
import java.util.Hashtable;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* Created by minjaesong on 15-12-30.
|
|
*/
|
|
public class KVHashtable {
|
|
|
|
private Hashtable<String, Object> hashtable;
|
|
|
|
public KVHashtable() {
|
|
hashtable = new Hashtable<>();
|
|
}
|
|
|
|
/**
|
|
* Add key-value pair to the configuration table.
|
|
* If key does not exist on the table, new key will be generated.
|
|
* If key already exists, the value will be overwritten.
|
|
*
|
|
* @param key case insensitive
|
|
* @param value
|
|
*/
|
|
public void set(String key, Object value){
|
|
hashtable.put(key.toLowerCase(), value);
|
|
}
|
|
|
|
/**
|
|
* Get value using key from configuration table.
|
|
*
|
|
* @param key case insensitive
|
|
* @return Object value
|
|
*/
|
|
public Object get(String key){
|
|
return hashtable.get(key.toLowerCase());
|
|
}
|
|
|
|
public int getAsInt(String key) {
|
|
return (int) get(key);
|
|
}
|
|
|
|
public float getAsFloat(String key) {
|
|
Object value = get(key);
|
|
if (value instanceof Integer) return ((Integer) value).floatValue();
|
|
else return (float) value;
|
|
}
|
|
|
|
public String getAsString(String key) {
|
|
return (String) get(key);
|
|
}
|
|
|
|
public boolean getAsBoolean(String key) {
|
|
return (boolean) get(key);
|
|
}
|
|
|
|
public boolean hasKey(String key) {
|
|
return hashtable.containsKey(key);
|
|
}
|
|
|
|
public Set getKeySet() {
|
|
return hashtable.keySet();
|
|
}
|
|
|
|
} |