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.opengamma.maths.lowlevelapi.functions.iss.IsInf.java
/** * Walks through a vector looking for infinity regardless of sign, if one is found the routine returns TRUE. * @param v the vector (with possible (+/-)Inf entries) * @return a boolean, TRUE if a (+/-)Inf is found in v, FALSE otherwise *//*from w ww.j a v a 2 s . c o m*/ 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] == DOUBLEPINF || v[i] == DOUBLENINF) { logical = true; return logical; } } return logical; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java
public static double[] stateless(double[] v) { Validate.notNull(v); final int n = v.length; double[] tmp = new double[n]; for (int i = 0; i < n; i++) { tmp[i] = Math.abs(v[i]);//from www . j a v a2 s. c o m } return tmp; }
From source file:bigbluej.ReflectionUtils.java
public static SortedMap<String, Object> getFieldsAndValuesInSortedMap(Object object) throws IllegalAccessException { Validate.notNull(object); SortedMap<String, Object> fieldAndValues = new TreeMap<>(); for (Field field : object.getClass().getDeclaredFields()) { field.setAccessible(true);//from w w w. jav a2s . c om String name = field.getName(); Object value = field.get(object); if (!field.isSynthetic() && value != null) { fieldAndValues.put(name, value); } } return fieldAndValues; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Permute.java
private static void inputValidator(int[] v, int[] p) { Validate.notNull(v); Validate.notNull(p);/*from www . j a v a2s . c o m*/ assertTrue("Permutation is of length: " + p.length + " whereas vector is of length " + v.length + ". Permutation is therefore impossible.", v.length == p.length); // shortcut costly parse tests if vectors are not the same length assertTrue("Permutation contains indices with impossible range (too large)", Max.value(p) < v.length); // make sure the permutation won't go out of range. assertTrue("Permutation doesn't contain index 0", Min.value(p) == 0); // make sure the permutation won't go out of range, also catches -ve indices assertTrue("Permutation is nonunique (some indices are repeated)", Unique.bitwise(p).length == p.length); // make sure the permutation is a valid permutation. }
From source file:ar.com.zauber.commons.web.transformation.utils.WebValidate.java
/** * Valida que la URI termine con / y que no sea nula sino * lanza una excepcion.//ww w . j a v a 2 s . c o m * * @param uri URI a validar. */ public static void uriNotNull(final String uri) { Validate.notNull(uri); uriWellFormed(uri); }
From source file:com.stealthyone.mcb.stbukkitlib.utils.TimeUtils.java
public static String translateSeconds(int seconds, TimeFormat format) { Validate.notNull(format); if (seconds < 0) throw new IllegalArgumentException("Seconds cannot be negative! (" + seconds + ")"); StringBuilder returnString = new StringBuilder(); int minutes = seconds / 60; seconds = seconds - minutes * 60;/*from w ww.j a v a 2s .c om*/ int hours = minutes / 60; minutes = minutes - hours * 60; int days = hours / 24; hours = hours - days * 24; if (format == TimeFormat.LONG) { if (days > 0) { returnString.append(days).append(days == 1 ? " day" : " days"); } if (hours > 0) { if (days > 0) returnString.append(" "); returnString.append(hours).append(hours == 1 ? " hour" : " hours"); } if (minutes > 0) { if (hours > 0) returnString.append(" "); returnString.append(minutes).append(minutes == 1 ? " minute" : " minutes"); } if (seconds > 0 || seconds == 0 && minutes == 0 && hours == 0 && days == 0) { if (minutes > 0) returnString.append(" "); returnString.append(seconds).append(seconds == 1 ? " second" : " seconds"); } } else if (format == TimeFormat.SHORT) { if (days > 0) { returnString.append(Integer.toString(days).length() == 1 ? "0" : "" + days); } if (hours > 0) { if (days > 0) returnString.append(":"); returnString.append(Integer.toString(hours).length() == 1 ? "0" : "" + hours); } if (hours > 0) returnString.append(":"); returnString.append(Integer.toString(minutes).length() == 1 ? "0" : "" + minutes); if (minutes > 0) returnString.append(":"); returnString.append(Integer.toString(seconds).length() == 1 ? "0" : "" + seconds); } return returnString.toString(); }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in ascending order * @param v1 the values to sort (a native backed array) * @return tmp the sorted values/* w w w .ja va 2s.c o m*/ */ public static int[] stateless(int[] v1) { Validate.notNull(v1); int[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sum.java
/** * Sums over selected indices of a given vector * @param v the vector over which the sum will be undertaken * @param idx the indices to be included in the sum * @return the sum of dereferenced indices of vector v *///from w w w. j a v a 2 s . c om public static double overIndices(double[] v, int[] idx) { Validate.notNull(v); Validate.notNull(idx); final int n = v.length; Validate.isTrue(Max.value(idx) < n, "Index out of range. Max of indexes is " + Max.value(idx) + " whereas vector to dereference is length " + n); Validate.isTrue(Min.value(idx) > -1, "Negative index dereference requested on vector"); double tmp = 0; final int idxn = idx.length; for (int i = 0; i < idxn; i++) { tmp += v[idx[i]]; } return tmp; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Reverse.java
/** * Reverses a vector in place/*from w w w . j a v a 2s.c om*/ * @param v1 the vector to be reversed */ public static void inPlace(float[] v1) { Validate.notNull(v1); float 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.iss.IsNaN.java
/** * Walks through a vector looking for NaN's and sets the index of a corresponding boolean vector to TRUE if a NaN is found. * @param v the vector (with possible NaN entries) * @return a boolean vector, true or false depending on whether a NaN is found in the input vector (true = NaN found at position). *//*from w w w . j av a2 s .c om*/ public static boolean[] getBooleans(double[] v) { Validate.notNull(v); final int len = v.length; boolean[] logical = new boolean[len]; for (int i = 0; i < len; i++) { if (v[i] != v[i]) { logical[i] = true; } } return logical; }