1 6 package de.uka.ipd.coverage.recording; 7 8 import java.io.Serializable ; 9 10 22 27 public class CoverageState implements Comparable , Serializable { 28 29 protected static final int FULL = 10; 30 protected static final int PARTIAL = 5; 31 protected static final int NONE = 0; 32 33 public static final CoverageState FULL_COVERAGE = new CoverageState(FULL); 34 public static final CoverageState PARTIAL_COVERAGE = new CoverageState(PARTIAL); 35 public static final CoverageState NO_COVERAGE = new CoverageState(NONE); 36 37 38 protected int state; 39 40 41 private CoverageState(int state) { 42 this.state = state; 43 } 44 45 public String toString() { 46 String stateString = ""; if (this.state == FULL) { 48 stateString = "FULL_COVERAGE"; } else if (this.state == PARTIAL) { 50 stateString = "PARTIAL_COVERAGE"; } else if (this.state == NONE) { 52 stateString = "NO_COVERAGE"; } 54 return stateString; 55 } 56 57 60 public int compareTo(Object anotherCoverageState) { 61 if (!(anotherCoverageState instanceof CoverageState)) { 62 throw new IllegalArgumentException ("Can only compare " + "CoverageState objects"); } 65 CoverageState obj = (CoverageState) anotherCoverageState; 66 return new Integer (this.state).compareTo(new Integer (obj.state)); 67 } 68 69 public boolean isGreaterThan(CoverageState comp) { 70 if (this.compareTo(comp) > 0) { 71 return true; 72 } 73 return false; 74 } 75 76 84 public static CoverageState mergeCoverages(CoverageState state1, CoverageState state2) { 85 CoverageState result = null; 87 if (state1.equals(CoverageState.NO_COVERAGE) 88 && state2.equals(CoverageState.NO_COVERAGE)) { 89 result = CoverageState.NO_COVERAGE; 90 } else if (state1.equals(CoverageState.FULL_COVERAGE) 91 && state2.equals(CoverageState.FULL_COVERAGE)) { 92 result = CoverageState.FULL_COVERAGE; 93 } else { 94 result = CoverageState.PARTIAL_COVERAGE; 95 } 96 return result; 97 } 98 99 } 100 | Popular Tags |