de.uniks.networkparser.logic.FeatureCondition Maven / Gradle / Ivy
package de.uniks.networkparser.logic;
import de.uniks.networkparser.buffer.CharacterBuffer;
import de.uniks.networkparser.graph.Clazz;
import de.uniks.networkparser.graph.Feature;
import de.uniks.networkparser.graph.FeatureProperty;
import de.uniks.networkparser.graph.GraphMember;
import de.uniks.networkparser.graph.util.FeatureSet;
import de.uniks.networkparser.interfaces.LocalisationInterface;
import de.uniks.networkparser.interfaces.ObjectCondition;
import de.uniks.networkparser.interfaces.SendableEntityCreator;
import de.uniks.networkparser.interfaces.TemplateParser;
import de.uniks.networkparser.list.SimpleSet;
/**
* @author Stefan
* FeatureCondition for ModelFilter
*
* Format {{#feature SETCLASS=SimpleSet}}
*/
public class FeatureCondition extends CustomCondition {
private static final String PROPERTY_FEATURE="variable.features";
public static final String TAG="feature";
private FeatureProperty feature;
@Override
public String getKey() {
return TAG;
}
@Override
public void create(CharacterBuffer buffer, TemplateParser parser, LocalisationInterface customTemplate) {
CharacterBuffer temp = buffer.nextToken(false, SPLITEND, ENTER);
this.feature = Feature.valueOf(temp.toString()).create();
temp = buffer.nextToken(false, SPLITEND);
if(temp.length()>0) {
String string = temp.toString();
if(SimpleSet.class.getSimpleName().equals(string) || SimpleSet.class.getName().equals(string)) {
this.feature.withClazzValue(SimpleSet.class);
}else {
this.feature.withStringValue(string);
}
buffer.skipChar(SPLITEND);
}
buffer.skip();
}
@Override
public FeatureCondition getSendableInstance(boolean isExpression) {
return new FeatureCondition().withExpression(isExpression);
}
@Override
public Object getValue(SendableEntityCreator creator, GraphMember member) {
return null;
}
@Override
public CharSequence getValue(LocalisationInterface value) {
FeatureProperty feature = getFeature(value);
if (feature != null) {
SendableEntityCreator creator = (SendableEntityCreator) value;
Class> classValue = feature.getClassValue();
if (classValue != null) {
creator.setValue(value, "headers", classValue.getName(), SendableEntityCreator.NEW);
return classValue.getSimpleName();
}
String stringValue = feature.getStringValue();
if (stringValue != null) {
creator.setValue(value, "headers", stringValue, SendableEntityCreator.NEW);
return stringValue;
}
}
return null;
}
private FeatureProperty getFeature(Object value) {
if(value instanceof SendableEntityCreator) {
SendableEntityCreator creator = (SendableEntityCreator) value;
FeatureSet features = (FeatureSet) creator.getValue(creator, PROPERTY_FEATURE);
return features.getFeatureProperty(this.feature.getName());
}
return null;
}
@Override
public boolean update(Object value) {
if(feature == null) {
return true;
}
if(this.isExpression == false && value instanceof ObjectCondition) {
return ((ObjectCondition)value).update(this);
}
FeatureProperty feature = getFeature(value);
if(feature != null) {
Clazz clazz = getMember(value).getClazz();
return hasFeatureProperty(feature, clazz);
}
return false;
}
public boolean hasFeatureProperty(FeatureProperty property, Clazz... values) {
if(property != null) {
if(values == null) {
return true;
}
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy