Skip to content

Commit

Permalink
calculateLevel method refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedran authored and Vedran committed Mar 22, 2018
1 parent f26ff2b commit a84cd14
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/org/cactoos/scalar/InheritanceLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,22 @@ public Integer value() {
if (this.base.equals(this.derived)) {
level = InheritanceLevel.IDENTICAL;
} else {
level = InheritanceLevel.calculateLevel(this.derived, this.base);
level = this.calculateLevel();
}
return level;
}

/**
* Calculates inheritance level.
* @param cbase Base class
* @param cderived Derived class
* @return Integer Level
*/
private static int calculateLevel(final Class<?> cderived,
final Class<?> cbase) {
private int calculateLevel() {
int level = InheritanceLevel.NOT_RELATED;
Class<?> sclass = cderived.getSuperclass();
Class<?> sclass = this.derived.getSuperclass();
int idx = 0;
while (!sclass.equals(Object.class)) {
idx += 1;
if (sclass.equals(cbase)) {
if (sclass.equals(this.base)) {
level = idx;
break;
}
Expand Down

0 comments on commit a84cd14

Please sign in to comment.