KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > datastore > AnalysisMetaDataIO


1 /*
2  * @(#)AnalysisMetaDataIO.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.datastore;
28
29 import java.io.IOException JavaDoc;
30 import java.io.Reader JavaDoc;
31 import java.io.Writer JavaDoc;
32
33 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
34
35 /**
36  * Knows how to read and write an IAnalysisMetaData object.
37  *
38  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
39  * @version $Date: 2004/04/15 05:48:25 $
40  * @since December 15, 2002
41  */

42 class AnalysisMetaDataIO
43 {
44     public AnalysisMetaDataIO()
45     {
46         // do nothing
47
}
48     
49     
50     private static class StaleAnalysisMetaData implements IAnalysisMetaData
51     {
52         private String JavaDoc covered;
53         private String JavaDoc notCovered;
54         private byte weight;
55         
56         public StaleAnalysisMetaData( String JavaDoc c, String JavaDoc n, byte w )
57         {
58             this.covered = c;
59             this.notCovered = n;
60             this.weight = w;
61         }
62         
63         public String JavaDoc getCoveredFormattedText() { return this.covered; }
64         public String JavaDoc getNotCoveredFormattedText() { return this.notCovered; }
65         public byte getInstructionWeight() { return this.weight; }
66     }
67     
68     public void writeAnalysisMetaData( IAnalysisMetaData ams, Writer JavaDoc out )
69             throws IOException JavaDoc
70     {
71         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
72         
73         sb.append( ams.getCoveredFormattedText().length() ).
74             append( ':' ).
75             append( ams.getCoveredFormattedText() ).
76             append( ',' ).
77             append( ams.getNotCoveredFormattedText().length() ).
78             append( ':' ).
79             append( ams.getNotCoveredFormattedText() ).
80             append( ',' ).
81             append( ams.getInstructionWeight() ).
82             append( ',' );
83         
84         out.write( sb.toString() );
85     }
86     
87     
88     public IAnalysisMetaData readAnalysisMetaData( Reader JavaDoc in )
89             throws IOException JavaDoc
90     {
91         int count = ReadUtil.toInt(
92             ReadUtil.readTo( in, ':' ) );
93         String JavaDoc covered = ReadUtil.readCount( in, count );
94         ReadUtil.readTo( in, ',' );
95         
96         count = ReadUtil.toInt(
97             ReadUtil.readTo( in, ':' ) );
98         String JavaDoc notCovered = ReadUtil.readCount( in, count );
99         ReadUtil.readTo( in, ',' );
100         
101         int iweight = ReadUtil.toInt(
102             ReadUtil.readTo( in, ',' ) );
103         
104         return new StaleAnalysisMetaData( covered, notCovered, (byte)iweight );
105     }
106 }
107
108
Popular Tags