Skip to main content
summaryrefslogtreecommitdiffstats
blob: 29fb0bbffecdc2bca5cab2ba2e1d0aadb187607b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Created on Jan 2, 2010
 *
 * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
 */
package org.eclipse.osee.coverage.model;

import java.util.Collection;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.HashCollection;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Strings;

/**
 * Simple provider that optimizes how test units are stored by sharing test unit names.
 * 
 * @author Donald G. Dunne
 */
public class SimpleTestUnitProvider implements ITestUnitProvider {

   // Since test units will cover many coverage items (sometimes thousands), it is more cost effective
   // to store single test script name shared by use of string.intern() rather than
   // create a new string for each coverage item.
   final HashCollection<CoverageItem, String> coverageItemToTestUnits = new HashCollection<CoverageItem, String>(1000);

   public SimpleTestUnitProvider() {
   }

   @Override
   public void addTestUnit(CoverageItem coverageItem, String testUnitName) throws OseeCoreException {
      if (!getTestUnits(coverageItem).contains(testUnitName)) {
         coverageItemToTestUnits.put(coverageItem, Strings.intern(testUnitName));
      }
   }

   @Override
   public Collection<String> getTestUnits(CoverageItem coverageItem) throws OseeCoreException {
      if (coverageItemToTestUnits.containsKey(coverageItem)) {
         return coverageItemToTestUnits.getValues(coverageItem);
      }
      return java.util.Collections.emptyList();
   }

   @Override
   public String toXml(CoverageItem coverageItem) throws OseeCoreException {
      return Collections.toString(";", getTestUnits(coverageItem));
   }

   @Override
   public void fromXml(CoverageItem coverageItem, String testUnitNames) throws OseeCoreException {
      if (Strings.isValid(testUnitNames)) {
         for (String testName : testUnitNames.split(";")) {
            addTestUnit(coverageItem, testName);
         }
      }
   }

   @Override
   public void setTestUnits(CoverageItem coverageItem, Collection<String> testUnitNames) throws OseeCoreException {
      coverageItemToTestUnits.removeValues(coverageItem);
      for (String testUnitName : testUnitNames) {
         addTestUnit(coverageItem, testUnitName);
      }
   }

   @Override
   public void removeTestUnit(CoverageItem coverageItem, String testUnitName) throws OseeCoreException {
      coverageItemToTestUnits.removeValue(coverageItem, testUnitName);
   }

}

Back to the top