public static boolean isObjectArray(Object o) { return isArray(o) && !isArrayTypePrimitive(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); }
/** * 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); }
@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(); }
@SuppressWarnings("unchecked") private static <T> List<T> asList(Object array) { if (array == null) return null; checkArgument(isArray(array), "The object should be an array"); int length = getLength(array); List<T> list = new ArrayList<>(length); for (int i = 0; i < length; i++) { list.add((T) Array.get(array, i)); } return list; }
/** * 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() ; }
@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 actual instanceof AtomicReferenceArray && isArray(other) && compareElementsOf((AtomicReferenceArray<T>) actual, (T[]) other); }
public static boolean areEqualArrays(Object o1, Object o2) { if (!isArray(o1) || !isArray(o2)) { return false; } if (o1 == o2) { return true; } int size = Array.getLength(o1); if (Array.getLength(o2) != size) { return false; } for (int i = 0; i < size; i++) { Object e1 = Array.get(o1, i); Object e2 = Array.get(o2, i); if (!areEqual(e1, e2)) { return false; } } return true; }
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; } }
/** * Get the values of any array (primitive or not) into a {@code 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 Object[]}. * @throws IllegalArgumentException it the given Object is not an array. */ public static Object[] asObjectArray(Object array) { checkArgument(isArray(array), "Given object %s is not an array", array); if (array == null) return null; int length = Array.getLength(array); Object[] objectArray = new Object[length]; for (int i = 0; i < length; i++) { objectArray[i] = Array.get(array, i); } return objectArray; }
@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 actual instanceof AtomicReferenceArray && isArray(other) && compareElementsOf((AtomicReferenceArray<T>) actual, (T[]) other); }
@SuppressWarnings("unchecked") private static <T> List<T> asList(Object array) { if (array == null) return null; checkArgument(isArray(array), "The object should be an array"); int length = getLength(array); List<T> list = new ArrayList<>(length); for (int i = 0; i < length; i++) { list.add((T) Array.get(array, i)); } return list; }
/** * Get the values of any array (primitive or not) into a {@code 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 Object[]}. * @throws IllegalArgumentException it the given Object is not an array. */ public static Object[] asObjectArray(Object array) { checkArgument(isArray(array), "Given object %s is not an array", array); if (array == null) return null; int length = Array.getLength(array); Object[] objectArray = new Object[length]; for (int i = 0; i < length; i++) { objectArray[i] = Array.get(array, i); } return objectArray; }
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; } }
/** * 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); }
public static void assertIsArray(AssertionInfo info, Object array) { if (!isArray(array)) throw Failures.instance().failure(info, shouldBeAnArray(array)); }
/** * 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); }
public static void assertIsArray(AssertionInfo info, Object array) { if (!isArray(array)) throw Failures.instance().failure(info, shouldBeAnArray(array)); }