-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.utils.strings;\r
-\r
-import java.text.DecimalFormat;\r
-import java.text.NumberFormat;\r
-import java.text.ParseException;\r
-import java.util.Locale;\r
-\r
-public class StringUtils {\r
-\r
- private static NumberFormat usFormat = DecimalFormat.getInstance(Locale.US);\r
- public final static String ZERO_LENGTH_STRING = ""; //$NON-NLS-1$\r
-\r
- /**\r
- * Ensures that a string is not null. Converts null strings into empty\r
- * strings, and leaves any other string unmodified. Use this to help\r
- * wrap calls to methods that return null instead of the empty string.\r
- * Can also help protect against implementation errors in methods that\r
- * are not supposed to return null. \r
- * \r
- * @param input input string (may be null)\r
- * @return input if not null, or the empty string if input is null\r
- */\r
- public static String safeString(String input) {\r
- if (input != null) {\r
- return input;\r
- }\r
-\r
- return ZERO_LENGTH_STRING;\r
- }\r
- \r
-\r
- public static double safeDouble(String input) {\r
-\r
- if(input == null) return Double.NaN;\r
- \r
- try {\r
-\r
- String usafied = input.replace(",", ".");\r
- Number number = usFormat.parse(usafied);\r
- return number.doubleValue();\r
- \r
- } catch (ParseException e) {\r
- \r
- return Double.NaN;\r
- \r
- }\r
- \r
- }\r
- \r
- public static String repeat(String pattern, int repeatCount)\r
- {\r
- StringBuilder sb = new StringBuilder(pattern.length() * repeatCount);\r
- for (int i=0; i<repeatCount; i++)\r
- sb.append(pattern);\r
- return sb.toString();\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.utils.strings;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
+
+public class StringUtils {
+
+ private static NumberFormat usFormat = DecimalFormat.getInstance(Locale.US);
+ public final static String ZERO_LENGTH_STRING = ""; //$NON-NLS-1$
+
+ /**
+ * Ensures that a string is not null. Converts null strings into empty
+ * strings, and leaves any other string unmodified. Use this to help
+ * wrap calls to methods that return null instead of the empty string.
+ * Can also help protect against implementation errors in methods that
+ * are not supposed to return null.
+ *
+ * @param input input string (may be null)
+ * @return input if not null, or the empty string if input is null
+ */
+ public static String safeString(String input) {
+ if (input != null) {
+ return input;
+ }
+
+ return ZERO_LENGTH_STRING;
+ }
+
+
+ public static double safeDouble(String input) {
+
+ if(input == null) return Double.NaN;
+
+ try {
+
+ String usafied = input.replace(",", ".");
+ Number number = usFormat.parse(usafied);
+ return number.doubleValue();
+
+ } catch (ParseException e) {
+
+ return Double.NaN;
+
+ }
+
+ }
+
+ public static String repeat(String pattern, int repeatCount)
+ {
+ StringBuilder sb = new StringBuilder(pattern.length() * repeatCount);
+ for (int i=0; i<repeatCount; i++)
+ sb.append(pattern);
+ return sb.toString();
+ }
+
+}