EpicEnchants/src/main/java/com/songoda/epicenchants/managers/Manager.java

49 lines
1.1 KiB
Java
Raw Normal View History

2019-02-19 14:23:20 +01:00
package com.songoda.epicenchants.managers;
import com.songoda.epicenchants.EpicEnchants;
2021-07-10 23:41:20 +02:00
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
2019-02-19 14:23:20 +01:00
public abstract class Manager<K, V> {
final EpicEnchants instance;
private final Map<K, V> map;
public Manager(EpicEnchants instance) {
this.instance = instance;
this.map = new HashMap<>();
}
public Optional<V> getValue(K key) {
2019-08-05 22:21:49 +02:00
for (Object k : map.keySet()) {
if (k.toString().equalsIgnoreCase(key.toString()))
return Optional.ofNullable(map.get(k));
}
return Optional.empty();
2019-02-19 14:23:20 +01:00
}
public void add(K key, V value) {
map.put(key, value);
}
public V getValueUnsafe(K key) {
return getValue(key).orElse(null);
}
public Collection<V> getValues() {
return Collections.unmodifiableCollection(map.values());
}
2019-04-08 15:37:46 +02:00
public Collection<K> getKeys() {
return Collections.unmodifiableCollection(map.keySet());
}
2019-03-21 15:35:12 +01:00
public void clear() {
map.clear();
}
2019-02-19 14:23:20 +01:00
}