// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheckResult.java
// public enum AccessibilityCheckResultType {
//   /** Clearly an accessibility bug, for example no speakable text on a clicked button */
//   ERROR(ResultTypeProto.ERROR),
//   /**
//    * Potentially an accessibility bug, for example finding another view with the same speakable
//    * text as a clicked view
//    */
//   WARNING(ResultTypeProto.WARNING),
//   /**
//    * Information that may be helpful when evaluating accessibility, for example a listing of all
//    * speakable text in a view hierarchy in the traversal order used by an accessibility service.
//    */
//   INFO(ResultTypeProto.INFO),
//   /**
//    * Indication that a potential issue was identified, but it was resolved as not an accessibility
//    * problem.
//    */
//   RESOLVED(ResultTypeProto.RESOLVED),
//   /** A signal that the check was not run at all (ex. because the API level was too low) */
//   NOT_RUN(ResultTypeProto.NOT_RUN),
//   /**
//    * A result that has been explicitly suppressed from throwing any Exceptions, used to allow for
//    * known issues.
//    */
//   SUPPRESSED(ResultTypeProto.SUPPRESSED);
// 
//   private static final Map<Integer, AccessibilityCheckResultType> PROTO_NUMBER_MAP =
//       new HashMap<>();
// 
//   static {
//     for (AccessibilityCheckResultType type : values()) {
//       PROTO_NUMBER_MAP.put(type.protoNumber, type);
//     }
//   }
// 
//   final int protoNumber;
// 
//   private AccessibilityCheckResultType(ResultTypeProto proto) {
//     this.protoNumber = proto.getNumber();
//   }
// 
//   public static AccessibilityCheckResultType fromProto(ResultTypeProto proto) {
//     AccessibilityCheckResultType type = PROTO_NUMBER_MAP.get(proto.getNumber());
//     checkArgument(
//         (type != null),
//         "Failed to create AccessibilityCheckResultType from proto with unknown value: %s",
//         proto.getNumber());
//     return checkNotNull(type);
//   }
// 
//   public ResultTypeProto toProto() {
//     return ResultTypeProto.forNumber(protoNumber);
//   }
// }


import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
import com.google.common.collect.ImmutableBiMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.apps.common.testing.accessibility.framework;


/**
 * Utility class for dealing with {@code AccessibilityCheckResult}s, without any dependency upon
 * Android classes.
 *
 * <p>This duplicates some of the methods in {@code AccessibilityCheckResultUtils} in order to
 * support separate Android and Java build targets while maintaining API compatibility.
 */
public final class AccessibilityCheckResultBaseUtils {

  private AccessibilityCheckResultBaseUtils() {}

  /**
   * Takes a list of {@code AccessibilityCheckResult}s and returns a list with only results obtained
   * from the given {@code AccessibilityCheck}.
   * <p>
   * NOTE: This method explicitly does not take subtypes of {@code checkClass} into account when
   * filtering results.
   *
   * @param results a list of {@code AccessibilityCheckResult}s
   * @param checkClass the {@code Class} of the {@code AccessibilityCheck} to get results for
   * @return a list of {@code AccessibilityCheckResult}s obtained from the given
   *         {@code AccessibilityCheck}.
   */
  public static <T extends AccessibilityCheckResult> List<T> getResultsForCheck(
      Iterable<T> results, Class<? extends AccessibilityCheck> checkClass) {
    return getResultsForCheck(results, checkClass, /* aliases= */ null);
  }

  /**
   * Takes a list of {@code AccessibilityCheckResult}s and returns a list with only results obtained
   * from the given {@code AccessibilityCheck}. If a BiMap of class aliases is provided, the
   * returned value will also include results obtained from the check class paired with the given
   * class in the BiMap.
   */
  static <T extends AccessibilityCheckResult> List<T> getResultsForCheck(
      Iterable<T> results,
      Class<? extends AccessibilityCheck> checkClass,
      @Nullable ImmutableBiMap<?, ?> aliases) {
    List<T> resultsForCheck = new ArrayList<T>();
    for (T result : results) {
      Class<? extends AccessibilityCheck> resultCheckClass = result.getSourceCheckClass();
      Object alias = getAlias(resultCheckClass, aliases);
      if (checkClass.equals(resultCheckClass) || checkClass.equals(alias)) {
        resultsForCheck.add(result);
      }
    }
    return resultsForCheck;
  }

  /**
   * Filters {@link AccessibilityCheckResult}s and returns a list with only results which match the
   * given {@link AccessibilityCheckResultType}.
   *
   * @param results an {@link Iterable} of {@link AccessibilityCheckResult}s
   * @param type the {@link AccessibilityCheckResultType} for the results to be returned
   * @return a list of {@link AccessibilityCheckResult}s with the given
   *         {@link AccessibilityCheckResultType}.
   */
  public static <T extends AccessibilityCheckResult> List<T> getResultsForType(
// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheckResult.java
// public enum AccessibilityCheckResultType {
//   /** Clearly an accessibility bug, for example no speakable text on a clicked button */
//   ERROR(ResultTypeProto.ERROR),
//   /**
//    * Potentially an accessibility bug, for example finding another view with the same speakable
//    * text as a clicked view
//    */
//   WARNING(ResultTypeProto.WARNING),
//   /**
//    * Information that may be helpful when evaluating accessibility, for example a listing of all
//    * speakable text in a view hierarchy in the traversal order used by an accessibility service.
//    */
//   INFO(ResultTypeProto.INFO),
//   /**
//    * Indication that a potential issue was identified, but it was resolved as not an accessibility
//    * problem.
//    */
//   RESOLVED(ResultTypeProto.RESOLVED),
//   /** A signal that the check was not run at all (ex. because the API level was too low) */
//   NOT_RUN(ResultTypeProto.NOT_RUN),
//   /**
//    * A result that has been explicitly suppressed from throwing any Exceptions, used to allow for
//    * known issues.
//    */
//   SUPPRESSED(ResultTypeProto.SUPPRESSED);
// 
//   private static final Map<Integer, AccessibilityCheckResultType> PROTO_NUMBER_MAP =
//       new HashMap<>();
// 
//   static {
//     for (AccessibilityCheckResultType type : values()) {
//       PROTO_NUMBER_MAP.put(type.protoNumber, type);
//     }
//   }
// 
//   final int protoNumber;
// 
//   private AccessibilityCheckResultType(ResultTypeProto proto) {
//     this.protoNumber = proto.getNumber();
//   }
// 
//   public static AccessibilityCheckResultType fromProto(ResultTypeProto proto) {
//     AccessibilityCheckResultType type = PROTO_NUMBER_MAP.get(proto.getNumber());
//     checkArgument(
//         (type != null),
//         "Failed to create AccessibilityCheckResultType from proto with unknown value: %s",
//         proto.getNumber());
//     return checkNotNull(type);
//   }
// 
//   public ResultTypeProto toProto() {
//     return ResultTypeProto.forNumber(protoNumber);
//   }
// }


// Path: src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheckResultBaseUtils.java
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
import com.google.common.collect.ImmutableBiMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;

/*
 * Copyright (C) 2014 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.apps.common.testing.accessibility.framework;


/**
 * Utility class for dealing with {@code AccessibilityCheckResult}s, without any dependency upon
 * Android classes.
 *
 * <p>This duplicates some of the methods in {@code AccessibilityCheckResultUtils} in order to
 * support separate Android and Java build targets while maintaining API compatibility.
 */
public final class AccessibilityCheckResultBaseUtils {

  private AccessibilityCheckResultBaseUtils() {}

  /**
   * Takes a list of {@code AccessibilityCheckResult}s and returns a list with only results obtained
   * from the given {@code AccessibilityCheck}.
   * <p>
   * NOTE: This method explicitly does not take subtypes of {@code checkClass} into account when
   * filtering results.
   *
   * @param results a list of {@code AccessibilityCheckResult}s
   * @param checkClass the {@code Class} of the {@code AccessibilityCheck} to get results for
   * @return a list of {@code AccessibilityCheckResult}s obtained from the given
   *         {@code AccessibilityCheck}.
   */
  public static <T extends AccessibilityCheckResult> List<T> getResultsForCheck(
      Iterable<T> results, Class<? extends AccessibilityCheck> checkClass) {
    return getResultsForCheck(results, checkClass, /* aliases= */ null);
  }

  /**
   * Takes a list of {@code AccessibilityCheckResult}s and returns a list with only results obtained
   * from the given {@code AccessibilityCheck}. If a BiMap of class aliases is provided, the
   * returned value will also include results obtained from the check class paired with the given
   * class in the BiMap.
   */
  static <T extends AccessibilityCheckResult> List<T> getResultsForCheck(
      Iterable<T> results,
      Class<? extends AccessibilityCheck> checkClass,
      @Nullable ImmutableBiMap<?, ?> aliases) {
    List<T> resultsForCheck = new ArrayList<T>();
    for (T result : results) {
      Class<? extends AccessibilityCheck> resultCheckClass = result.getSourceCheckClass();
      Object alias = getAlias(resultCheckClass, aliases);
      if (checkClass.equals(resultCheckClass) || checkClass.equals(alias)) {
        resultsForCheck.add(result);
      }
    }
    return resultsForCheck;
  }

  /**
   * Filters {@link AccessibilityCheckResult}s and returns a list with only results which match the
   * given {@link AccessibilityCheckResultType}.
   *
   * @param results an {@link Iterable} of {@link AccessibilityCheckResult}s
   * @param type the {@link AccessibilityCheckResultType} for the results to be returned
   * @return a list of {@link AccessibilityCheckResult}s with the given
   *         {@link AccessibilityCheckResultType}.
   */
  public static <T extends AccessibilityCheckResult> List<T> getResultsForType(
      Iterable<T> results, AccessibilityCheckResultType type) {