Record Class AggregateMetrics
java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.AggregateMetrics
- Record Components:
cohesion- LCOM4 cohesion (0.0 low to 1.0 high)coupling- CBO coupling (number of coupled classes)inheritanceDepth- DIT inheritance depthmethodCount- Number of methods (or WMC weighted count)
public record AggregateMetrics(double cohesion, int coupling, int inheritanceDepth, int methodCount)
extends Record
Code quality metrics for a class, record, or component.
Object-oriented metrics that most tools ignore but are valuable for identifying refactoring candidates. These metrics are UNIQUE to EK9 coverage reports - competitors like JaCoCo don't offer them.
Metric definitions:
- LCOM4 (Lack of Cohesion of Methods): 0.0 = poor cohesion, 1.0 = perfect cohesion
- CBO (Coupling Between Objects): Count of classes this class depends on
- DIT (Depth of Inheritance Tree): How deep in inheritance hierarchy
- WMC (Weighted Methods per Class): Sum of method complexities
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AggregateMetricsEmpty metrics for aggregates without collected data. -
Constructor Summary
ConstructorsConstructorDescriptionAggregateMetrics(double cohesion, int coupling, int inheritanceDepth, int methodCount) Creates an instance of aAggregateMetricsrecord class. -
Method Summary
Modifier and TypeMethodDescriptiondoublecohesion()Returns the value of thecohesionrecord component.Get cohesion interpretation for display.intcoupling()Returns the value of thecouplingrecord component.Get coupling interpretation for display.final booleanIndicates whether some other object is "equal to" this one.booleanhasData()Check if this record has any meaningful data.booleanCheck if inheritance is too deep.final inthashCode()Returns a hash code value for this object.booleanCheck if coupling is above acceptable threshold.booleanCheck if cohesion is below acceptable threshold.intReturns the value of theinheritanceDepthrecord component.intReturns the value of themethodCountrecord component.booleanCheck if this aggregate needs attention based on any metric.toString()Returns a string representation of this record class.
-
Field Details
-
EMPTY
Empty metrics for aggregates without collected data.
-
-
Constructor Details
-
AggregateMetrics
public AggregateMetrics(double cohesion, int coupling, int inheritanceDepth, int methodCount) Creates an instance of aAggregateMetricsrecord class.- Parameters:
cohesion- the value for thecohesionrecord componentcoupling- the value for thecouplingrecord componentinheritanceDepth- the value for theinheritanceDepthrecord componentmethodCount- the value for themethodCountrecord component
-
-
Method Details
-
hasLowCohesion
public boolean hasLowCohesion()Check if cohesion is below acceptable threshold.LCOM4 < 0.5 indicates poor cohesion - the class is likely doing too many unrelated things and should be split.
- Returns:
- true if cohesion is poor (but data exists)
-
hasHighCoupling
public boolean hasHighCoupling()Check if coupling is above acceptable threshold.CBO > 10 indicates high coupling - the class depends on too many other classes, making it fragile to changes.
- Returns:
- true if coupling is too high
-
hasDeepInheritance
public boolean hasDeepInheritance()Check if inheritance is too deep.DIT > 5 may indicate over-engineering or poor design. Deep hierarchies are hard to understand and maintain.
- Returns:
- true if inheritance is too deep
-
needsAttention
public boolean needsAttention()Check if this aggregate needs attention based on any metric.- Returns:
- true if any metric indicates a problem
-
cohesionInterpretation
Get cohesion interpretation for display.- Returns:
- human-readable cohesion assessment
-
couplingInterpretation
Get coupling interpretation for display.- Returns:
- human-readable coupling assessment
-
hasData
public boolean hasData()Check if this record has any meaningful data.- Returns:
- true if any metric has data
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
cohesion
-
coupling
-
inheritanceDepth
public int inheritanceDepth()Returns the value of theinheritanceDepthrecord component.- Returns:
- the value of the
inheritanceDepthrecord component
-
methodCount
public int methodCount()Returns the value of themethodCountrecord component.- Returns:
- the value of the
methodCountrecord component
-