1 | /* $Id: PgmlUtility.java 19614 2011-07-20 12:10:13Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2005-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.persistence; | |
40 | ||
41 | import java.util.ArrayList; | |
42 | import java.util.Collection; | |
43 | import java.util.Iterator; | |
44 | import java.util.List; | |
45 | ||
46 | import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote; | |
47 | import org.argouml.uml.diagram.ui.FigEdgeAssociationClass; | |
48 | import org.tigris.gef.base.Diagram; | |
49 | import org.tigris.gef.base.Layer; | |
50 | import org.tigris.gef.presentation.Fig; | |
51 | import org.tigris.gef.presentation.FigEdge; | |
52 | import org.tigris.gef.presentation.FigGroup; | |
53 | ||
54 | /** | |
55 | * Utility class for use by pgml.tee. | |
56 | * | |
57 | * @author Bob Tarling | |
58 | */ | |
59 | public final class PgmlUtility { | |
60 | ||
61 | /** | |
62 | * Constructor. | |
63 | */ | |
64 | private PgmlUtility() { | |
65 | } | |
66 | | |
67 | /** | |
68 | * Translate the visibility flag of a Fig to the PGML "visibility" attribute | |
69 | * value. | |
70 | * The PGML values are 0=hidden and 1=shown. | |
71 | * If not specified then 1 is the default so we return null for this to | |
72 | * prevent redundent data being written to PGML. | |
73 | * TODO: Remove on GEF release after 0.11.9 as it will be provided there. | |
74 | * | |
75 | * @param f The Fig | |
76 | * @return "0"=hidden, null=shown | |
77 | */ | |
78 | public static String getVisibility(Fig f) { | |
79 |
1
1. getVisibility : negated conditional → NO_COVERAGE |
if (f.isVisible()) { |
80 |
1
1. getVisibility : mutated return of Object value for org/argouml/persistence/PgmlUtility::getVisibility to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
81 | } | |
82 |
1
1. getVisibility : mutated return of Object value for org/argouml/persistence/PgmlUtility::getVisibility to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "0"; |
83 | } | |
84 | | |
85 | /** | |
86 | * Return just the comment edges for a specific layer. | |
87 | * TODO: Document: Diagram / layer? | |
88 | * | |
89 | * @param diagram The diagram. | |
90 | * @return a {@link List} with the edges. | |
91 | */ | |
92 | public static List getEdges(Diagram diagram) { | |
93 | Layer lay = diagram.getLayer(); | |
94 | Collection edges = lay.getContentsEdgesOnly(); | |
95 | List returnEdges = new ArrayList(edges.size()); | |
96 |
1
1. getEdges : removed call to org/argouml/persistence/PgmlUtility::getEdges → NO_COVERAGE |
getEdges(diagram, edges, returnEdges); |
97 |
1
1. getEdges : mutated return of Object value for org/argouml/persistence/PgmlUtility::getEdges to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return returnEdges; |
98 | } | |
99 | ||
100 | /** | |
101 | * Return the diagram contents in the order to save to PGML | |
102 | * Nodes first, then edges connecting nodes and lastly | |
103 | * edges that connect edges to other edges. | |
104 | * | |
105 | * @param diagram The {@link Diagram}. | |
106 | * @return a {@link List} with the contents. | |
107 | */ | |
108 | public static List getContents(Diagram diagram) { | |
109 | Layer lay = diagram.getLayer(); | |
110 | List contents = lay.getContents(); | |
111 | int size = contents.size(); | |
112 | List list = new ArrayList(size); | |
113 |
3
1. getContents : changed conditional boundary → NO_COVERAGE 2. getContents : Changed increment from 1 to -1 → NO_COVERAGE 3. getContents : negated conditional → NO_COVERAGE |
for (int i = 0; i < size; i++) { |
114 | Object o = contents.get(i); | |
115 |
1
1. getContents : negated conditional → NO_COVERAGE |
if (!(o instanceof FigEdge)) { |
116 | list.add(o); | |
117 | } | |
118 | } | |
119 |
1
1. getContents : removed call to org/argouml/persistence/PgmlUtility::getEdges → NO_COVERAGE |
getEdges(diagram, lay.getContentsEdgesOnly(), list); |
120 |
1
1. getContents : mutated return of Object value for org/argouml/persistence/PgmlUtility::getContents to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return list; |
121 | } | |
122 | | |
123 | private static void getEdges(Diagram diagram, | |
124 | Collection edges, List returnEdges) { | |
125 | Iterator it = edges.iterator(); | |
126 |
1
1. getEdges : negated conditional → NO_COVERAGE |
while (it.hasNext()) { |
127 | Object o = it.next(); | |
128 |
1
1. getEdges : negated conditional → NO_COVERAGE |
if (!(o instanceof FigEdgeNote) |
129 |
1
1. getEdges : negated conditional → NO_COVERAGE |
&& !(o instanceof FigEdgeAssociationClass)) { |
130 | returnEdges.add(o); | |
131 | } | |
132 | } | |
133 | it = edges.iterator(); | |
134 |
1
1. getEdges : negated conditional → NO_COVERAGE |
while (it.hasNext()) { |
135 | Object o = it.next(); | |
136 |
1
1. getEdges : negated conditional → NO_COVERAGE |
if (o instanceof FigEdgeAssociationClass) { |
137 | returnEdges.add(o); | |
138 | } | |
139 | } | |
140 | it = edges.iterator(); | |
141 |
1
1. getEdges : negated conditional → NO_COVERAGE |
while (it.hasNext()) { |
142 | Object o = it.next(); | |
143 |
1
1. getEdges : negated conditional → NO_COVERAGE |
if (o instanceof FigEdgeNote) { |
144 | returnEdges.add(o); | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
149 | /** | |
150 | * Return the identifier for this Fig which is the encloser | |
151 | * of the given Fig | |
152 | * @param f the Fig to generate the id for | |
153 | * @return a unique string | |
154 | */ | |
155 | public static String getEnclosingId(Fig f) { | |
156 | | |
157 | Fig encloser = f.getEnclosingFig(); | |
158 | | |
159 |
1
1. getEnclosingId : negated conditional → NO_COVERAGE |
if (encloser == null) { |
160 |
1
1. getEnclosingId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getEnclosingId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
161 | } | |
162 | | |
163 |
1
1. getEnclosingId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getEnclosingId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getId(encloser); |
164 | } | |
165 | ||
166 | ||
167 | /** | |
168 | * Generate an identifier for this Fig which is unique within the | |
169 | * diagram. | |
170 | * @param f the Fig to generate the id for | |
171 | * @return a unique string | |
172 | */ | |
173 | public static String getId(Fig f) { | |
174 |
1
1. getId : negated conditional → NO_COVERAGE |
if (f == null) { |
175 | throw new IllegalArgumentException("A fig must be supplied"); | |
176 | } | |
177 |
1
1. getId : negated conditional → NO_COVERAGE |
if (f.getGroup() != null) { |
178 | String groupId = f.getGroup().getId(); | |
179 |
1
1. getId : negated conditional → NO_COVERAGE |
if (f.getGroup() instanceof FigGroup) { |
180 | FigGroup group = (FigGroup) f.getGroup(); | |
181 |
1
1. getId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return groupId + "." + (group.getFigs()).indexOf(f); |
182 |
1
1. getId : negated conditional → NO_COVERAGE |
} else if (f.getGroup() instanceof FigEdge) { |
183 | FigEdge edge = (FigEdge) f.getGroup(); | |
184 |
1
1. getId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return groupId + "." |
185 |
1
1. getId : Replaced integer addition with subtraction → NO_COVERAGE |
+ (((List) edge.getPathItemFigs()).indexOf(f) + 1); |
186 | } else { | |
187 |
1
1. getId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return groupId + ".0"; |
188 | } | |
189 | } | |
190 | ||
191 | Layer layer = f.getLayer(); | |
192 |
1
1. getId : negated conditional → NO_COVERAGE |
if (layer == null) { |
193 |
1
1. getId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "LAYER_NULL"; |
194 | } | |
195 | ||
196 | List c = layer.getContents(); | |
197 | int index = c.indexOf(f); | |
198 |
1
1. getId : mutated return of Object value for org/argouml/persistence/PgmlUtility::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "Fig" + index; |
199 | } | |
200 | ||
201 | } | |
Mutations | ||
79 |
1.1 |
|
80 |
1.1 |
|
82 |
1.1 |
|
96 |
1.1 |
|
97 |
1.1 |
|
113 |
1.1 2.2 3.3 |
|
115 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
126 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
134 |
1.1 |
|
136 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
163 |
1.1 |
|
174 |
1.1 |
|
177 |
1.1 |
|
179 |
1.1 |
|
181 |
1.1 |
|
182 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
187 |
1.1 |
|
192 |
1.1 |
|
193 |
1.1 |
|
198 |
1.1 |