Package org.moeaframework.core.attribute
Interface Attribute
- All Known Implementing Classes:
CrowdingDistance
,Fitness
,Niche
,NicheDistance
,NormalizedObjectives
,OperatorIndex
,Penalty
,Rank
public interface Attribute
Marker interface for accessing attributes. Attributes are metadata associated with a specific solution. While one
can call the
Solution
methods for working with attributes directly, such as
Solution.getAttribute(String)
, these attribute classes provide a standardized and
type-safe way to access the attributes.
These classes are implemented with static
methods. This design decision was made for performance and
simplicity, as an actual class would require extra overhead from calling the constructor and methods. Static (and
final) methods can be resolved at compile-time and often in-lined. Additionally, these static methods can be used
with Java's functional interfaces (see java.util.function
) if more flexibility is required.
While this interface does not mandate any particular implementation, for standardization we recommend the following:
- The class should be
final
- Define
public static final String ATTRIBUTE_NAME
that identifies the key / name of the attribute - Define the following
static final
methods:boolean hasAttribute(Solution)
void setAttribute(Solution, T)
T getAttribute(Solution)
void removeAttribute(Solution)
(optional)
T
is the type of the attribute. Prefer using primitive types and implement any boxing / un-boxing
within the getter and setter.