/** * Creates a new </code>{@link TextDescription}</code>. * * @param value the value of this description. * @throws NullPointerException if the given value is {@code null}. */ public TextDescription(String value) { checkNotNull(value); this.value = value; }
/** * Returns a {@link PropertyDescriptor} for a property matching the given name in the given object. * * @param propertyName the given property name. * @param target the given object. * @return a {@code PropertyDescriptor} for a property matching the given name in the given object. * @throws NullPointerException if the given property name is {@code null}. * @throws IllegalArgumentException if the given property name is empty. * @throws NullPointerException if the given object is {@code null}. * @throws IntrospectionError if a matching property cannot be found or accessed. */ public static PropertyDescriptor getProperty(String propertyName, Object target) { checkNotNullOrEmpty(propertyName); checkNotNull(target); BeanInfo beanInfo = null; Class<?> type = target.getClass(); try { beanInfo = Introspector.getBeanInfo(type); } catch (Throwable t) { throw new IntrospectionError(format("Unable to get BeanInfo for type %s", type.getName()), t); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (propertyName.equals(descriptor.getName())) { return descriptor; } } throw new IntrospectionError(propertyNotFoundErrorMessage(propertyName, target)); }
/** * Interprets a printf-style format {@code String} for failed assertion messages. It is similar to * <code>{@link String#format(String, Object...)}</code>, except for: * <ol> * <li>the value of the given <code>{@link Description}</code> is used as the first argument referenced in the format * string</li> * <li>each of the arguments in the given array is converted to a {@code String} by invoking * <code>{@link ToString#toStringOf(Object)}</code>. * </ol> * * @param d the description of the failed assertion, may be {@code null}. * @param format the format string. * @param args arguments referenced by the format specifiers in the format string. * @throws NullPointerException if the format string is {@code null}. * @return A formatted {@code String}. */ public String format(Description d, String format, Object... args) { checkNotNull(format); checkNotNull(args); return descriptionFormatter.format(d) + String.format(format, format(args)); }
/** * Creates a new {@link Offset}. * * @param value the value of the offset. * @return the created {@code Offset}. * @throws NullPointerException if the given value is {@code null}. * @throws IllegalArgumentException if the given value is negative. */ public static Offset<Integer> offset(Integer value) { checkNotNull(value); if (value.intValue() < 0) { throw valueNotPositive(); } return new Offset<Integer>(value); }
/** * Creates a new {@link Offset}. * * @param value the value of the offset. * @return the created {@code Offset}. * @throws NullPointerException if the given value is {@code null}. * @throws IllegalArgumentException if the given value is negative. */ public static Offset<Float> offset(Float value) { checkNotNull(value); if (value.floatValue() < 0f) { throw valueNotPositive(); } return new Offset<Float>(value); }
/** * Creates a new {@link Offset}. * * @param value the value of the offset. * @return the created {@code Offset}. * @throws NullPointerException if the given value is {@code null}. * @throws IllegalArgumentException if the given value is negative. */ public static Offset<Double> offset(Double value) { checkNotNull(value); if (value.doubleValue() < 0d) { throw valueNotPositive(); } return new Offset<Double>(value); }
/** * Verifies that the given {@code String} is not {@code null} or empty. * * @param s the given {@code String}. * @return the validated {@code String}. * @throws NullPointerException if the given {@code String} is {@code null}. * @throws IllegalArgumentException if the given {@code String} is empty. */ public static String checkNotNullOrEmpty(String s) { checkNotNull(s); if (s.isEmpty()) { throw new IllegalArgumentException(); } return s; }
/** * Returns {@code true} if the given array has only {@code null} elements, {@code false} otherwise. If given array is * empty, this method returns {@code true}. * * @param <T> the type of elements of the array. * @param array the given array. <b>It must not be null</b>. * @return {@code true} if the given array has only {@code null} elements or is empty, {@code false} otherwise. * @throws NullPointerException if the given array is {@code null}. * @since 1.1.3 */ public static <T> boolean hasOnlyNullElements(T[] array) { checkNotNull(array); if (!hasElements(array)) { return false; } for (T o : array) { if (o != null) { return false; } } return true; }