1 | /* | |
2 | * Copyright 1999-2004 The Apache Software Foundation. | |
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 | ||
17 | package com.lowagie.text.pdf.hyphenation; | |
18 | ||
19 | import java.io.Serializable; | |
20 | ||
21 | /** | |
22 | * This class implements a simple char vector with access to the | |
23 | * underlying array. | |
24 | * | |
25 | * @author Carlos Villegas <cav@uniscope.co.jp> | |
26 | */ | |
27 | public class CharVector implements Cloneable, Serializable { | |
28 | ||
29 | private static final long serialVersionUID = -4875768298308363544L; | |
30 | /** | |
31 | * Capacity increment size | |
32 | */ | |
33 | private static final int DEFAULT_BLOCK_SIZE = 2048; | |
34 | private int blockSize; | |
35 | ||
36 | /** | |
37 | * The encapsulated array | |
38 | */ | |
39 | private char[] array; | |
40 | ||
41 | /** | |
42 | * Points to next free item | |
43 | */ | |
44 | private int n; | |
45 | ||
46 | public CharVector() { | |
47 | this(DEFAULT_BLOCK_SIZE); | |
48 | } | |
49 | ||
50 | public CharVector(int capacity) { | |
51 |
2
1. 2. |
if (capacity > 0) { |
52 | blockSize = capacity; | |
53 | } else { | |
54 | blockSize = DEFAULT_BLOCK_SIZE; | |
55 | } | |
56 | array = new char[blockSize]; | |
57 | n = 0; | |
58 | } | |
59 | ||
60 | public CharVector(char[] a) { | |
61 | blockSize = DEFAULT_BLOCK_SIZE; | |
62 | array = a; | |
63 | n = a.length; | |
64 | } | |
65 | ||
66 | public CharVector(char[] a, int capacity) { | |
67 |
2
1. 2. |
if (capacity > 0) { |
68 | blockSize = capacity; | |
69 | } else { | |
70 | blockSize = DEFAULT_BLOCK_SIZE; | |
71 | } | |
72 | array = a; | |
73 | n = a.length; | |
74 | } | |
75 | ||
76 | /** | |
77 | * Reset Vector but don't resize or clear elements | |
78 | */ | |
79 | public void clear() { | |
80 | n = 0; | |
81 | } | |
82 | ||
83 | public Object clone() { | |
84 | CharVector cv = new CharVector(array.clone(), blockSize); | |
85 | cv.n = this.n; | |
86 |
1
1. clone : mutated return of Object value for com/lowagie/text/pdf/hyphenation/CharVector::clone to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return cv; |
87 | } | |
88 | ||
89 | public char[] getArray() { | |
90 | return array; | |
91 | } | |
92 | ||
93 | /** | |
94 | * return number of items in array | |
95 | */ | |
96 | public int length() { | |
97 | return n; | |
98 | } | |
99 | ||
100 | /** | |
101 | * returns current capacity of array | |
102 | */ | |
103 | public int capacity() { | |
104 |
1
1. capacity : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return array.length; |
105 | } | |
106 | ||
107 | public void put(int index, char val) { | |
108 | array[index] = val; | |
109 | } | |
110 | ||
111 | public char get(int index) { | |
112 |
1
1. get : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return array[index]; |
113 | } | |
114 | ||
115 | public int alloc(int size) { | |
116 | int index = n; | |
117 | int len = array.length; | |
118 |
3
1. alloc : changed conditional boundary → NO_COVERAGE 2. alloc : Replaced integer addition with subtraction → NO_COVERAGE 3. alloc : negated conditional → NO_COVERAGE |
if (n + size >= len) { |
119 |
1
1. alloc : Replaced integer addition with subtraction → NO_COVERAGE |
char[] aux = new char[len + blockSize]; |
120 |
1
1. alloc : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(array, 0, aux, 0, len); |
121 | array = aux; | |
122 | } | |
123 |
1
1. alloc : Replaced integer addition with subtraction → NO_COVERAGE |
n += size; |
124 |
1
1. alloc : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return index; |
125 | } | |
126 | ||
127 | public void trimToSize() { | |
128 |
2
1. trimToSize : changed conditional boundary → NO_COVERAGE 2. trimToSize : negated conditional → NO_COVERAGE |
if (n < array.length) { |
129 | char[] aux = new char[n]; | |
130 |
1
1. trimToSize : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(array, 0, aux, 0, n); |
131 | array = aux; | |
132 | } | |
133 | } | |
134 | ||
135 | } | |
Mutations | ||
51 |
1.1 2.2 |
|
67 |
1.1 2.2 |
|
86 |
1.1 |
|
104 |
1.1 |
|
112 |
1.1 |
|
118 |
1.1 2.2 3.3 |
|
119 |
1.1 |
|
120 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
128 |
1.1 2.2 |
|
130 |
1.1 |