Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public class AttributeUtils {
// return new String[] { "Not an extended Feature Model" };
// }

public static boolean isNumerical(IFeatureAttribute att) {
public static boolean isNumerical(IFeatureAttribute<?> att) {
return att.getType().equals(FeatureAttribute.LONG) || att.getType().equals(FeatureAttribute.DOUBLE);
}

public static boolean isBoolean(IFeatureAttribute att) {
public static boolean isBoolean(IFeatureAttribute<?> att) {
return att.getType().equals(FeatureAttribute.BOOLEAN);
}

Expand All @@ -85,7 +85,7 @@ public static String getUnitByName(IFeatureModel featureModel, String attribute)
IExtendedFeatureModel extModel = (IExtendedFeatureModel) featureModel;
for (IFeature feat : extModel.getFeatures()) {
IExtendedFeature ext = (IExtendedFeature) feat;
for (IFeatureAttribute att : ext.getAttributes()) {
for (IFeatureAttribute<?> att : ext.getAttributes()) {
if (att.getName().equals(attribute)) {
return att.getUnit();
}
Expand All @@ -96,7 +96,7 @@ public static String getUnitByName(IFeatureModel featureModel, String attribute)
return null;
}

public static Double getDoubleValue(IFeatureAttribute att, Double defaultValue) {
public static Double getDoubleValue(IFeatureAttribute<?> att, Double defaultValue) {
if (!isNumerical(att)) {
return null;
}
Expand All @@ -111,14 +111,14 @@ public static Double getDoubleValue(IFeatureAttribute att, Double defaultValue)
}
}

public static Boolean getBooleanValue(IFeatureAttribute att) {
public static Boolean getBooleanValue(IFeatureAttribute<?> att) {
if (!isBoolean(att) || att.getValue() == null) {
return null;
}
return (boolean) att.getValue();
}

public static Double getBooleanValueAsDouble(IFeatureAttribute att, Double defaultValue) {
public static Double getBooleanValueAsDouble(IFeatureAttribute<?> att, Double defaultValue) {
Double trueDouble = 1d;
Double falseDouble = 0d;
Boolean value = getBooleanValue(att);
Expand All @@ -136,7 +136,7 @@ public static Double getBooleanValueAsDouble(IFeatureAttribute att, Double defau
* @param attributeName The name of the attribute
* @return The attribute, or null if the feature or attribute cannot be found
*/
public static IFeatureAttribute getAttribute(IFeatureModel featureModel, String featureName, String attributeName) {
public static IFeatureAttribute<?> getAttribute(IFeatureModel featureModel, String featureName, String attributeName) {
final IFeature feature = featureModel.getFeature(featureName);
if (feature instanceof IExtendedFeature) { // Also checks that feature != null
final IExtendedFeature extendedFeature = (IExtendedFeature) feature;
Expand All @@ -153,13 +153,13 @@ public static IFeatureAttribute getAttribute(IFeatureModel featureModel, String
* @param attributeName
* @return The found attribute, or null if no attribute is found
*/
public static IFeatureAttribute getChildAttribute(IExtendedFeature feature, String attributeName) {
IFeatureAttribute att = feature.getAttribute(attributeName);
public static IFeatureAttribute<?> getChildAttribute(IExtendedFeature feature, String attributeName) {
IFeatureAttribute<?> att = feature.getAttribute(attributeName);
if (att != null) {
return att;
}
for (IFeatureStructure child : feature.getStructure().getChildren()) {
IFeatureAttribute childAtt = getChildAttribute((IExtendedFeature) child.getFeature(), attributeName);
IFeatureAttribute<?> childAtt = getChildAttribute((IExtendedFeature) child.getFeature(), attributeName);
if (childAtt != null) {
return childAtt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

import de.ovgu.featureide.fm.attributes.base.exceptions.FeatureAttributeParseException;
import de.ovgu.featureide.fm.attributes.base.exceptions.UnknownFeatureAttributeTypeException;
import de.ovgu.featureide.fm.attributes.base.impl.BooleanFeatureAttribute;
import de.ovgu.featureide.fm.attributes.base.impl.DoubleFeatureAttribute;
import de.ovgu.featureide.fm.attributes.base.impl.LongFeatureAttribute;
import de.ovgu.featureide.fm.attributes.base.impl.StringFeatureAttribute;
import de.ovgu.featureide.fm.core.base.IFeature;

/**
Expand All @@ -41,7 +45,7 @@ public abstract class AbstractFeatureAttributeFactory {
* @return The instance of the feature attribute. Can return null when information contain invalid values. Like the value of an extended feature attribute
* of type double is set to "test".
*/
public abstract IFeatureAttribute createFeatureAttribute(IFeatureAttributeParsedData attributeData, IFeature correspondingFeature)
public abstract IFeatureAttribute<?> createFeatureAttribute(IFeatureAttributeParsedData attributeData, IFeature correspondingFeature)
throws FeatureAttributeParseException, UnknownFeatureAttributeTypeException;

/**
Expand All @@ -55,7 +59,7 @@ public abstract IFeatureAttribute createFeatureAttribute(IFeatureAttributeParsed
* @param configurable true when the attribute should be configurable
* @return The instance of the created feature attribute.
*/
public abstract IFeatureAttribute createStringAttribute(IFeature correspondingFeature, String name, String unit, String value, boolean recursive,
public abstract StringFeatureAttribute createStringAttribute(IFeature correspondingFeature, String name, String unit, String value, boolean recursive,
boolean configurable);

/**
Expand All @@ -69,7 +73,7 @@ public abstract IFeatureAttribute createStringAttribute(IFeature correspondingFe
* @param configurable true when the attribute should be configurable
* @return The instance of the created feature attribute.
*/
public abstract IFeatureAttribute createBooleanAttribute(IFeature correspondingFeature, String name, String unit, Boolean value, boolean recursive,
public abstract BooleanFeatureAttribute createBooleanAttribute(IFeature correspondingFeature, String name, String unit, Boolean value, boolean recursive,
boolean configurable);

/**
Expand All @@ -83,7 +87,7 @@ public abstract IFeatureAttribute createBooleanAttribute(IFeature correspondingF
* @param configurable true when the attribute should be configurable
* @return The instance of the created feature attribute.
*/
public abstract IFeatureAttribute createLongAttribute(IFeature correspondingFeature, String name, String unit, Long value, boolean recursive,
public abstract LongFeatureAttribute createLongAttribute(IFeature correspondingFeature, String name, String unit, Long value, boolean recursive,
boolean configurable);

/**
Expand All @@ -97,7 +101,7 @@ public abstract IFeatureAttribute createLongAttribute(IFeature correspondingFeat
* @param configurable true when the attribute should be configurable
* @return The instance of the created feature attribute.
*/
public abstract IFeatureAttribute createDoubleAttribute(IFeature correspondingFeature, String name, String unit, Double value, boolean recursive,
public abstract DoubleFeatureAttribute createDoubleAttribute(IFeature correspondingFeature, String name, String unit, Double value, boolean recursive,
boolean configurable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public interface IExtendedFeature extends IFeature {
/**
* @return all attributes that are contained in this feature.
*/
public List<IFeatureAttribute> getAttributes();
public List<IFeatureAttribute<?>> getAttributes();

/**
* @param name The name of an attribute
* @return The attribute with the given name, or null if no such attribute exists
*/
public default IFeatureAttribute getAttribute(String name) {
for (IFeatureAttribute attribute : getAttributes()) {
public default IFeatureAttribute<?> getAttribute(String name) {
for (IFeatureAttribute<?> attribute : getAttributes()) {
if (attribute.getName().equals(name)) {
return attribute;
}
Expand All @@ -56,17 +56,17 @@ public default IFeatureAttribute getAttribute(String name) {
/**
* @param attribute the attribute that is added to this feature.
*/
public void addAttribute(IFeatureAttribute attribute);
public void addAttribute(IFeatureAttribute<?> attribute);

/**
* @param attribute the attribute that needs to be removed from this feature.
*/
public void removeAttribute(IFeatureAttribute attribute);
public void removeAttribute(IFeatureAttribute<?> attribute);

/**
* @param attribute the attribute that needs to be checked for containment in this feature.
* @return true, if the name of the given attribute is contained in the feature. False otherwise.
*/
public boolean isContainingAttribute(IFeatureAttribute attribute);
public boolean isContainingAttribute(IFeatureAttribute<?> attribute);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author Joshua Sprey
* @author Chico Sundermann
*/
public interface IFeatureAttribute {
public interface IFeatureAttribute<T> {

/**
* Retrieves the {@link IFeature} assigned to the feature attribute.
Expand All @@ -53,7 +53,7 @@ public interface IFeatureAttribute {
/**
* @return The value of the feature attribute.
*/
public Object getValue();
public T getValue();

/**
* @return The type of the feature attribute.
Expand Down Expand Up @@ -94,7 +94,7 @@ public interface IFeatureAttribute {
*
* @param value New value for the attribute.
*/
public void setValue(Object value);
public void setValue(T value);

/**
* Sets the feature attribute to recursive.
Expand Down Expand Up @@ -133,15 +133,15 @@ public interface IFeatureAttribute {
* @param feature New feature
* @return Clone of attribute with new feature.
*/
public IFeatureAttribute cloneRecursive(IFeature feature);
public IFeatureAttribute<T> cloneRecursive(IFeature feature);

/**
* Clones the attribute.
*
* @param feature New feature
* @return Clone of the attribute with the new feature.
*/
public IFeatureAttribute cloneAtt(IFeature feature);
public IFeatureAttribute<T> cloneAtt(IFeature feature);

/**
* @return true, if attribute is head recursive attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package de.ovgu.featureide.fm.attributes.base.impl;

import de.ovgu.featureide.fm.attributes.base.IFeatureAttribute;
import de.ovgu.featureide.fm.core.base.IFeature;

/**
Expand All @@ -29,9 +28,7 @@
* @author Joshua Sprey
* @author Chico Sundermann
*/
public class BooleanFeatureAttribute extends FeatureAttribute {

private Boolean value;
public class BooleanFeatureAttribute extends FeatureAttribute<Boolean> {

/**
* Creates a new boolean attribute with the given values.
Expand All @@ -45,8 +42,7 @@ public class BooleanFeatureAttribute extends FeatureAttribute {
*
*/
public BooleanFeatureAttribute(IFeature feature, String name, String unit, Boolean value, boolean recursive, boolean configurable) {
super(feature, name, unit, recursive, configurable);
this.value = value;
super(feature, name, value, unit, recursive, configurable);
attributeType = FeatureAttribute.BOOLEAN;
}

Expand All @@ -58,27 +54,10 @@ public BooleanFeatureAttribute(IFeature feature, String name, String unit, Boole
*/
public BooleanFeatureAttribute(BooleanFeatureAttribute oldAttribute, IFeature feature) {
super(oldAttribute, feature);
value = oldAttribute.value;
}

@Override
public Boolean getValue() {
return value;
}

@Override
public void setValue(Object value) {
if (value == null) {
this.value = null;
return;
}
if (value instanceof Boolean) {
this.value = (Boolean) value;
}
}

@Override
public IFeatureAttribute cloneAtt(IFeature feature) {
public BooleanFeatureAttribute cloneAtt(IFeature feature) {
return new BooleanFeatureAttribute(this, feature);
}

Expand All @@ -89,12 +68,13 @@ public IFeatureAttribute cloneAtt(IFeature feature) {
* @return clone of the attribute with value set to null
*/
@Override
public IFeatureAttribute cloneRecursive(IFeature feature) {
public BooleanFeatureAttribute cloneRecursive(IFeature feature) {
return new BooleanFeatureAttribute(feature, this.getName(), this.getUnit(), null, this.isRecursive(), this.isConfigurable());
}

@Override
public boolean isValidValue(String value) {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package de.ovgu.featureide.fm.attributes.base.impl;

import de.ovgu.featureide.fm.attributes.base.IFeatureAttribute;
import de.ovgu.featureide.fm.core.base.IFeature;

/**
Expand All @@ -29,9 +28,7 @@
* @author Joshua Sprey
* @author Chico Sundermann
*/
public class DoubleFeatureAttribute extends FeatureAttribute {

private Double value;
public class DoubleFeatureAttribute extends FeatureAttribute<Double> {

/**
* Creates a new double attribute with the given values.
Expand All @@ -45,8 +42,7 @@ public class DoubleFeatureAttribute extends FeatureAttribute {
*
*/
public DoubleFeatureAttribute(IFeature feature, String name, String unit, Double value, boolean recursive, boolean configurable) {
super(feature, name, unit, recursive, configurable);
this.value = value;
super(feature, name, value, unit, recursive, configurable);
attributeType = FeatureAttribute.DOUBLE;
}

Expand All @@ -58,34 +54,13 @@ public DoubleFeatureAttribute(IFeature feature, String name, String unit, Double
*/
public DoubleFeatureAttribute(DoubleFeatureAttribute oldAttribute, IFeature feature) {
super(oldAttribute, feature);
value = oldAttribute.value;
}

@Override
public Double getValue() {
return value;
}

/*
* (non-Javadoc)
* @see de.ovgu.featureide.fm.core.attributes.impl.FeatureAttribute#setValue(java.lang.Object)
*/
@Override
public void setValue(Object value) {
if (value == null) {
this.value = null;
return;
}
if (value instanceof Double) {
this.value = (Double) value;
}
}

/**
* Returns a copy of the attribute
*/
@Override
public IFeatureAttribute cloneAtt(IFeature feature) {
public DoubleFeatureAttribute cloneAtt(IFeature feature) {
return new DoubleFeatureAttribute(this, feature);
}

Expand All @@ -96,7 +71,7 @@ public IFeatureAttribute cloneAtt(IFeature feature) {
* @return clone of the attribute with value set to null
*/
@Override
public IFeatureAttribute cloneRecursive(IFeature feature) {
public DoubleFeatureAttribute cloneRecursive(IFeature feature) {
return new DoubleFeatureAttribute(feature, this.getName(), this.getUnit(), null, this.isRecursive(), this.isConfigurable());
}

Expand All @@ -109,4 +84,5 @@ public boolean isValidValue(String value) {
return false;
}
}

}
Loading
Loading