
org.kasource.commons.reflection.collection.PackageMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ka-commons-reflection Show documentation
Show all versions of ka-commons-reflection Show documentation
Common utilities and classes for reflection
package org.kasource.commons.reflection.collection;
import java.util.Map;
/**
* Wraps a map and resolves super packages of the key.
*
* @author rikardwi
*
* @param Content type of the map
**/
public class PackageMap {
private Map map;
public PackageMap() {}
public PackageMap(Map map) {
this.map = map;
}
public T get(Class> clazz) {
return get(clazz.getName());
}
public T get(String packageOrClassName) {
if(map == null || map.isEmpty()) {
return null;
}
int index = packageOrClassName.lastIndexOf(".");
String packageName = packageOrClassName;
T object = map.get(packageName);
while (object == null && index > 0) {
packageName = packageName.substring(0, index);
object = map.get(packageName);
index = packageName.lastIndexOf(".");
}
return object;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy