Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.databene.model.data.FeatureDescriptor Maven / Gradle / Ivy
Go to download
benerator is a framework for creating realistic and valid high-volume test data, used for
testing (unit/integration/load) and showcase setup.
Metadata constraints are imported from systems and/or configuration files. Data can imported from
and exported to files and systems, anonymized or generated from scratch. Domain packages provide
reusable generators for creating domain-specific data as names and addresses internationalizable
in language and region. It is strongly customizable with plugins and configuration options.
package org.databene.model.data;
import org.databene.commons.Named;
import org.databene.commons.NullSafeComparator;
import org.databene.commons.Operation;
import org.databene.commons.StringUtil;
import org.databene.commons.collection.OrderedNameMap;
import org.databene.commons.converter.AnyConverter;
import org.databene.commons.converter.ConverterManager;
import org.databene.commons.converter.String2ConverterConverter;
import org.databene.commons.converter.ToStringConverter;
import java.util.List;
/**
* Common parent class of all descriptors.
* Created: 17.07.2006 21:30:45
* @since 0.1
* @author Volker Bergmann
*/
public class FeatureDescriptor implements Named {
public static final String NAME = "name";
static {
ConverterManager.getInstance().registerConverterClass(String2ConverterConverter.class);
}
protected OrderedNameMap> details;
// constructor -----------------------------------------------------------------------------------------------------
public FeatureDescriptor(String name) {
this.details = new OrderedNameMap>();
addConstraint(NAME, String.class, null, null);
setName(name);
}
// typed interface -------------------------------------------------------------------------------------------------
/*
public void setParent(FeatureDescriptor parent) {
this.parent = parent;
}
*/
public String getName() {
return (String) getDetailValue(NAME);
}
public void setName(String name) {
setDetailValue(NAME, name);
}
// generic detail access -------------------------------------------------------------------------------------------
public boolean supportsDetail(String name) {
return details.containsKey(name);
}
public Object getDeclaredDetailValue(String name) {
return getConfiguredDetail(name).getValue();
}
public Object getDetailValue(String name) {
FeatureDetail detail = getConfiguredDetail(name);
return detail.getValue();
}
public void setDetailValue(String detailName, Object detailValue) {
FeatureDetail detail = getConfiguredDetail(detailName);
detail.setValue(AnyConverter.convert(detailValue, detail.getType()));
}
public T getDetailDefault(String name) {
FeatureDetail detail = getConfiguredDetail(name);
return detail.getDefault();
}
public List> getDetails() {
return details.values();
}
// java.lang overrides ---------------------------------------------------------------------------------------------
@Override
public String toString() {
String name = getName();
if (StringUtil.isEmpty(name))
name = "anonymous";
StringBuilder buffer = new StringBuilder(name).append("[");
boolean empty = true;
for (FeatureDetail> descriptor : details.values())
if (descriptor.getValue() != null && !NAME.equals(descriptor.getName())) {
if (!empty)
buffer.append(", ");
empty = false;
buffer.append(descriptor.getName()).append("=");
buffer.append(ToStringConverter.convert(descriptor.getValue(), "[null]"));
}
return buffer.append("]").toString();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
final FeatureDescriptor that = (FeatureDescriptor) o;
for (FeatureDetail> detail : details.values()) {
String detailName = detail.getName();
if (!NullSafeComparator.equals(detail.getValue(), that.getDetailValue(detailName)))
return false;
}
return true;
}
@Override
public int hashCode() {
return (getClass().hashCode() * 29 /*+ (parent != null ? parent.hashCode() : 0)*/) * 29 + details.hashCode();
}
// helpers ---------------------------------------------------------------------------------------------------------
protected Class> getDetailType(String detailName) {
FeatureDetail> detail = details.get(detailName);
if (detail == null)
throw new UnsupportedOperationException("Feature detail not supported: " + detailName);
return detail.getType();
}
protected void addConfig(String name, Class type, T defaultValue) {
addConfig(name, type, defaultValue, false);
}
protected void addConfig(String name, Class type, T defaultValue, boolean deprecated) {
addDetail(name, type, false, defaultValue, deprecated, null);
}
protected void addConstraint(String name, Class type, T defaultValue, Operation combinator) {
addDetail(name, type, true, defaultValue, false, combinator);
}
protected void addDetail(String detailName, Class detailType, boolean constraint, T defaultValue,
boolean deprecated, Operation combinator) {
this.details.put(detailName, new FeatureDetail(detailName, detailType, constraint, defaultValue, combinator));
}
// generic property access -----------------------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public FeatureDetail getConfiguredDetail(String name) {
if (!supportsDetail(name))
throw new UnsupportedOperationException("Feature detail '" + name +
"' not supported in feature type: " + getClass().getName());
return (FeatureDetail) details.get(name);
}
}