1 | /* | |
2 | * Copyright 2004 Paulo Soares | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * Contributions by: | |
44 | * Lubos Strapko | |
45 | * | |
46 | * If you didn't download this code from the following link, you should check if | |
47 | * you aren't using an obsolete version: | |
48 | * http://www.lowagie.com/iText/ | |
49 | */ | |
50 | ||
51 | package com.lowagie.text.html.simpleparser; | |
52 | ||
53 | import com.lowagie.text.ElementTags; | |
54 | import java.util.ArrayList; | |
55 | import java.util.HashMap; | |
56 | import java.util.List; | |
57 | import java.util.Map; | |
58 | ||
59 | public class ChainedProperties { | |
60 | ||
61 | public final static int[] fontSizes = {8, 10, 12, 14, 18, 24, 36}; | |
62 | ||
63 | public List<Object[]> chain = new ArrayList<>(); | |
64 | ||
65 | /** Creates a new instance of ChainedProperties */ | |
66 | public ChainedProperties() { | |
67 | } | |
68 | ||
69 | public String getProperty(String key) { | |
70 |
4
1. getProperty : changed conditional boundary → SURVIVED 2. getProperty : Changed increment from -1 to 1 → SURVIVED 3. getProperty : Replaced integer subtraction with addition → KILLED 4. getProperty : negated conditional → KILLED |
for (int k = chain.size() - 1; k >= 0; --k) { |
71 | Object[] obj = chain.get(k); | |
72 | HashMap prop = (HashMap) obj[1]; | |
73 | String ret = (String) prop.get(key); | |
74 |
1
1. getProperty : negated conditional → NO_COVERAGE |
if (ret != null) |
75 |
1
1. getProperty : mutated return of Object value for com/lowagie/text/html/simpleparser/ChainedProperties::getProperty to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ret; |
76 | } | |
77 |
1
1. getProperty : mutated return of Object value for com/lowagie/text/html/simpleparser/ChainedProperties::getProperty to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
78 | } | |
79 | ||
80 | public boolean hasProperty(String key) { | |
81 |
4
1. hasProperty : changed conditional boundary → NO_COVERAGE 2. hasProperty : Changed increment from -1 to 1 → NO_COVERAGE 3. hasProperty : Replaced integer subtraction with addition → NO_COVERAGE 4. hasProperty : negated conditional → NO_COVERAGE |
for (int k = chain.size() - 1; k >= 0; --k) { |
82 | Object[] obj = chain.get(k); | |
83 | HashMap prop = (HashMap) obj[1]; | |
84 |
1
1. hasProperty : negated conditional → NO_COVERAGE |
if (prop.containsKey(key)) |
85 |
1
1. hasProperty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
86 | } | |
87 |
1
1. hasProperty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
88 | } | |
89 | ||
90 | public void addToChain(String key, Map<String, String> prop) { | |
91 | // adjust the font size | |
92 | String value = prop.get(ElementTags.SIZE); | |
93 |
1
1. addToChain : negated conditional → NO_COVERAGE |
if (value != null) { |
94 |
1
1. addToChain : negated conditional → NO_COVERAGE |
if (value.endsWith("pt")) { |
95 | prop.put(ElementTags.SIZE, value.substring(0, | |
96 |
1
1. addToChain : Replaced integer subtraction with addition → NO_COVERAGE |
value.length() - 2)); |
97 | } else { | |
98 | int s = 0; | |
99 |
2
1. addToChain : negated conditional → NO_COVERAGE 2. addToChain : negated conditional → NO_COVERAGE |
if (value.startsWith("+") || value.startsWith("-")) { |
100 | String old = getProperty("basefontsize"); | |
101 |
1
1. addToChain : negated conditional → NO_COVERAGE |
if (old == null) |
102 | old = "12"; | |
103 | float f = Float.parseFloat(old); | |
104 | int c = (int) f; | |
105 |
4
1. addToChain : changed conditional boundary → NO_COVERAGE 2. addToChain : Changed increment from -1 to 1 → NO_COVERAGE 3. addToChain : Replaced integer subtraction with addition → NO_COVERAGE 4. addToChain : negated conditional → NO_COVERAGE |
for (int k = fontSizes.length - 1; k >= 0; --k) { |
106 |
2
1. addToChain : changed conditional boundary → NO_COVERAGE 2. addToChain : negated conditional → NO_COVERAGE |
if (c >= fontSizes[k]) { |
107 | s = k; | |
108 | break; | |
109 | } | |
110 | } | |
111 |
1
1. addToChain : negated conditional → NO_COVERAGE |
int inc = Integer.parseInt(value.startsWith("+") ? value |
112 | .substring(1) : value); | |
113 |
1
1. addToChain : Replaced integer addition with subtraction → NO_COVERAGE |
s += inc; |
114 | } else { | |
115 | try { | |
116 |
1
1. addToChain : Replaced integer subtraction with addition → NO_COVERAGE |
s = Integer.parseInt(value) - 1; |
117 | } catch (NumberFormatException nfe) { | |
118 | s = 0; | |
119 | } | |
120 | } | |
121 |
2
1. addToChain : changed conditional boundary → NO_COVERAGE 2. addToChain : negated conditional → NO_COVERAGE |
if (s < 0) |
122 | s = 0; | |
123 |
2
1. addToChain : changed conditional boundary → NO_COVERAGE 2. addToChain : negated conditional → NO_COVERAGE |
else if (s >= fontSizes.length) |
124 |
1
1. addToChain : Replaced integer subtraction with addition → NO_COVERAGE |
s = fontSizes.length - 1; |
125 | prop.put(ElementTags.SIZE, Integer.toString(fontSizes[s])); | |
126 | } | |
127 | } | |
128 | chain.add(new Object[] { key, prop }); | |
129 | } | |
130 | ||
131 | public void removeChain(String key) { | |
132 |
4
1. removeChain : changed conditional boundary → NO_COVERAGE 2. removeChain : Changed increment from -1 to 1 → NO_COVERAGE 3. removeChain : Replaced integer subtraction with addition → NO_COVERAGE 4. removeChain : negated conditional → NO_COVERAGE |
for (int k = chain.size() - 1; k >= 0; --k) { |
133 |
1
1. removeChain : negated conditional → NO_COVERAGE |
if (key.equals(chain.get(k)[0])) { |
134 | chain.remove(k); | |
135 | return; | |
136 | } | |
137 | } | |
138 | } | |
139 | } | |
Mutations | ||
70 |
1.1 2.2 3.3 4.4 |
|
74 |
1.1 |
|
75 |
1.1 |
|
77 |
1.1 |
|
81 |
1.1 2.2 3.3 4.4 |
|
84 |
1.1 |
|
85 |
1.1 |
|
87 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
96 |
1.1 |
|
99 |
1.1 2.2 |
|
101 |
1.1 |
|
105 |
1.1 2.2 3.3 4.4 |
|
106 |
1.1 2.2 |
|
111 |
1.1 |
|
113 |
1.1 |
|
116 |
1.1 |
|
121 |
1.1 2.2 |
|
123 |
1.1 2.2 |
|
124 |
1.1 |
|
132 |
1.1 2.2 3.3 4.4 |
|
133 |
1.1 |