/** * Get the values of any array (primitive or not) into a {@code List<Object>}. * * @param array array passed as an object to support both primitive and Object array * @return the values of the given Object as a {@code List<Object>}. * @throws IllegalArgumentException it the given Object is not an array. */ public static List<Object> asList(Object array) { return newArrayList(asObjectArray(array)); }
/** * Specifies the charset to use for text-based assertions on the file's contents. * * @param charset the charset to use. * @return {@code this} assertion object. * @throws NullPointerException if the given charset is {@code null}. */ @CheckReturnValue public SELF usingCharset(Charset charset) { this.charset = checkNotNull(charset, "The charset should not be null"); return myself; }
/** * Returns the names of the files inside the specified directory. * * @param dirName the name of the directory to start the search from. * @param recurse if {@code true}, we will look in subdirectories. * @return the names of the files inside the specified directory. * @throws IllegalArgumentException if the given directory name does not point to an existing directory. */ public static List<String> fileNamesIn(String dirName, boolean recurse) { File dir = new File(dirName); checkArgument(dir.isDirectory(), "%s is not a directory", quote(dirName)); return fileNamesIn(dir, recurse); }
/** * Returns <code>true</code> if given item is in given array, <code>false</code> otherwise. * * @param item the object to look for in arrayOfValues * @param arrayOfValues the array of values * @return <code>true</code> if given item is in given array, <code>false</code> otherwise. */ private static boolean isItemInArray(Object item, Object[] arrayOfValues) { for (Object value : arrayOfValues) if (areEqual(value, item)) return true; return false; }
private void validatePropertyOrFieldName(String propertyOrFieldName) { checkArgument(!Strings.isNullOrEmpty(propertyOrFieldName), "The property/field name to filter on should not be null or empty"); }
public class ShouldEndWithPath extends BasicErrorMessageFactory { @VisibleForTesting public static final String PATH_SHOULD_END_WITH = "%nExpected path:%n <%s>%nto end with:%n <%s>%nbut it did not."; public static ErrorMessageFactory shouldEndWith(final Path actual, final Path other) { return new ShouldEndWithPath(actual, other); } private ShouldEndWithPath(final Path actual, final Path other) { super(PATH_SHOULD_END_WITH, actual, other); } }
/** * Check that the {@link LocalDate} to compare actual {@link LocalDate} to is not null, in that case throws a * {@link IllegalArgumentException} with an explicit message * * @param other the {@link LocalDate} to check * @throws IllegalArgumentException with an explicit message if the given {@link LocalDate} is null */ private static void assertLocalDateParameterIsNotNull(LocalDate other) { checkArgument(other != null, NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE); }
@Override public int hashCode() { int result = 1; result = HASH_CODE_PRIME * result + hashCodeFor(actual); result = HASH_CODE_PRIME * result + hashCodeFor(expected); return result; }
@SuppressWarnings("unchecked") private static Comparable<Object>[] arrayOfComparableItems(Object array) { ArrayWrapperList arrayWrapperList = wrap(array); Comparable<Object>[] arrayOfComparableItems = new Comparable[arrayWrapperList.size()]; for (int i = 0; i < arrayWrapperList.size(); i++) { arrayOfComparableItems[i] = (Comparable<Object>) arrayWrapperList.get(i); } return arrayOfComparableItems; }
@Override @CheckReturnValue public AbstractMapAssert<MapAssert<KEY, VALUE>, Map<KEY, VALUE>, KEY, VALUE> returnToMap() { return source; } }
private ShouldBeInstanceOfAny(Throwable throwable, Class<?>[] types) { super("%nExpecting:%n <%s>%nto be an instance of any of:%n <%s>%nbut was:%n <%s>", throwable, types, getStackTrace(throwable)); } }
/** * Closes the given {@link Closeable}s, ignoring any thrown exceptions. * * @param closeables the {@code Closeable}s to close. */ public static void closeQuietly(Closeable... closeables) { for (Closeable c : closeables) { closeCloseable(c); } }
@Override public int compareNonNull(Float x, Float y) { if (closeEnough(x, y, precision)) return 0; return x < y ? -1 : 1; }
/** * ISO 8601 date-time format (yyyy-MM-dd'T'HH:mm:ss), example : <code>2003-04-26T13:01:02</code> * @return a {@code yyyy-MM-dd'T'HH:mm:ss} {@link DateFormat} */ public static DateFormat newIsoDateTimeFormat() { return strictDateFormatForPattern("yyyy-MM-dd'T'HH:mm:ss"); }
/** * Check that the {@link LocalTime} string representation to compare actual {@link LocalTime} to is not null, * otherwise throws a {@link IllegalArgumentException} with an explicit message * * @param localTimeAsString String representing the {@link LocalTime} to compare actual with * @throws IllegalArgumentException with an explicit message if the given {@link String} is null */ private static void assertLocalTimeAsStringParameterIsNotNull(String localTimeAsString) { checkArgument(localTimeAsString != null, "The String representing the LocalTime to compare actual with should not be null"); }
/** * Construct the delta for original and revised chunks * * @param original Chunk describing the original text. Must not be {@code null}. * @param revised Chunk describing the revised text. Must not be {@code null}. */ public Delta(Chunk<T> original, Chunk<T> revised) { checkArgument(original != null, "original must not be null"); checkArgument(revised != null, "revised must not be null"); this.original = original; this.revised = revised; }
/** * Check that the {@link java.time.OffsetTime} string representation to compare actual {@link java.time.OffsetTime} to * is not null, * otherwise throws a {@link IllegalArgumentException} with an explicit message * * @param OffsetTimeAsString String representing the {@link java.time.OffsetTime} to compare actual with * @throws IllegalArgumentException with an explicit message if the given {@link String} is null */ private static void assertOffsetTimeAsStringParameterIsNotNull(String OffsetTimeAsString) { checkArgument(OffsetTimeAsString != null, "The String representing the OffsetTime to compare actual with should not be null"); }
/** * Check that the {@link java.time.OffsetDateTime} to compare actual {@link java.time.OffsetDateTime} to is not null, * in that case throws a {@link IllegalArgumentException} with an explicit message * * @param other the {@link java.time.OffsetDateTime} to check * @throws IllegalArgumentException with an explicit message if the given {@link java.time.OffsetDateTime} is null */ private static void assertOffsetDateTimeParameterIsNotNull(OffsetDateTime other) { checkArgument(other != null, "The OffsetDateTime to compare actual with should not be null"); }
/** * Check that the {@link LocalDateTime} to compare actual {@link LocalDateTime} to is not null, in that case throws a * {@link IllegalArgumentException} with an explicit message * * @param other the {@link LocalDateTime} to check * @throws IllegalArgumentException with an explicit message if the given {@link LocalDateTime} is null */ private static void assertLocalDateTimeParameterIsNotNull(LocalDateTime other) { checkArgument(other != null, "The LocalDateTime to compare actual with should not be null"); }