Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
41   172   8   6.83
0   96   0.2   6
6     1.33  
1    
 
  ToStringVisitor       Line # 37 41 0% 8 0 100% 1.0
 
  (3)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // ToStringVisitor.java Copyright (c) 2009 Giovanni Azua Garcia
5    // bravegag@hotmail.com
6    //
7    // This program is free software; you can redistribute it and/or
8    // modify it under the terms of the GNU General Public License
9    // as published by the Free Software Foundation; either version 3
10    // of the License, or (at your option) any later version.
11    //
12    // This program is distributed in the hope that it will be useful,
13    // but WITHOUT ANY WARRANTY; without even the implied warranty of
14    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    // GNU General Public License for more details.
16    //
17    // You should have received a copy of the GNU General Public License
18    // along with this program; if not, see <http://www.gnu.org/licenses/>.
19    //
20    //----------------------------------------------------------------------
21    package org.perfectjpattern.example.datamodel.visitor;
22   
23    import java.text.*;
24    import java.util.*;
25   
26    import org.apache.commons.lang.*;
27    import org.perfectjpattern.core.behavioral.visitor.*;
28    import org.perfectjpattern.example.datamodel.*;
29   
30    /**
31    * Visits any data model type and provides generating a String representation
32    *
33    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
34    * @version $ $Date: Dec 6, 2008 6:25:02 PM $
35    */
36    public
 
37    class ToStringVisitor
38    extends AbstractVisitor<Object>
39    {
40    //------------------------------------------------------------------------
41    // public
42    //------------------------------------------------------------------------
 
43  2 toggle public void
44    visitCustomer(Customer aCustomer)
45    {
46  2 Validate.notNull(aCustomer, "'aCustomer' must not be null");
47   
48  2 String myPattern = theBundle.getString(aCustomer.getClass().
49    getSimpleName());
50   
51  2 StringBuilder myResult = new StringBuilder();
52   
53  2 StringBuilder myBuilder = new StringBuilder();
54  2 for (Order myOrder : aCustomer.getOrders())
55    {
56  4 myBuilder.append(LINE_BREAK);
57   
58  4 visit(myOrder);
59  4 myBuilder.append(getResult());
60    }
61   
62  2 myResult.append(LINE_BREAK);
63  2 myResult.append(
64    "**************************************************************");
65  2 myResult.append(LINE_BREAK);
66  2 myResult.append(MessageFormat.format(myPattern, aCustomer.getId(),
67    aCustomer.getName()));
68  2 myResult.append(myBuilder.toString());
69  2 myResult.append(LINE_BREAK);
70  2 myResult.append(
71    "**************************************************************");
72   
73  2 setResult(myResult.toString());
74    }
75   
76    //------------------------------------------------------------------------
 
77  4 toggle public void
78    visitOrder(Order anOrder)
79    {
80  4 Validate.notNull(anOrder, "'anOrder' must not be null");
81   
82  4 String myPattern = theBundle.getString(anOrder.getClass().
83    getSimpleName());
84   
85  4 StringBuilder myBuilder = new StringBuilder();
86  4 for (Product myProduct : anOrder.getProducts())
87    {
88  9 myBuilder.append(LINE_BREAK);
89   
90  9 visit(myProduct);
91  9 myBuilder.append(getResult());
92    }
93   
94  4 StringBuilder myResult = new StringBuilder();
95  4 myResult.append(MessageFormat.format(myPattern, anOrder.getId(),
96    anOrder.getDate()));
97  4 myResult.append(myBuilder.toString());
98   
99  4 setResult(myResult.toString());
100    }
101   
102    //------------------------------------------------------------------------
 
103  9 toggle public void
104    visitProduct(Product aProduct)
105    {
106  9 Validate.notNull(aProduct, "'aProduct' must not be null");
107   
108  9 String myPattern = theBundle.getString(aProduct.getClass().
109    getSimpleName());
110   
111  9 String myResult = MessageFormat.format(myPattern, aProduct.getId(),
112    aProduct.getName(), aProduct.getListPrice());
113   
114  9 setResult(myResult);
115    }
116   
117    //------------------------------------------------------------------------
 
118  4 toggle public void
119    visitMovie(Movie aMovie)
120    {
121  4 Validate.notNull(aMovie, "'aMovie' must not be null");
122   
123  4 String myPattern = theBundle.getString(aMovie.getClass().
124    getSimpleName());
125   
126  4 StringBuilder myResult = new StringBuilder();
127   
128  4 myResult.append(LINE_BREAK);
129  4 myResult.append(
130    "**************************************************************");
131  4 myResult.append(LINE_BREAK);
132  4 myResult.append(MessageFormat.format(myPattern, aMovie.getId(),
133    aMovie.getTitle(), aMovie.getDirector(), aMovie.getYear()));
134   
135  4 setResult(myResult.toString());
136    }
137   
138    //------------------------------------------------------------------------
139    /**
140    * Returns the result
141    *
142    * @return the result
143    */
 
144  19 toggle public final String
145    getResult()
146    {
147  19 return theResult;
148    }
149   
150    //------------------------------------------------------------------------
151    // protected
152    //------------------------------------------------------------------------
153    /**
154    * Sets the result
155    *
156    * @param anResult the result to set
157    */
 
158  19 toggle protected final void
159    setResult(String anResult)
160    {
161  19 theResult = anResult;
162    }
163   
164    //------------------------------------------------------------------------
165    // members
166    //------------------------------------------------------------------------
167    private static final String LINE_BREAK = System.getProperty(
168    "line.separator");
169    private final ResourceBundle theBundle = ResourceBundle.getBundle(
170    getClass().getSimpleName());
171    private String theResult;
172    }