View Javadoc
1 /* Segment.java */ 2 3 package org.quilt.cover.seg; 4 5 import java.util.Iterator; 6 import java.util.List; 7 8 /*** 9 * A segment for coverage purposes. It has an index and visit count, 10 * and 'from' and 'to', which will typically be line numbers or indices 11 * of some sort. 12 */ 13 14 public class Segment { 15 16 /*** ideally unique */ 17 private int index = -1; 18 /*** visit count */ 19 private int visits = 0; 20 /*** index, line number, etc */ 21 private int from = -1; 22 private int to = -1; 23 24 /*** No-arg constructor; creates a segment with -1 index. */ 25 public Segment() { 26 } 27 /*** 28 * Constructor specifying a segment index. 29 * 30 * @param n The index; should be non-negative. 31 */ 32 33 public Segment (int n) { 34 index = n; 35 } 36 // GET/SET METHODS ////////////////////////////////////////////// 37 /*** Get the 'from' value. */ 38 public int getFrom() { 39 return from; 40 } 41 /*** Set the 'from' value. */ 42 public void setFrom (int n) { 43 from = n; 44 } 45 46 /*** Get the (ideally unique) index of the segment. */ 47 public int getIndex() { 48 return index; 49 } 50 /*** Set the segment index. */ 51 public void setIndex (int n) { 52 index = n; 53 } 54 55 /*** Get the 'to' value. */ 56 public int getTo() { 57 return to; 58 } 59 /*** Set the 'to' value. */ 60 public void setTo (int n) { 61 to = n; 62 } 63 64 /*** Get the number of visits so far. */ 65 public int getVisits() { 66 return visits; 67 } 68 /*** Set the number of visits to zero. */ 69 public void reset() { 70 visits = 0; 71 } 72 /*** Set the number of visits; may never be used. */ 73 public void setVisits(int n) { 74 visits = n; 75 } 76 // OTHER METHODS //////////////////////////////////////////////// 77 /*** 78 * Add the visit count from another segment. 79 * 80 * @param seg Reference to the other segment. 81 */ 82 protected Segment add( final Segment seg ) { 83 visits += seg.getVisits(); 84 return this; 85 } 86 /*** Step the visit count. */ 87 public void visit () { 88 visits++; 89 } 90 /*** 91 * Format the segment for XML output. 92 * 93 * @param type String whose value is appropriate for an XML element name. 94 */ 95 public String toXML(final String type) { 96 return "<" + type + " index=\"" + index 97 + "\" from=\"" + from 98 + "\" to=\"" + to + "\">\n" 99 100 + " <visits>" + visits + "</visits>\n" 101 102 + "</" + type + ">\n"; 103 } 104 /*** Format the segment for output as a String. */ 105 public String toString () { 106 return "segment " + index + ": " + from + " --> " + to 107 + " : " + visits + " visits"; 108 } 109 }

This page was automatically generated by Maven