All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.internal.ResultMap Maven / Gradle / Ivy

There is a newer version: 7.10.2
Show newest version
package org.testng.internal;

import org.testng.IResultMap;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.collections.Objects;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class ResultMap implements IResultMap {
  /**
   *
   */
  private static final long serialVersionUID = 80134376515999093L;
  private Map m_map = new ConcurrentHashMap<>();

  @Override
  public void addResult(ITestResult result, ITestNGMethod method) {
    m_map.put(result, method);
  }

  @Override
  public Set getResults(ITestNGMethod method) {
    Set result = new HashSet<>();

    for (Map.Entry entry : m_map.entrySet()) {
      if (entry.getValue().equals(method)) {
        result.add(entry.getKey());
      }
    }

    return result;
  }

  @Override
  public void removeResult(ITestNGMethod m) {
    for (Entry entry : m_map.entrySet()) {
      if (entry.getValue().equals(m)) {
        m_map.remove(entry.getKey());
        return;
      }
    }
  }

  @Override
  public void removeResult(ITestResult r) {
    m_map.remove(r);
  }

  @Override
  public Set getAllResults() {
    return m_map.keySet();
  }

  @Override
  public int size() {
    return m_map.size();
  }

  @Override
  public Collection getAllMethods() {
    return m_map.values();
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(getClass())
        .add("map", m_map)
        .toString();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy