Phrase.java

1
/*
2
 * $Id: Phrase.java 4065 2009-09-16 23:09:11Z psoares33 $
3
 *
4
 * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text;
51
52
import java.util.ArrayList;
53
import java.util.Collection;
54
55
import com.lowagie.text.error_messages.MessageLocalization;
56
57
import com.lowagie.text.pdf.HyphenationEvent;
58
59
/**
60
 * A <CODE>Phrase</CODE> is a series of <CODE>Chunk</CODE>s.
61
 * <P>
62
 * A <CODE>Phrase</CODE> has a main <CODE>Font</CODE>, but some chunks
63
 * within the phrase can have a <CODE>Font</CODE> that differs from the
64
 * main <CODE>Font</CODE>. All the <CODE>Chunk</CODE>s in a <CODE>Phrase</CODE>
65
 * have the same <CODE>leading</CODE>.
66
 * <P>
67
 * Example:
68
 * <BLOCKQUOTE><PRE>
69
 * // When no parameters are passed, the default leading = 16
70
 * <STRONG>Phrase phrase0 = new Phrase();</STRONG>
71
 * <STRONG>Phrase phrase1 = new Phrase("this is a phrase");</STRONG>
72
 * // In this example the leading is passed as a parameter
73
 * <STRONG>Phrase phrase2 = new Phrase(16, "this is a phrase with leading 16");</STRONG>
74
 * // When a Font is passed (explicitly or embedded in a chunk), the default leading = 1.5 * size of the font
75
 * <STRONG>Phrase phrase3 = new Phrase("this is a phrase with a red, normal font Courier, size 12", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, new Color(255, 0, 0)));</STRONG>
76
 * <STRONG>Phrase phrase4 = new Phrase(new Chunk("this is a phrase"));</STRONG>
77
 * <STRONG>Phrase phrase5 = new Phrase(18, new Chunk("this is a phrase", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));</STRONG>
78
 * </PRE></BLOCKQUOTE>
79
 *
80
 * @see        Element
81
 * @see        Chunk
82
 * @see        Paragraph
83
 * @see        Anchor
84
 */
85
86
public class Phrase extends ArrayList implements TextElementArray {
87
88
    // constants
89
    private static final long serialVersionUID = 2643594602455068231L;
90
91
    // membervariables
92
    /** This is the leading of this phrase. */
93
    protected float leading = Float.NaN;
94
95
    /** This is the font of this phrase. */
96
    protected Font font;
97
98
    /** Null, unless the Phrase has to be hyphenated.
99
     * @since    2.1.2
100
     */
101
    protected HyphenationEvent hyphenation = null;
102
103
    // constructors
104
105
    /**
106
     * Constructs a <CODE>Phrase</CODE> without specifying a leading.
107
     */
108
    public Phrase() {
109
        this(16);
110
    }
111
112
    /**
113
     * Copy constructor for <CODE>Phrase</CODE>.
114
     */
115
    public Phrase(Phrase phrase) {
116
        super();
117
        this.addAll(phrase);
118
        leading = phrase.getLeading();
119
        font = phrase.getFont();
120 1 1. : removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE
        setHyphenation(phrase.getHyphenation());
121
    }
122
123
    /**
124
     * Constructs a <CODE>Phrase</CODE> with a certain leading.
125
     *
126
     * @param    leading        the leading
127
     */
128
    public Phrase(float leading) {
129
        this.leading = leading;
130
        font = new Font();
131
    }
132
133
    /**
134
     * Constructs a <CODE>Phrase</CODE> with a certain <CODE>Chunk</CODE>.
135
     *
136
     * @param    chunk        a <CODE>Chunk</CODE>
137
     */
138
    public Phrase(Chunk chunk) {
139
        super.add(chunk);
140
        font = chunk.getFont();
141 1 1. : removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE
        setHyphenation(chunk.getHyphenation());
142
    }
143
144
    /**
145
     * Constructs a <CODE>Phrase</CODE> with a certain <CODE>Chunk</CODE>
146
     * and a certain leading.
147
     *
148
     * @param    leading    the leading
149
     * @param    chunk        a <CODE>Chunk</CODE>
150
     */
151
    public Phrase(float leading, Chunk chunk) {
152
        this.leading = leading;
153
        super.add(chunk);
154
        font = chunk.getFont();
155 1 1. : removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE
        setHyphenation(chunk.getHyphenation());
156
    }
157
158
    /**
159
     * Constructs a <CODE>Phrase</CODE> with a certain <CODE>String</CODE>.
160
     *
161
     * @param    string        a <CODE>String</CODE>
162
     */
163
    public Phrase(String string) {
164
        this(Float.NaN, string, new Font());
165
    }
166
167
    /**
168
     * Constructs a <CODE>Phrase</CODE> with a certain <CODE>String</CODE> and a certain <CODE>Font</CODE>.
169
     *
170
     * @param    string        a <CODE>String</CODE>
171
     * @param    font        a <CODE>Font</CODE>
172
     */
173
    public Phrase(String string, Font font) {
174
        this(Float.NaN, string, font);
175
    }
176
177
    /**
178
     * Constructs a <CODE>Phrase</CODE> with a certain leading and a certain <CODE>String</CODE>.
179
     *
180
     * @param    leading    the leading
181
     * @param    string        a <CODE>String</CODE>
182
     */
183
    public Phrase(float leading, String string) {
184
        this(leading, string, new Font());
185
    }
186
187
    /**
188
     * Constructs a <CODE>Phrase</CODE> with a certain leading, a certain <CODE>String</CODE>
189
     * and a certain <CODE>Font</CODE>.
190
     *
191
     * @param    leading    the leading
192
     * @param    string        a <CODE>String</CODE>
193
     * @param    font        a <CODE>Font</CODE>
194
     */
195
    public Phrase(float leading, String string, Font font) {
196
        this.leading = leading;
197
        this.font = font;
198
        /* bugfix by August Detlefsen */
199 2 1. : negated conditional → NO_COVERAGE
2. : negated conditional → NO_COVERAGE
        if (string != null && string.length() != 0) {
200
            super.add(new Chunk(string, font));
201
        }
202
    }
203
204
    // implementation of the Element-methods
205
206
    /**
207
     * Processes the element by adding it (or the different parts) to an
208
     * <CODE>ElementListener</CODE>.
209
     *
210
     * @param    listener    an <CODE>ElementListener</CODE>
211
     * @return    <CODE>true</CODE> if the element was processed successfully
212
     */
213
    public boolean process(ElementListener listener) {
214
        try {
215
            for (Object o : this) {
216
                listener.add((Element) o);
217
            }
218 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return true;
219
        }
220
        catch(DocumentException de) {
221 1 1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
222
        }
223
    }
224
225
    /**
226
     * Gets the type of the text element.
227
     *
228
     * @return    a type
229
     */
230
    public int type() {
231
        return Element.PHRASE;
232
    }
233
234
    /**
235
     * Gets all the chunks in this element.
236
     *
237
     * @return    an <CODE>ArrayList</CODE>
238
     */
239
    public ArrayList getChunks() {
240
        ArrayList tmp = new ArrayList();
241
        for (Object o : this) {
242
            tmp.addAll(((Element) o).getChunks());
243
        }
244 1 1. getChunks : mutated return of Object value for com/lowagie/text/Phrase::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return tmp;
245
    }
246
247
    /**
248
     * @see com.lowagie.text.Element#isContent()
249
     * @since    iText 2.0.8
250
     */
251
    public boolean isContent() {
252
        return true;
253
    }
254
255
    /**
256
     * @see com.lowagie.text.Element#isNestable()
257
     * @since    iText 2.0.8
258
     */
259
    public boolean isNestable() {
260
        return true;
261
    }
262
263
    // overriding some of the ArrayList-methods
264
265
    /**
266
     * Adds a <CODE>Chunk</CODE>, an <CODE>Anchor</CODE> or another <CODE>Phrase</CODE>
267
     * to this <CODE>Phrase</CODE>.
268
     *
269
     * @param    index    index at which the specified element is to be inserted
270
     * @param    o       an object of type <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
271
     * @throws    ClassCastException    when you try to add something that isn't a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
272
     */
273
    public void add(int index, Object o) {
274 1 1. add : negated conditional → NO_COVERAGE
        if (o == null) return;
275
        try {
276
            Element element = (Element) o;
277 1 1. add : negated conditional → NO_COVERAGE
            if (element.type() == Element.CHUNK) {
278
                Chunk chunk = (Chunk) element;
279 1 1. add : negated conditional → NO_COVERAGE
                if (!font.isStandardFont()) {
280 1 1. add : removed call to com/lowagie/text/Chunk::setFont → NO_COVERAGE
                    chunk.setFont(font.difference(chunk.getFont()));
281
                }
282 3 1. add : negated conditional → NO_COVERAGE
2. add : negated conditional → NO_COVERAGE
3. add : negated conditional → NO_COVERAGE
                if (hyphenation != null && chunk.getHyphenation() == null && !chunk.isEmpty()) {
283
                    chunk.setHyphenation(hyphenation);
284
                }
285 1 1. add : removed call to java/util/ArrayList::add → NO_COVERAGE
                super.add(index, chunk);
286
            }
287 1 1. add : negated conditional → NO_COVERAGE
            else if (element.type() == Element.PHRASE ||
288 1 1. add : negated conditional → NO_COVERAGE
            element.type() == Element.ANCHOR ||
289 1 1. add : negated conditional → NO_COVERAGE
            element.type() == Element.ANNOTATION ||
290 1 1. add : negated conditional → NO_COVERAGE
            element.type() == Element.TABLE || // line added by David Freels
291 1 1. add : negated conditional → NO_COVERAGE
            element.type() == Element.YMARK ||
292 1 1. add : negated conditional → NO_COVERAGE
            element.type() == Element.MARKED) {
293 1 1. add : removed call to java/util/ArrayList::add → NO_COVERAGE
                super.add(index, element);
294
            }
295
            else {
296
                throw new ClassCastException(String.valueOf(element.type()));
297
            }
298
        }
299
        catch(ClassCastException cce) {
300
            throw new ClassCastException(MessageLocalization.getComposedMessage("insertion.of.illegal.element.1", cce.getMessage()));
301
        }
302
    }
303
304
    /**
305
     * Adds a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or another <CODE>Phrase</CODE>
306
     * to this <CODE>Phrase</CODE>.
307
     *
308
     * @param    o    an object of type <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
309
     * @return    a boolean
310
     * @throws    ClassCastException    when you try to add something that isn't a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
311
     */
312
    public boolean add(Object o) {
313 2 1. add : negated conditional → NO_COVERAGE
2. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        if (o == null) return false;
314 1 1. add : negated conditional → NO_COVERAGE
        if (o instanceof String) {
315 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return super.add(new Chunk((String) o, font));
316
        }
317 1 1. add : negated conditional → NO_COVERAGE
        if (o instanceof RtfElementInterface) {
318 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return super.add(o);
319
        }
320
        try {
321
            Element element = (Element) o;
322
            switch(element.type()) {
323
                case Element.CHUNK:
324 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                    return addChunk((Chunk) o);
325
                case Element.PHRASE:
326
                case Element.PARAGRAPH:
327
                    Phrase phrase = (Phrase) o;
328
                    boolean success = true;
329
                    Element e;
330
                    for (Object o1 : phrase) {
331
                        e = (Element) o1;
332 1 1. add : negated conditional → NO_COVERAGE
                        if (e instanceof Chunk) {
333 1 1. add : Replaced bitwise AND with OR → NO_COVERAGE
                            success &= addChunk((Chunk) e);
334
                        } else {
335 1 1. add : Replaced bitwise AND with OR → NO_COVERAGE
                            success &= this.add(e);
336
                        }
337
                    }
338 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                    return success;
339
                case Element.MARKED:
340
                case Element.ANCHOR:
341
                case Element.ANNOTATION:
342
                case Element.FOOTNOTE:
343
                case Element.TABLE: // case added by David Freels
344
                case Element.PTABLE: // case added by mr. Karen Vardanyan
345
                    // This will only work for PDF!!! Not for RTF/HTML
346
                case Element.LIST:
347
                case Element.YMARK:
348 1 1. add : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                    return super.add(o);
349
                    default:
350
                        throw new ClassCastException(String.valueOf(element.type()));
351
            }
352
        }
353
        catch(ClassCastException cce) {
354
            throw new ClassCastException(MessageLocalization.getComposedMessage("insertion.of.illegal.element.1", cce.getMessage()));
355
        }
356
    }
357
358
    /**
359
     * Adds a collection of <CODE>Chunk</CODE>s
360
     * to this <CODE>Phrase</CODE>.
361
     *
362
     * @param    collection    a collection of <CODE>Chunk</CODE>s, <CODE>Anchor</CODE>s and <CODE>Phrase</CODE>s.
363
     * @return    <CODE>true</CODE> if the action succeeded, <CODE>false</CODE> if not.
364
     * @throws    ClassCastException    when you try to add something that isn't a <CODE>Chunk</CODE>, <CODE>Anchor</CODE> or <CODE>Phrase</CODE>
365
     */
366
    public boolean addAll(Collection collection) {
367
        for (Object o : collection) {
368
            this.add(o);
369
        }
370 1 1. addAll : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return true;
371
    }
372
373
    /**
374
     * Adds a Chunk.
375
     * <p>
376
     * This method is a hack to solve a problem I had with phrases that were split between chunks
377
     * in the wrong place.
378
     * @param chunk a Chunk to add to the Phrase
379
     * @return true if adding the Chunk succeeded
380
     */
381
    protected boolean addChunk(Chunk chunk) {
382
        Font f = chunk.getFont();
383
        String c = chunk.getContent();
384 2 1. addChunk : negated conditional → NO_COVERAGE
2. addChunk : negated conditional → NO_COVERAGE
        if (font != null && !font.isStandardFont()) {
385
            f = font.difference(chunk.getFont());
386
        }
387 3 1. addChunk : changed conditional boundary → NO_COVERAGE
2. addChunk : negated conditional → NO_COVERAGE
3. addChunk : negated conditional → NO_COVERAGE
        if (size() > 0 && !chunk.hasAttributes()) {
388
            try {
389 1 1. addChunk : Replaced integer subtraction with addition → NO_COVERAGE
                Chunk previous = (Chunk) get(size() - 1);
390 2 1. addChunk : negated conditional → NO_COVERAGE
2. addChunk : negated conditional → NO_COVERAGE
                if (!previous.hasAttributes()
391
                        && (f == null
392 1 1. addChunk : negated conditional → NO_COVERAGE
                        || f.compareTo(previous.getFont()) == 0)
393 1 1. addChunk : negated conditional → NO_COVERAGE
                        && !"".equals(previous.getContent().trim())
394 1 1. addChunk : negated conditional → NO_COVERAGE
                        && !"".equals(c.trim())) {
395
                    previous.append(c);
396 1 1. addChunk : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                    return true;
397
                }
398
            }
399
            catch(ClassCastException cce) {
400
            }
401
        }
402
        Chunk newChunk = new Chunk(c, f);
403 1 1. addChunk : removed call to com/lowagie/text/Chunk::setAttributes → NO_COVERAGE
        newChunk.setAttributes(chunk.getAttributes());
404 3 1. addChunk : negated conditional → NO_COVERAGE
2. addChunk : negated conditional → NO_COVERAGE
3. addChunk : negated conditional → NO_COVERAGE
        if (hyphenation != null && newChunk.getHyphenation() == null && !newChunk.isEmpty()) {
405
            newChunk.setHyphenation(hyphenation);
406
        }
407 1 1. addChunk : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return super.add(newChunk);
408
    }
409
410
    /**
411
     * Adds a <CODE>Object</CODE> to the <CODE>Paragraph</CODE>.
412
     *
413
     * @param    object        the object to add.
414
     */
415
    protected void addSpecial(Object object) {
416
        super.add(object);
417
    }
418
419
    // other methods that change the member variables
420
421
    /**
422
     * Sets the leading of this phrase.
423
     *
424
     * @param    leading        the new leading
425
     */
426
427
    public void setLeading(float leading) {
428
        this.leading = leading;
429
    }
430
431
    /**
432
     * Sets the main font of this phrase.
433
     * @param font    the new font
434
     */
435
    public void setFont(Font font) {
436
        this.font = font;
437
    }
438
439
    // methods to retrieve information
440
441
    /**
442
     * Gets the leading of this phrase.
443
     *
444
     * @return    the linespacing
445
     */
446
    public float getLeading() {
447 2 1. getLeading : negated conditional → NO_COVERAGE
2. getLeading : negated conditional → NO_COVERAGE
        if (Float.isNaN(leading) && font != null) {
448 1 1. getLeading : replaced return of float value with -(x + 1) for com/lowagie/text/Phrase::getLeading → NO_COVERAGE
            return font.getCalculatedLeading(1.5f);
449
        }
450 1 1. getLeading : replaced return of float value with -(x + 1) for com/lowagie/text/Phrase::getLeading → NO_COVERAGE
        return leading;
451
    }
452
453
    /**
454
     * Checks you if the leading of this phrase is defined.
455
     *
456
     * @return    true if the leading is defined
457
     */
458
    public boolean hasLeading() {
459 2 1. hasLeading : negated conditional → NO_COVERAGE
2. hasLeading : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return !Float.isNaN(leading);
460
    }
461
462
    /**
463
     * Gets the font of the first <CODE>Chunk</CODE> that appears in this <CODE>Phrase</CODE>.
464
     *
465
     * @return    a <CODE>Font</CODE>
466
     */
467
    public Font getFont() {
468
        return font;
469
    }
470
471
    /**
472
     * Returns the content as a String object.
473
     * This method differs from toString because toString will return an ArrayList with the toString value of the Chunks in this Phrase.
474
     */
475
    public String getContent() {
476
        StringBuilder buf = new StringBuilder();
477
        for (Object o : getChunks()) {
478
            buf.append(o.toString());
479
        }
480 1 1. getContent : mutated return of Object value for com/lowagie/text/Phrase::getContent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return buf.toString();
481
    }
482
483
    /**
484
     * Checks is this <CODE>Phrase</CODE> contains no or 1 empty <CODE>Chunk</CODE>.
485
     *
486
     * @return    <CODE>false</CODE> if the <CODE>Phrase</CODE>
487
     * contains more than one or more non-empty<CODE>Chunk</CODE>s.
488
     */
489
    public boolean isEmpty() {
490
        switch(size()) {
491
            case 0:
492 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                return true;
493
            case 1:
494
                Element element = (Element) get(0);
495 3 1. isEmpty : negated conditional → NO_COVERAGE
2. isEmpty : negated conditional → NO_COVERAGE
3. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                return element.type() == Element.CHUNK && ((Chunk) element).isEmpty();
496
            default:
497 1 1. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
                    return false;
498
        }
499
    }
500
501
    /**
502
     * Getter for the hyphenation settings.
503
     * @return    a HyphenationEvent
504
     * @since    2.1.2
505
     */
506
    public HyphenationEvent getHyphenation() {
507
        return hyphenation;
508
    }
509
510
    /**
511
     * Setter for the hyphenation.
512
     * @param    hyphenation    a HyphenationEvent instance
513
     * @since    2.1.2
514
     */
515
    public void setHyphenation(HyphenationEvent hyphenation) {
516
        this.hyphenation = hyphenation;
517
    }
518
519
    // kept for historical reasons; people should use FontSelector
520
    // eligible for deprecation, but the methods are mentioned in the book p277.
521
522
    /**
523
     * Constructs a Phrase that can be used in the static getInstance() method.
524
     * @param    dummy    a dummy parameter
525
     */
526
    private Phrase(boolean dummy) {
527
    }
528
529
    /**
530
     * Gets a special kind of Phrase that changes some characters into corresponding symbols.
531
     * @param string
532
     * @return a newly constructed Phrase
533
     */
534
    public static final Phrase getInstance(String string) {
535 1 1. getInstance : mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getInstance(16, string, new Font());
536
    }
537
538
    /**
539
     * Gets a special kind of Phrase that changes some characters into corresponding symbols.
540
     * @param leading
541
     * @param string
542
     * @return a newly constructed Phrase
543
     */
544
    public static final Phrase getInstance(int leading, String string) {
545 1 1. getInstance : mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getInstance(leading, string, new Font());
546
    }
547
548
    /**
549
     * Gets a special kind of Phrase that changes some characters into corresponding symbols.
550
     * @param leading
551
     * @param string
552
     * @param font
553
     * @return a newly constructed Phrase
554
     */
555
    public static final Phrase getInstance(int leading, String string, Font font) {
556
        Phrase p = new Phrase(true);
557 1 1. getInstance : removed call to com/lowagie/text/Phrase::setLeading → NO_COVERAGE
        p.setLeading(leading);
558
        p.font = font;
559 3 1. getInstance : negated conditional → NO_COVERAGE
2. getInstance : negated conditional → NO_COVERAGE
3. getInstance : negated conditional → NO_COVERAGE
        if (font.getFamily() != Font.SYMBOL && font.getFamily() != Font.ZAPFDINGBATS && font.getBaseFont() == null) {
560
            int index;
561 2 1. getInstance : changed conditional boundary → NO_COVERAGE
2. getInstance : negated conditional → NO_COVERAGE
            while((index = SpecialSymbol.index(string)) > -1) {
562 2 1. getInstance : changed conditional boundary → NO_COVERAGE
2. getInstance : negated conditional → NO_COVERAGE
                if (index > 0) {
563
                    String firstPart = string.substring(0, index);
564
                    p.add(new Chunk(firstPart, font));
565
                    string = string.substring(index);
566
                }
567
                Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
568
                StringBuilder buf = new StringBuilder();
569
                buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
570
                string = string.substring(1);
571 1 1. getInstance : negated conditional → NO_COVERAGE
                while (SpecialSymbol.index(string) == 0) {
572
                    buf.append(SpecialSymbol.getCorrespondingSymbol(string.charAt(0)));
573
                    string = string.substring(1);
574
                }
575
                p.add(new Chunk(buf.toString(), symbol));
576
            }
577
        }
578 2 1. getInstance : negated conditional → NO_COVERAGE
2. getInstance : negated conditional → NO_COVERAGE
        if (string != null && string.length() != 0) {
579
            p.add(new Chunk(string, font));
580
        }
581 1 1. getInstance : mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return p;
582
    }
583
584
}

Mutations

120

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE

141

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE

155

1.1
Location :
Killed by : none
removed call to com/lowagie/text/Phrase::setHyphenation → NO_COVERAGE

199

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location :
Killed by : none
negated conditional → NO_COVERAGE

218

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

221

1.1
Location : process
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

244

1.1
Location : getChunks
Killed by : none
mutated return of Object value for com/lowagie/text/Phrase::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

274

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

277

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

279

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

280

1.1
Location : add
Killed by : none
removed call to com/lowagie/text/Chunk::setFont → NO_COVERAGE

282

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : add
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : add
Killed by : none
negated conditional → NO_COVERAGE

285

1.1
Location : add
Killed by : none
removed call to java/util/ArrayList::add → NO_COVERAGE

287

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

288

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

289

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

290

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

291

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

292

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

293

1.1
Location : add
Killed by : none
removed call to java/util/ArrayList::add → NO_COVERAGE

313

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

314

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

315

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

317

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

318

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

324

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

332

1.1
Location : add
Killed by : none
negated conditional → NO_COVERAGE

333

1.1
Location : add
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

335

1.1
Location : add
Killed by : none
Replaced bitwise AND with OR → NO_COVERAGE

338

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

348

1.1
Location : add
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

370

1.1
Location : addAll
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

384

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

387

1.1
Location : addChunk
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

389

1.1
Location : addChunk
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

390

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

392

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

393

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

394

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

396

1.1
Location : addChunk
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

403

1.1
Location : addChunk
Killed by : none
removed call to com/lowagie/text/Chunk::setAttributes → NO_COVERAGE

404

1.1
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : addChunk
Killed by : none
negated conditional → NO_COVERAGE

407

1.1
Location : addChunk
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

447

1.1
Location : getLeading
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getLeading
Killed by : none
negated conditional → NO_COVERAGE

448

1.1
Location : getLeading
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Phrase::getLeading → NO_COVERAGE

450

1.1
Location : getLeading
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/Phrase::getLeading → NO_COVERAGE

459

1.1
Location : hasLeading
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : hasLeading
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

480

1.1
Location : getContent
Killed by : none
mutated return of Object value for com/lowagie/text/Phrase::getContent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

492

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

495

1.1
Location : isEmpty
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : isEmpty
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

497

1.1
Location : isEmpty
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

535

1.1
Location : getInstance
Killed by : none
mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

545

1.1
Location : getInstance
Killed by : none
mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

557

1.1
Location : getInstance
Killed by : none
removed call to com/lowagie/text/Phrase::setLeading → NO_COVERAGE

559

1.1
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

561

1.1
Location : getInstance
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

562

1.1
Location : getInstance
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

571

1.1
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

578

1.1
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

581

1.1
Location : getInstance
Killed by : none
mutated return of Object value for com/lowagie/text/Phrase::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2