Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.FindingType

LineHitsNoteSource
1  /*
2   * $Id: FindingType.java 1509 2009-06-07 20:14:07Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.report;
34  
35  import java.util.HashMap;
36  import java.util.HashSet;
37  import java.util.Map;
38  import java.util.Set;
39  import java.util.logging.Logger;
40  
41  import org.jcoderz.commons.util.StringUtil;
42  
43  /**
44   * Base class identifies the unique type of a finding.
45   * 
46   * @author Andreas Mandel
47   */
48  public class FindingType
49  {
50100     private static final String CLASSNAME = FindingType.class.getName();
51100     private static final Logger LOGGER = Logger.getLogger(CLASSNAME);
52      private static final Map<String, FindingType>
53100         FINDING_TYPES = new HashMap<String, FindingType>();
54      private static final Set<Origin>
55100         INITIALIZED_FINDING_TYPES = new HashSet<Origin>();
56      private final String mSymbol;
57      private final String mShortText;
58      private final String mDescription;
59  
60  
61      protected FindingType (String symbol, String shortText, String description)
62100     {
63100         mSymbol = symbol.intern();
6475         mShortText 
65              = StringUtil.isNullOrBlank(shortText) ? mSymbol : shortText;
6675         mDescription 
67              = StringUtil.isNullOrBlank(description) ? mShortText : description;
68100         FINDING_TYPES.put(mSymbol, this);
69100     }
70  
71     /**
72      * Retrieves the finding type based on it's symbol. 
73      * @param symbol the symbol to look up.
74      * @return the findings type that holds the given symbol.
75      */
76     public static FindingType fromString (String symbol)
77     {
78        // touch the class to get the static initializer to be called
79100       LazyInit.class.getName();
80  
81100       FindingType result = FINDING_TYPES.get(symbol);
82100       if (result == null)
83        {
840          result = new FindingType(symbol, null, null);
85        }
86100       return result;
87     }
88  
89     /**
90      * Initializes the findings with the given origin.
91      * @param origin the class of findings to be initialized.
92      */
93     public static void initialize (Origin origin)
94     {
950        if (!INITIALIZED_FINDING_TYPES.contains(origin))
96         {
970(1)           INITIALIZED_FINDING_TYPES.add(origin);
980            if (Origin.CHECKSTYLE.equals(origin))
99             {
1000                CheckstyleFindingType.initialize();
101             }
1020            else if (Origin.COVERAGE.equals(origin))
103             {
104                 // No stuff here
105             }
1060            else if (Origin.FINDBUGS.equals(origin))
107             {
1080                FindBugsFindingType.initialize();
109             }
1100            else if (Origin.PMD.equals(origin))
111             {
1120                PmdFindingType.initialize();
113             }
1140            else if (Origin.CPD.equals(origin))
115             {
1160                CpdFindingType.initialize();
117             }
1180            else if (Origin.SYSTEM.equals(origin))
119             {
1200                SystemFindingType.initialize();
121             }
122             else
123             {
1240                GenericReportReader.initialize(origin);
125             }
126         }
1270    }
128     
129     /**
130      * Returns the symbol of this finding type.
131      * @return the symbol of this finding type.
132      */
133     public String getSymbol ()
134     {
1350       return mSymbol;
136     }
137  
138     /**
139      * Returns the short text description of this finding type.
140      * Should be a one liner.
141      * @return the short text description of this finding type.
142      */
143     public String getShortText ()
144     {
1450       return mShortText;
146     }
147  
148     /**
149      * Returns a long description of this finding type. Might 
150      *   contain html markup.
151      * @return the long description of this finding type.
152      */
153     public String getDescription ()
154     {
155100       return mDescription;
156     }
157  
158     /**
159      * Returns the finding type symbol as its string representation.
160      * @return the finding type symbol as its string representation.
161      */
162     public String toString ()
163     {
1640       return mSymbol;
165     }
166  
167     /** {@inheritDoc} */
168     public int hashCode ()
169     {
1700       return mSymbol.hashCode();
171     }
172  
173     /** {@inheritDoc} */
174     public boolean equals (Object o)
175     {
1760       return (o instanceof FindingType)
177                && mSymbol.equals(((FindingType) o).mSymbol);
178     }
179  
1800    protected static class LazyInit
181     {
182        static
183        {
1840           initialize(Origin.CHECKSTYLE);
1850           initialize(Origin.FINDBUGS);
1860           initialize(Origin.PMD);
1870           initialize(Origin.CPD);
1880           initialize(Origin.SYSTEM);
1890       }
190     }
191  }

Findings in this File

w (1) 97 : 0 class org.jcoderz.phoenix.report.FindingType defines static field that appears to allow memory bloat