Skip to content

Commit 0697231

Browse files
committed
PDFBOX-5660: refactor, as suggested by Valery Bokov; closes #249
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1928328 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2a6f133 commit 0697231

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ final float[] parseRectangleAttributes(String rect, String errorMessage) throws
320320
return values;
321321
}
322322

323+
final float[] parseFloats(String[] srcValues)
324+
{
325+
float[] values = new float[srcValues.length];
326+
for (int i = 0; i < srcValues.length; i++)
327+
{
328+
values[i] = Float.parseFloat(srcValues[i]);
329+
}
330+
return values;
331+
}
332+
323333
final PDRectangle createRectangleFromAttributes(String rect, String errorMessage) throws IOException
324334
{
325335
String[] rectValues = rect.split(",");

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationFreeText.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ private void initCallout(Element element)
116116
if (callout != null && !callout.isEmpty())
117117
{
118118
String[] calloutValues = callout.split(",");
119-
float[] values = new float[calloutValues.length];
120-
for (int i = 0; i < calloutValues.length; i++)
121-
{
122-
values[i] = Float.parseFloat(calloutValues[i]);
123-
}
119+
float[] values = parseFloats(calloutValues);
124120
setCallout(values);
125121
}
126122
}

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationInk.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ public FDFAnnotationInk(Element element) throws IOException
9696
{
9797
String gesture = node.getFirstChild().getNodeValue();
9898
String[] gestureValues = gesture.split("[,;]");
99-
float[] values = new float[gestureValues.length];
100-
for (int j = 0; j < gestureValues.length; j++)
101-
{
102-
values[j] = Float.parseFloat(gestureValues[j]);
103-
}
99+
float[] values = parseFloats(gestureValues);
104100
inklist.add(values);
105101
}
106102
}

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationPolygon.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ private void initVertices(Element element) throws IOException
9595
throw new IOException("Error: missing element 'vertices'");
9696
}
9797
String[] verticesValues = vertices.split(",|;");
98-
float[] values = new float[verticesValues.length];
99-
for (int i = 0; i < verticesValues.length; i++)
100-
{
101-
values[i] = Float.parseFloat(verticesValues[i]);
102-
}
98+
float[] values = parseFloats(verticesValues);
10399
setVertices(values);
104100
}
105101
catch (XPathExpressionException e)

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationPolyline.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ private void initVertices(Element element) throws IOException
9191
throw new IOException("Error: missing element 'vertices'");
9292
}
9393
String[] verticesValues = vertices.split("[,;]");
94-
float[] values = new float[verticesValues.length];
95-
for (int i = 0; i < verticesValues.length; i++)
96-
{
97-
values[i] = Float.parseFloat(verticesValues[i]);
98-
}
94+
float[] values = parseFloats(verticesValues);
9995
setVertices(values);
10096
}
10197
catch (XPathExpressionException e)

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTextMarkup.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ protected FDFAnnotationTextMarkup(Element element) throws IOException
6868
{
6969
throw new IOException("Error: too little numbers in attribute 'coords'");
7070
}
71-
float[] values = new float[coordsValues.length];
72-
for (int i = 0; i < coordsValues.length; i++)
73-
{
74-
values[i] = Float.parseFloat(coordsValues[i]);
75-
}
71+
float[] values = parseFloats(coordsValues);
7672
setCoords(values);
7773
}
7874

0 commit comments

Comments
 (0)