org.aksw.commons.accessors.PropertySource Maven / Gradle / Ivy
package org.aksw.commons.accessors;
import java.util.Collection;
/**
* This class is similar to the spring PropertySource - except that it allows setting properties as well.
* A simple interface to resolve properties by name, value type and value multiplicity (single or multi).
*
*
*
* @author raven Apr 10, 2018
*
*/
public interface PropertySource {
Object getSource();
SingleValuedAccessor getProperty(String name, Class valueType);
/**
* Retrieve an accessor to a multi valued collection
*
* @param name
* @param itemType
* @return
*/
default SingleValuedAccessor> getCollectionProperty(String name, Class itemType) {
Object tmp = getProperty(name, Collection.class);
return (SingleValuedAccessor>) tmp;
}
/**
* Retrieves a single valued property and wraps it as a set with at most 1 item.
* Removing the item from the set is equivalent to setting the property to null.
*
* @param name
* @param itemType
* @return
*/
// default SingleValuedAccessor> getPropertyAsSet(String name, Class itemType) {
// SingleValuedAccessor> result =
// new SingleValuedAccessorDirect<>(
// new CollectionFromSingleValuedAccessor<>(
// getProperty(name, itemType)));
// return result;
// }
default CollectionAccessor getPropertyAsSet(String name, Class itemType) {
SingleValuedAccessor accessor = getProperty(name, itemType);
if(accessor == null) {
throw new RuntimeException("No accessor for " + name + " on " + this);
}
CollectionAccessor result =
new CollectionAccessorFromSingleValuedAccessor<>(accessor);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy