Kaydet (Commit) ca7899d6 authored tarafından Robert Antoni Buj i Gelonch's avatar Robert Antoni Buj i Gelonch Kaydeden (comit) Noel Grandin

xmerge: reuse the value of value.indexOf and remove duplicated code

Change-Id: I44d72f7d9f8c58436657ea1517d8eb76332abb4b
Reviewed-on: https://gerrit.libreoffice.org/11747Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 08f33ca6
...@@ -125,18 +125,7 @@ public class ColumnStyle extends Style implements Cloneable { ...@@ -125,18 +125,7 @@ public class ColumnStyle extends Style implements Cloneable {
* @return The twips equivalent. * @return The twips equivalent.
*/ */
private int parseColWidth(String value) { private int parseColWidth(String value) {
return TwipsConverter.convert2twips(value, 255);
int width = 255; // Default value
if(value.indexOf("cm")!=-1) {
float widthCM = Float.parseFloat(value.substring(0,value.indexOf('c')));
width = TwipsConverter.cm2twips(widthCM);
} else if(value.indexOf("inch")!=-1) {
float widthInch = Float.parseFloat(value.substring(0,value.indexOf('i')));
width = TwipsConverter.inches2twips(widthInch);
}
return (width);
} }
/** /**
......
...@@ -124,19 +124,7 @@ public class RowStyle extends Style implements Cloneable { ...@@ -124,19 +124,7 @@ public class RowStyle extends Style implements Cloneable {
* @return The twips equivalent. * @return The twips equivalent.
*/ */
private int parseRowHeight(String value) { private int parseRowHeight(String value) {
return TwipsConverter.convert2twips(value, 255);
int height = 255; // Default value
if(value.indexOf("cm")!=-1) {
float heightCM = Float.parseFloat(value.substring(0,value.indexOf('c')));
height = TwipsConverter.cm2twips(heightCM);
} else if(value.indexOf("inch")!=-1) {
float heightInch = Float.parseFloat(value.substring(0,value.indexOf('i')));
height = TwipsConverter.inches2twips(heightInch);
}
return (height);
} }
/** /**
......
...@@ -39,8 +39,7 @@ public class TwipsConverter { ...@@ -39,8 +39,7 @@ public class TwipsConverter {
/** /**
* Convert from cm's to twips. * Convert from cm's to twips.
* *
* @param value {@code byte} array containing the LE representation of * @param value {@code float} containing the representation of the value.
* the value.
* *
* @return {@code int} containing the converted value. * @return {@code int} containing the converted value.
*/ */
...@@ -52,12 +51,34 @@ public class TwipsConverter { ...@@ -52,12 +51,34 @@ public class TwipsConverter {
/** /**
* Convert from cm's to twips. * Convert from cm's to twips.
* *
* @param value {@code byte} array containing the LE representation of * @param value {@code float} containing the representation of the value.
* the value.
* *
* @return {@code int} containing the converted value. * @return {@code int} containing the converted value.
*/ */
public static int inches2twips(float value) { public static int inches2twips(float value) {
return (int) (value*1440); return (int) (value*1440);
} }
/**
* Convert {@code String} to twips.
*
* @param value {@code String} in the form {@literal "1.234cm"} or
* {@literal "1.234inch"}.
* @param defaultValue the default value.
* @return the converted value if {@code value} is a well-formatted {@code
* String}, {@code defaultValue} otherwise.
*/
public static int convert2twips(String value, int defaultValue) {
int posi;
if ((posi = value.indexOf("cm")) != -1) {
float cm = Float.parseFloat(value.substring(0,posi));
return cm2twips(cm);
} else if ((posi = value.indexOf("inch")) != -1) {
float inches = Float.parseFloat(value.substring(0,posi));
return inches2twips(inches);
}
return defaultValue;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment