001: /*
002: * @(#)AnalysisMetaDataIO.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.datastore;
028:
029: import java.io.IOException;
030: import java.io.Reader;
031: import java.io.Writer;
032:
033: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
034:
035: /**
036: * Knows how to read and write an IAnalysisMetaData object.
037: *
038: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
039: * @version $Date: 2004/04/15 05:48:25 $
040: * @since December 15, 2002
041: */
042: class AnalysisMetaDataIO {
043: public AnalysisMetaDataIO() {
044: // do nothing
045: }
046:
047: private static class StaleAnalysisMetaData implements
048: IAnalysisMetaData {
049: private String covered;
050: private String notCovered;
051: private byte weight;
052:
053: public StaleAnalysisMetaData(String c, String n, byte w) {
054: this .covered = c;
055: this .notCovered = n;
056: this .weight = w;
057: }
058:
059: public String getCoveredFormattedText() {
060: return this .covered;
061: }
062:
063: public String getNotCoveredFormattedText() {
064: return this .notCovered;
065: }
066:
067: public byte getInstructionWeight() {
068: return this .weight;
069: }
070: }
071:
072: public void writeAnalysisMetaData(IAnalysisMetaData ams, Writer out)
073: throws IOException {
074: StringBuffer sb = new StringBuffer();
075:
076: sb.append(ams.getCoveredFormattedText().length()).append(':')
077: .append(ams.getCoveredFormattedText()).append(',')
078: .append(ams.getNotCoveredFormattedText().length())
079: .append(':').append(ams.getNotCoveredFormattedText())
080: .append(',').append(ams.getInstructionWeight()).append(
081: ',');
082:
083: out.write(sb.toString());
084: }
085:
086: public IAnalysisMetaData readAnalysisMetaData(Reader in)
087: throws IOException {
088: int count = ReadUtil.toInt(ReadUtil.readTo(in, ':'));
089: String covered = ReadUtil.readCount(in, count);
090: ReadUtil.readTo(in, ',');
091:
092: count = ReadUtil.toInt(ReadUtil.readTo(in, ':'));
093: String notCovered = ReadUtil.readCount(in, count);
094: ReadUtil.readTo(in, ',');
095:
096: int iweight = ReadUtil.toInt(ReadUtil.readTo(in, ','));
097:
098: return new StaleAnalysisMetaData(covered, notCovered,
099: (byte) iweight);
100: }
101: }
|