# HG changeset patch # User Ingo Weinzierl # Date 1328098865 0 # Node ID 31fa7cae0f35a03b329f7c3d19abc1457293c8bb # Parent ebbb18ed78c4955a7e232b01a285c5b7bdb66f23 Added new helper methods to FLYSUtils that extract int[] and double[] from string. flys-artifacts/trunk@3855 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ebbb18ed78c4 -r 31fa7cae0f35 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Feb 01 11:14:24 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed Feb 01 12:21:05 2012 +0000 @@ -1,3 +1,8 @@ +2012-02-01 Ingo Weinzierl + + * src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added helper + methods to extract int[] and double[] from string. + 2012-02-01 Ingo Weinzierl * doc/conf/artifacts/winfo.xml: Registered new facet type diff -r ebbb18ed78c4 -r 31fa7cae0f35 flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java --- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Wed Feb 01 11:14:24 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java Wed Feb 01 12:21:05 2012 +0000 @@ -17,6 +17,7 @@ import org.hibernate.impl.SessionFactoryImpl; import gnu.trove.TDoubleArrayList; +import gnu.trove.TIntArrayList; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; @@ -716,5 +717,68 @@ return wqkms[idx]; } } + + + /** + * This method transform a string into an int array. Therefore, the string + * raw must consist of int values separated by a ';'. + * + * @param raw The raw integer array as string separated by a ';'. + * + * @return an array of int values. + */ + public static int[] intArrayFromString(String raw) { + String[] splitted = raw != null ? raw.split(";") : null; + + if (splitted == null || splitted.length == 0) { + logger.warn("No integer values found in '" + raw + "'"); + return new int[0]; + } + + TIntArrayList integers = new TIntArrayList(splitted.length); + + for (String value: splitted) { + try { + integers.add(Integer.valueOf(value)); + } + catch (NumberFormatException nfe) { + logger.warn("Parsing integer failed: " + nfe); + } + } + + return integers.toNativeArray(); + } + + + /** + * This method transform a string into an double array. Therefore, the + * string raw must consist of double values separated by a + * ';'. + * + * @param raw The raw double array as string separated by a ';'. + * + * @return an array of double values. + */ + public static double[] doubleArrayFromString(String raw) { + String[] splitted = raw != null ? raw.split(";") : null; + + if (splitted == null || splitted.length == 0) { + logger.warn("No double values found in '" + raw + "'"); + return new double[0]; + } + + TDoubleArrayList doubles = new TDoubleArrayList(splitted.length); + + for (String value: splitted) { + try { + doubles.add(Double.valueOf(value)); + } + catch (NumberFormatException nfe) { + logger.warn("Parsing double failed: " + nfe); + } + } + + return doubles.toNativeArray(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :