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.Map;
19 import java.util.TreeMap;
20
21 import de.smartics.testdoc.core.doc.Type;
22 import de.smartics.testdoc.core.doc.UnitTestDoc;
23
24 /**
25 * Generates an index on the names of the UUTs.
26 *
27 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
28 * @version $Revision:591 $
29 */
30 public class UutNameIndex implements ExportIndex
31 {
32 // ********************************* Fields *********************************
33
34 // --- constants ------------------------------------------------------------
35
36 /**
37 * The class version identifier.
38 * <p>
39 * The value of this constant is {@value}.
40 * </p>
41 */
42 private static final long serialVersionUID = 1L;
43
44 /**
45 * The name of the section generated by this index.
46 * <p>
47 * The value of this constant is {@value}.
48 * </p>
49 */
50 public static final String SECTION_NAME = "uutName";
51
52 // --- members --------------------------------------------------------------
53
54 /**
55 * The index is ordered by the natural order of UUT type names.
56 *
57 * @serial
58 */
59 private final Map<String, UnitTestDoc> index =
60 new TreeMap<String, UnitTestDoc>();
61
62 // ****************************** Initializer *******************************
63
64 // ****************************** Constructors ******************************
65
66 /**
67 * Default constructor.
68 */
69 public UutNameIndex()
70 {
71 }
72
73 // ****************************** Inner Classes *****************************
74
75 // ********************************* Methods ********************************
76
77 // --- init -----------------------------------------------------------------
78
79 // --- get&set --------------------------------------------------------------
80
81 /**
82 * {@inheritDoc}
83 *
84 * @see de.smartics.testdoc.report.index.ExportIndex#getSectionName()
85 */
86 @Override
87 public String getSectionName()
88 {
89 return SECTION_NAME;
90 }
91
92 // --- business -------------------------------------------------------------
93
94 /**
95 * {@inheritDoc}
96 *
97 * @see de.smartics.testdoc.report.index.ExportIndex#addToIndex(de.smartics.testdoc.core.doc.UnitTestDoc)
98 */
99 @Override
100 public void addToIndex(final UnitTestDoc testDoc)
101 {
102 final Type type = testDoc.getUutType();
103 final String typeName = type.getTypeName();
104 index.put(typeName, testDoc);
105 }
106
107 /**
108 * {@inheritDoc}
109 *
110 * @see de.smartics.testdoc.report.index.ExportIndex#getSection()
111 */
112 @Override
113 public Section<UnitTestDoc> getSection()
114 {
115 final Section<UnitTestDoc> section =
116 new StaticSection<UnitTestDoc>(getSectionName());
117 for (final UnitTestDoc testDoc : index.values())
118 {
119 section.addItem(testDoc);
120 }
121 return section;
122 }
123
124 /**
125 * {@inheritDoc}
126 *
127 * @see de.smartics.testdoc.report.index.ExportIndex#isEmpty()
128 */
129 @Override
130 public boolean isEmpty()
131 {
132 return index.isEmpty();
133 }
134
135 // --- object basics --------------------------------------------------------
136
137 }