1 | package com.lowagie.text.pdf.collection; | |
2 | ||
3 | import com.lowagie.text.pdf.PdfArray; | |
4 | import com.lowagie.text.pdf.PdfBoolean; | |
5 | import com.lowagie.text.pdf.PdfDictionary; | |
6 | import com.lowagie.text.pdf.PdfName; | |
7 | import com.lowagie.text.pdf.PdfObject; | |
8 | import com.lowagie.text.error_messages.MessageLocalization; | |
9 | ||
10 | public class PdfCollectionSort extends PdfDictionary { | |
11 | | |
12 | /** | |
13 | * Constructs a PDF Collection Sort Dictionary. | |
14 | * @param key the key of the field that will be used to sort entries | |
15 | */ | |
16 | public PdfCollectionSort(String key) { | |
17 | super(PdfName.COLLECTIONSORT); | |
18 |
1
1. |
put(PdfName.S, new PdfName(key)); |
19 | } | |
20 | | |
21 | /** | |
22 | * Constructs a PDF Collection Sort Dictionary. | |
23 | * @param keys the keys of the fields that will be used to sort entries | |
24 | */ | |
25 | public PdfCollectionSort(String[] keys) { | |
26 | super(PdfName.COLLECTIONSORT); | |
27 | PdfArray array = new PdfArray(); | |
28 | for (String key : keys) { | |
29 | array.add(new PdfName(key)); | |
30 | } | |
31 |
1
1. |
put(PdfName.S, array); |
32 | } | |
33 | | |
34 | /** | |
35 | * Defines the sort order of the field (ascending or descending). | |
36 | * @param ascending true is the default, use false for descending order | |
37 | */ | |
38 | public void setSortOrder(boolean ascending) { | |
39 | PdfObject o = get(PdfName.S); | |
40 |
1
1. setSortOrder : negated conditional → NO_COVERAGE |
if (o instanceof PdfName) { |
41 |
1
1. setSortOrder : removed call to com/lowagie/text/pdf/collection/PdfCollectionSort::put → NO_COVERAGE |
put(PdfName.A, new PdfBoolean(ascending)); |
42 | } | |
43 | else { | |
44 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("you.have.to.define.a.boolean.array.for.this.collection.sort.dictionary")); | |
45 | } | |
46 | } | |
47 | | |
48 | /** | |
49 | * Defines the sort order of the field (ascending or descending). | |
50 | * @param ascending an array with every element corresponding with a name of a field. | |
51 | */ | |
52 | public void setSortOrder(boolean[] ascending) { | |
53 | PdfObject o = get(PdfName.S); | |
54 |
1
1. setSortOrder : negated conditional → NO_COVERAGE |
if (o instanceof PdfArray) { |
55 |
1
1. setSortOrder : negated conditional → NO_COVERAGE |
if (((PdfArray)o).size() != ascending.length) { |
56 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.number.of.booleans.in.this.array.doesn.t.correspond.with.the.number.of.fields")); | |
57 | } | |
58 | PdfArray array = new PdfArray(); | |
59 | for (boolean b : ascending) { | |
60 | array.add(new PdfBoolean(b)); | |
61 | } | |
62 |
1
1. setSortOrder : removed call to com/lowagie/text/pdf/collection/PdfCollectionSort::put → NO_COVERAGE |
put(PdfName.A, array); |
63 | } | |
64 | else { | |
65 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("you.need.a.single.boolean.for.this.collection.sort.dictionary")); | |
66 | } | |
67 | } | |
68 | | |
69 | | |
70 | } | |
Mutations | ||
18 |
1.1 |
|
31 |
1.1 |
|
40 |
1.1 |
|
41 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
62 |
1.1 |