Skip to content

Commit

Permalink
Add ability to include or exclude methods from Object class with Clas…
Browse files Browse the repository at this point in the history
…sComparer.

Signed-off-by: Donald Raab <Donald.Raab@bnymellon.com>
  • Loading branch information
donraab committed Nov 21, 2021
1 parent e7e8416 commit 6c70892
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ClassComparer
private final boolean includeParameterTypesInMethods;
private final boolean includeReturnTypes;
private final boolean includePackageNames;
private boolean includeObjectMethods = false;
private final Appendable appendable;

public ClassComparer()
Expand Down Expand Up @@ -162,7 +163,17 @@ private String classNames(Twin<Class<?>> classPair)

public MutableSortedSet<String> getMethodNames(Class<?> classOne)
{
return ArrayIterate.collect(classOne.getMethods(), this::methodName, SortedSets.mutable.empty());
return ArrayIterate.collectIf(classOne.getMethods(), this::includeMethod, this::methodName, SortedSets.mutable.empty());
}

public void includeObjectMethods()
{
this.includeObjectMethods = true;
}

private boolean includeMethod(Method method)
{
return this.includeObjectMethods || !method.getDeclaringClass().equals(Object.class);
}

private String methodName(Method method)
Expand Down

0 comments on commit 6c70892

Please sign in to comment.