View Javadoc

1   /*
2    * Copyright 2010-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.testdoc.report.index;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import net.jcip.annotations.NotThreadSafe;
23  import de.smartics.testdoc.core.doc.UnitTestDoc;
24  
25  /**
26   * Provides means to handle multiple export indexes.
27   *
28   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
29   * @version $Revision:591 $
30   */
31  @NotThreadSafe
32  public class ExportMultiIndex implements ExportIndex
33  {
34    // ********************************* Fields *********************************
35  
36    // --- constants ------------------------------------------------------------
37  
38    /**
39     * The class version identifier.
40     * <p>
41     * The value of this constant is {@value}.
42     * </p>
43     */
44    private static final long serialVersionUID = 1L;
45  
46    /**
47     * The name of the section generated by this index.
48     * <p>
49     * The value of this constant is {@value}.
50     * </p>
51     */
52    public static final String SECTION_NAME = "allSections";
53  
54    // --- members --------------------------------------------------------------
55  
56    /**
57     * The list of indexes the multi index cares for.
58     */
59    private final List<ExportIndex> indexes = new ArrayList<ExportIndex>();
60  
61    // ****************************** Initializer *******************************
62  
63    // ****************************** Constructors ******************************
64  
65    /**
66     * Default constructor.
67     */
68    public ExportMultiIndex()
69    {
70    }
71  
72    // ****************************** Inner Classes *****************************
73  
74    // ********************************* Methods ********************************
75  
76    // --- init -----------------------------------------------------------------
77  
78    // --- get&set --------------------------------------------------------------
79  
80    /**
81     * {@inheritDoc}
82     *
83     * @see de.smartics.testdoc.report.index.ExportIndex#getSectionName()
84     */
85    @Override
86    public String getSectionName()
87    {
88      return SECTION_NAME;
89    }
90  
91    // --- business -------------------------------------------------------------
92  
93    /**
94     * Adds the given index to the list of indexes.
95     *
96     * @param index the index to be added.
97     */
98    public void addIndex(final ExportIndex index)
99    {
100     indexes.add(index);
101   }
102 
103   /**
104    * {@inheritDoc}
105    *
106    * @see de.smartics.testdoc.report.index.ExportIndex#addToIndex(de.smartics.testdoc.core.doc.UnitTestDoc)
107    */
108   public void addToIndex(final UnitTestDoc testDoc)
109   {
110     for (final ExportIndex index : indexes)
111     {
112       index.addToIndex(testDoc);
113     }
114   }
115 
116   /**
117    * Returns a reference to an unmodifiable instance of the list of indexes.
118    *
119    * @return the list of indexes.
120    */
121   public List<ExportIndex> getIndexes()
122   {
123     return Collections.unmodifiableList(indexes);
124   }
125 
126   /**
127    * {@inheritDoc}
128    * <p>
129    * Returns the sections of all its indexes as subsections.
130    * </p>
131    *
132    * @see de.smartics.testdoc.report.index.ExportIndex#getSection()
133    */
134   @Override
135   public Section<UnitTestDoc> getSection()
136   {
137     final Section<UnitTestDoc> section =
138         new StaticSection<UnitTestDoc>(getSectionName());
139     for (final ExportIndex index : indexes)
140     {
141       final Section<UnitTestDoc> subSection = index.getSection();
142       section.addSubSection(subSection);
143     }
144     return section;
145   }
146 
147   /**
148    * {@inheritDoc}
149    *
150    * @see de.smartics.testdoc.report.index.ExportIndex#isEmpty()
151    */
152   @Override
153   public boolean isEmpty()
154   {
155     for (final ExportIndex index : indexes)
156     {
157       final boolean empty = index.isEmpty();
158       if(!empty)
159       {
160         return false;
161       }
162     }
163     return true;
164   }
165 
166   // --- object basics --------------------------------------------------------
167 
168 }