comparison flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java @ 2216:31fa7cae0f35

Added new helper methods to FLYSUtils that extract int[] and double[] from string. flys-artifacts/trunk@3855 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Feb 2012 12:21:05 +0000
parents c3e523a76340
children ee5310134463
comparison
equal deleted inserted replaced
2215:ebbb18ed78c4 2216:31fa7cae0f35
15 15
16 import org.hibernate.SessionFactory; 16 import org.hibernate.SessionFactory;
17 import org.hibernate.impl.SessionFactoryImpl; 17 import org.hibernate.impl.SessionFactoryImpl;
18 18
19 import gnu.trove.TDoubleArrayList; 19 import gnu.trove.TDoubleArrayList;
20 import gnu.trove.TIntArrayList;
20 21
21 import de.intevation.artifacts.Artifact; 22 import de.intevation.artifacts.Artifact;
22 import de.intevation.artifacts.CallContext; 23 import de.intevation.artifacts.CallContext;
23 24
24 import de.intevation.artifacts.common.utils.Config; 25 import de.intevation.artifacts.common.utils.Config;
714 else if (wqkms.length < idx) 715 else if (wqkms.length < idx)
715 logger.warn("not enough waterlevels in artifact"); 716 logger.warn("not enough waterlevels in artifact");
716 return wqkms[idx]; 717 return wqkms[idx];
717 } 718 }
718 } 719 }
720
721
722 /**
723 * This method transform a string into an int array. Therefore, the string
724 * <i>raw</i> must consist of int values separated by a <i>';'</i>.
725 *
726 * @param raw The raw integer array as string separated by a ';'.
727 *
728 * @return an array of int values.
729 */
730 public static int[] intArrayFromString(String raw) {
731 String[] splitted = raw != null ? raw.split(";") : null;
732
733 if (splitted == null || splitted.length == 0) {
734 logger.warn("No integer values found in '" + raw + "'");
735 return new int[0];
736 }
737
738 TIntArrayList integers = new TIntArrayList(splitted.length);
739
740 for (String value: splitted) {
741 try {
742 integers.add(Integer.valueOf(value));
743 }
744 catch (NumberFormatException nfe) {
745 logger.warn("Parsing integer failed: " + nfe);
746 }
747 }
748
749 return integers.toNativeArray();
750 }
751
752
753 /**
754 * This method transform a string into an double array. Therefore, the
755 * string <i>raw</i> must consist of double values separated by a
756 * <i>';'</i>.
757 *
758 * @param raw The raw double array as string separated by a ';'.
759 *
760 * @return an array of double values.
761 */
762 public static double[] doubleArrayFromString(String raw) {
763 String[] splitted = raw != null ? raw.split(";") : null;
764
765 if (splitted == null || splitted.length == 0) {
766 logger.warn("No double values found in '" + raw + "'");
767 return new double[0];
768 }
769
770 TDoubleArrayList doubles = new TDoubleArrayList(splitted.length);
771
772 for (String value: splitted) {
773 try {
774 doubles.add(Double.valueOf(value));
775 }
776 catch (NumberFormatException nfe) {
777 logger.warn("Parsing double failed: " + nfe);
778 }
779 }
780
781 return doubles.toNativeArray();
782 }
719 } 783 }
720 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 784 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org