public AtomicIntegerArrayAssert(AtomicIntegerArray actual) { super(actual, AtomicIntegerArrayAssert.class); array = array(actual); }
/** * Returns an array containing the names of the given types. * * @param types the given types. * @return the names of the given types stored in an array. */ public static String[] namesOf(Class<?>... types) { if (isNullOrEmpty(types)) { return new String[0]; } String[] names = new String[types.length]; for (int i = 0; i < types.length; i++) { names[i] = types[i].getName(); } return names; }
private static List<Object> flatten(Iterable<Object> collectionToFlatten) { List<Object> result = new ArrayList<>(); for (Object item : collectionToFlatten) { if (item instanceof Iterable<?>) result.addAll(toCollection((Iterable<?>) item)); else if (isArray(item)) result.addAll(org.assertj.core.util.Arrays.asList(item)); else result.add(item); } return result; } }
public static boolean isObjectArray(Object o) { return isArray(o) && !isArrayTypePrimitive(o); }
/** * Returns the {@code String} representation of the given array, or {@code null} if the given object is either * {@code null} or not an array. This method supports arrays having other arrays as elements. * * @param o the object that is expected to be an array. * @return the {@code String} representation of the given array. */ protected String formatArray(Object o) { if (!isArray(o)) return null; return isObjectArray(o) ? smartFormat((Object[]) o) : formatPrimitiveArray(o); }
@SuppressWarnings("unchecked") @Override public boolean areEqual(Object actual, Object other) { if (actual == null && other == null) return true; if (actual == null || other == null) return false; // expecting actual and other to be T[] return isArray(actual) && isArray(other) && compareElementsOf((T[]) actual, (T[]) other); }
protected String formatPrimitiveArray(Object o) { if (!isArray(o)) return null; if (!isArrayTypePrimitive(o)) throw Arrays.notAnArrayOfPrimitives(o); int size = getLength(o); if (size == 0) return DEFAULT_START + DEFAULT_END; StringBuilder buffer = new StringBuilder(); buffer.append(DEFAULT_START); buffer.append(toStringOf(Array.get(o, 0))); for (int i = 1; i < size; i++) { buffer.append(ELEMENT_SEPARATOR) .append(INDENTATION_FOR_SINGLE_LINE); if (i == maxElementsForPrinting) { buffer.append(DEFAULT_MAX_ELEMENTS_EXCEEDED); break; } buffer.append(toStringOf(Array.get(o, i))); } buffer.append(DEFAULT_END); return buffer.toString(); }
throw failures.failure(info, shouldContainExactly(actual, asList(entries), notFound, notExpected));
/** * Returns the {@code toString} representation of the given collection. It may or not the object's own implementation * of {@code toString}. * * @param o the given object. * @return the {@code toString} representation of the given object. */ public static String toStringOf(Representation representation, Object o) { if (isArray(o)) { return org.assertj.core.util.Arrays.format(representation, o); } else if (o instanceof Collection<?>) { return toStringOf((Collection<?>) o, representation); } else if (o instanceof Map<?, ?>) { return toStringOf((Map<?, ?>) o, representation); } else if (o instanceof Tuple) { return toStringOf((Tuple) o, representation); } return defaultToString(o); }
/** * 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)); }
/** * Returns the {@code String} {@link org.assertj.core.presentation.StandardRepresentation standard representation} of * the given array, or {@code null} if the given object is either {@code null} or not an array. * This method supports arrays having other arrays as elements. * * @param array the object that is expected to be an array. * @return the {@code String} standard representation of the given array. */ public static Object format(final Object array) { return format(STANDARD_REPRESENTATION, array); }
/** * Indicates whether the given array is {@code null} or empty. * * @param <T> the type of elements of the array. * @param array the array to check. * @return {@code true} if the given array is {@code null} or empty, otherwise {@code false}. */ public static <T> boolean isNullOrEmpty(T[] array) { return array == null || !hasElements(array); }
/** * Returns the hash code for the given object. If the object is {@code null}, this method returns zero. Otherwise * calls the method {@code hashCode} of the given object. * * @param o the given object. * @return the hash code for the given object */ public static int hashCodeFor(Object o) { if (o == null) return 0; return isArray(o) && !o.getClass().getComponentType().isPrimitive() ? java.util.Arrays.deepHashCode((Object[]) o) : o.hashCode() ; }
public static boolean isObjectArray(Object o) { return isArray(o) && !isArrayTypePrimitive(o); }
protected String formatPrimitiveArray(Object o) { if (!isArray(o)) return null; if (!isArrayTypePrimitive(o)) throw Arrays.notAnArrayOfPrimitives(o); int size = getLength(o); if (size == 0) return DEFAULT_START + DEFAULT_END; StringBuilder buffer = new StringBuilder(); buffer.append(DEFAULT_START); buffer.append(toStringOf(Array.get(o, 0))); for (int i = 1; i < size; i++) { buffer.append(ELEMENT_SEPARATOR) .append(INDENTATION_FOR_SINGLE_LINE); if (i == maxElementsForPrinting) { buffer.append(DEFAULT_MAX_ELEMENTS_EXCEEDED); break; } buffer.append(toStringOf(Array.get(o, i))); } buffer.append(DEFAULT_END); return buffer.toString(); }
throw failures.failure(info, shouldContainExactly(actual, asList(entries), notFound, notExpected));
/** * Returns the {@code String} representation of the given array, or {@code null} if the given object is either * {@code null} or not an array. This method supports arrays having other arrays as elements. * * @param o the object that is expected to be an array. * @return the {@code String} representation of the given array. */ protected String formatArray(Object o) { if (!isArray(o)) return null; return isObjectArray(o) ? smartFormat((Object[]) o) : formatPrimitiveArray(o); }
/** * 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)); }
@Override public String toString() { return format("%s[format=%s, arguments=%s]", getClass().getSimpleName(), quote(format), format(new StandardRepresentation(), arguments)); }
/** * 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; }