Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
fix: Remove API 22/23 unsupported forEach calls (#124)
Browse files Browse the repository at this point in the history
* Removes forEach since it is not supported in Android 22 and 23

* Resolves Check Style issues
  • Loading branch information
devchan4188 authored Nov 18, 2020
1 parent 01bee14 commit 2b56372
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/main/java/com/deque/axe/android/AxeConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,24 @@ public AxeConf() {

public final transient Set<Class<? extends AxeRuleViewHierarchy>> customRules = new HashSet<>();

/**
* A set of AxeRules that will be excluded from result.
* @param ruleIds List of ruleIds to ignore.
* @param ignore boolean to ignore or not.
* @return the AxeConf instance.
*/
public AxeConf ignore(final List<String> ruleIds, boolean ignore) {
ruleIds.forEach(s -> ignore(s, ignore));
for (String s : ruleIds) {
ignore(s, ignore);
}
return this;
}

/**
* A set of AxeRules that will be excluded from result.
* An AxeRule that will be excluded from result.
* @param ruleId ruleId to ignore.
* @param ignore boolean to ignore or not.
* @return the AxeConf instance.
*/
public AxeConf ignore(final String ruleId, final boolean ignore) {
rules.get(ruleId).ignored = ignore;
Expand Down Expand Up @@ -209,19 +220,21 @@ public AxeConf removeStandard(@AxeStandard String standard) {

private void normalize() {
// Make sure that all RulesIDs were trying to run are classes we have access to.
ruleIds.forEach(s -> {
if (!rules.containsKey(s)) {
for (String ruleId : ruleIds) {
if (!rules.containsKey(ruleId)) {
throw new RuntimeException("Tried to run a RuleID that doesn't exist.");
}
});
}

// Make sure that the RuleIDs list matches the rules data structure.
ruleIds.clear();
rules.forEach((s, ruleConf) -> {
for (Map.Entry<String, RuleConf> entry : rules.entrySet()) {
String s = entry.getKey();
RuleConf ruleConf = entry.getValue();
if (!ruleConf.ignored) {
ruleIds.add(s);
}
});
}
}

Set<AxeRule> ruleInstances() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/deque/axe/android/AxeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ public String getScreenTitle() {

final StringBuilder result = new StringBuilder();

contentView.children.forEach(axeView -> {
for (AxeView axeView : contentView.children) {
if (result.length() == 0
&& axeView.viewIdResourceName != null
&& !"null".equals(axeView.viewIdResourceName)) {
result.append(axeView.viewIdResourceName);
}
});
}

return result.toString();
}
Expand Down

0 comments on commit 2b56372

Please sign in to comment.