List of usage examples for org.apache.commons.lang Validate notNull
public static void notNull(Object object)
Validate an argument, throwing IllegalArgumentException
if the argument is null
.
Validate.notNull(myObject);
The message in the exception is 'The validated object is null'.
From source file:com.hmsinc.epicenter.tools.geocoder.FacilityGeocoder.java
/** * @param args/*from w ww .java 2s .c o m*/ */ @SuppressWarnings("unchecked") public static void main(String[] args) { if (args.length == 5) { System.setProperty("db.driver", args[0]); System.setProperty("db.url", args[1]); System.setProperty("db.type", args[2]); System.setProperty("db.user", args[3]); System.setProperty("db.password", args[4]); appContext = new ClassPathXmlApplicationContext(CONTEXT_FILES); final ProviderRepository providerRepository = (ProviderRepository) appContext .getBean("providerRepository"); Validate.notNull(providerRepository); final Geocoder geocoder = (Geocoder) appContext.getBean("geocoder"); Validate.notNull(geocoder); final PlatformTransactionManager tm = (PlatformTransactionManager) appContext .getBean("transactionManager"); Validate.notNull(tm); final TransactionTemplate template = new TransactionTemplate(tm); List<Facility> facilities = (List<Facility>) template.execute(new TransactionCallback() { /* * (non-Javadoc) * * @see org.springframework.transaction.support.TransactionCallback#doInTransaction(org.springframework.transaction.TransactionStatus) */ public List<Facility> doInTransaction(TransactionStatus status) { return providerRepository.getList(Facility.class); } }); for (final Facility facility : facilities) { if (facility.getGeometry() == null && facility.getAddress1() != null && facility.getCity() != null && facility.getState() != null && facility.getZipcode() != null) { template.execute(new TransactionCallbackWithoutResult() { /* * (non-Javadoc) * * @see org.springframework.transaction.support.TransactionCallbackWithoutResult#doInTransactionWithoutResult(org.springframework.transaction.TransactionStatus) */ @Override protected void doInTransactionWithoutResult(TransactionStatus status) { System.out.println(facility.toString()); final Geometry geom = geocoder.geocode(facility.getAddress1(), facility.getCity(), facility.getState(), facility.getZipcode()); if (geom != null) { facility.setGeometry(geom); providerRepository.update(facility); } } }); } } } else { usage(); } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java
public static int[] stateless(int[] v) { Validate.notNull(v); final int n = v.length; int[] tmp = new int[n]; for (int i = 0; i < n; i++) { tmp[i] = Math.abs(v[i]);// w ww. ja v a2s. c om } return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Reverse.java
/** * Reverses a vector in place//w ww .j ava 2s. c om * @param v1 the vector to be reversed */ public static void inPlace(int[] v1) { Validate.notNull(v1); int tmp; final int half = v1.length / 2; final int len = v1.length - 1; for (int i = 0; i < half; i++) { tmp = v1[len - i]; v1[len - i] = v1[i]; v1[i] = tmp; } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Negate.java
/** * Negates the boolean values in a vector in a stateless manner. * @param v a vector of booleans//from w w w. ja v a 2 s.c om * @return tmp the negated representation of v */ public static boolean[] stateless(boolean[] v) { Validate.notNull(v); final int len = v.length; boolean[] tmp = new boolean[len]; for (int i = 0; i < len; i++) { if (v[i] == true) { tmp[i] = false; } else { tmp[i] = true; } } return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Max.java
/** * Returns the maximum value in data/* w w w.jav a 2s. c o m*/ * @param data the data to search * @return max, the maximum */ public static int value(int... data) { Validate.notNull(data); int max = 0x80000000; final int n = data.length; for (int i = 0; i < n; i++) { if (data[i] > max) { max = data[i]; } } return max; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Min.java
/** * Returns the minimum value in data/*w w w. j a v a2s . c o m*/ * @param data the data to search * @return min, the minimum */ public static int value(int... data) { Validate.notNull(data); int min = 0x7fffffff; final int n = data.length; for (int i = 0; i < n; i++) { if (data[i] < min) { min = data[i]; } } return min; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java
public static long[] stateless(long[] v) { Validate.notNull(v); final int n = v.length; long[] tmp = new long[n]; for (int i = 0; i < n; i++) { tmp[i] = Math.abs(v[i]);// w ww . jav a2 s . com } return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.iss.IsNaN.java
/** * Walks through a vector looking for NaN's if one is found the routine returns TRUE. * @param v the vector (with possible NaN entries) * @return a boolean, TRUE if a NaN is found in v, FALSE otherwise *//*from w w w. j a v a 2 s .c om*/ public static boolean any(double[] v) { Validate.notNull(v); boolean logical = false; final int len = v.length; for (int i = 0; i < len; i++) { if (v[i] != v[i]) { logical = true; return logical; } } return logical; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sum.java
/** * Sums over all indices of a given vector (classic vector reduction) * @param v the vector over which the sum will be undertaken. * @return the sum of vector v//from w w w . j av a 2s . c om */ public static double overAllIndices(double[] v) { Validate.notNull(v); double tmp = 0; final int n = v.length; for (int i = 0; i < n; i++) { tmp += v[i]; } return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.View.java
/** * Looks up the values in v at positions given by index and returns them! * @param v the vector/*w w w . j ava 2s . c om*/ * @param index the indices to look up in the vector * @return tmp the values looked up by index. i.e. values[index]; */ public static double[] byIndex(double[] v, int[] index) { Validate.notNull(v); Validate.notNull(index); Validate.isTrue(Max.value(index) < v.length); Validate.isTrue(Min.value(index) > -1); final int idxn = index.length; double[] tmp = new double[idxn]; for (int i = 0; i < idxn; i++) { tmp[i] = v[index[i]]; } return tmp; }