/** * Returns true if actual and other are equal based on {@link Object#equals(Object)}, false otherwise. * * @param actual the object to compare to other * @param other the object to compare to actual * @return true if actual and other are equal based on {@link Object#equals(Object)}, false otherwise. */ @Override public boolean areEqual(Object actual, Object other) { return Objects.areEqual(actual, other); }
@Override public int hashCode() { int result = 1; result = HASH_CODE_PRIME * result + hashCodeFor(value); return result; }
/** * Returns {@code true} if the given objects are equal or if both objects are {@code null}. * * @param o1 one of the objects to compare. * @param o2 one of the objects to compare. * @return {@code true} if the given objects are equal or if both objects are {@code null}. */ public static boolean areEqual(Object o1, Object o2) { if (o1 == null) { return o2 == null; } if (o1.equals(o2)) { return true; } return areEqualArrays(o1, o2); }
/** * 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; }
@Override public int hashCode() { int result = 1; result = HASH_CODE_PRIME * result + hashCodeFor(key); result = HASH_CODE_PRIME * result + hashCodeFor(value); return result; }
/** * Returns true if given {@link Iterable} contains given value based on {@link Object#equals(Object)}, false otherwise.<br> * If given {@link Iterable} is null, return false. * * @param iterable the {@link Iterable} to search value in * @param value the object to look for in given {@link Iterable} * @return true if given {@link Iterable} contains given value based on {@link Object#equals(Object)}, false otherwise. */ @Override public boolean iterableContains(Iterable<?> iterable, Object value) { if (iterable == null) { return false; } for (Object next : iterable) { if (Objects.areEqual(next, value)) { return true; } } return false; }
@Override public int hashCode() { int result = 1; result = HASH_CODE_PRIME * result + hashCodeFor(actual); result = HASH_CODE_PRIME * result + hashCodeFor(expected); return result; } }
@Override public int hashCode() { return HASH_CODE_PRIME * 1 + hashCodeFor(value); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BasicErrorMessageFactory other = (BasicErrorMessageFactory) obj; if (!areEqual(format, other.format)) return false; // because it does not manage array recursively, don't use : Arrays.equals(arguments, other.arguments); // example if arguments[1] and other.arguments[1] are logically same arrays but not same object, it will return // false return areEqual(arguments, other.arguments); }
@Override public int hashCode() { int result = 1; result = HASH_CODE_PRIME * result + hashCodeFor(format); result = HASH_CODE_PRIME * result + Arrays.hashCode(arguments); return result; }
private boolean containsEntry(Map<?, ?> actual, MapEntry entry) { if (entry == null) { throw new NullPointerException("Entries to look for should not be null"); } if (!actual.containsKey(entry.key)) { return false; } return areEqual(actual.get(entry.key), entry.value); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Offset<?> other = (Offset<?>) obj; return areEqual(value, other.value); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } TextDescription other = (TextDescription) obj; return areEqual(value, other.value); } }
/** * {@inheritDoc} */ @Override public void iterableRemoves(Iterable<?> iterable, Object value) { if (iterable == null) { return; } Iterator<?> iterator = iterable.iterator(); while (iterator.hasNext()) { if (Objects.areEqual(iterator.next(), value)) { iterator.remove(); } } }
private List<String> diff(BufferedReader actual, BufferedReader expected) throws IOException { List<String> diffs = new ArrayList<String>(); int lineNumber = 0; while (true) { String actualLine = actual.readLine(); String expectedLine = expected.readLine(); if (actualLine == null || expectedLine == null) { if (expectedLine != null) { diffs.add(output(lineNumber, EOF, expectedLine)); } if (actualLine != null) { diffs.add(output(lineNumber, actualLine, EOF)); } return diffs; } else if (!areEqual(actualLine, expectedLine)) { diffs.add(output(lineNumber, actualLine, expectedLine)); } lineNumber += 1; } }
private boolean actualAndExpectedHaveSameStringRepresentation() { return areEqual(toStringOf(actual), toStringOf(expected)); }
/** * Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) <b>not equals to</b> given * value. * <p> * Typical usage : * * <pre> * filter(employees).with("name").notEqualsTo("Vader").get(); * </pre> * * @param propertyValue the filter value. * @return this {@link Filters} to chain other filter operation. * @throws NullPointerException if the property name to filter on has not been set. */ public Filters<E> notEqualsTo(Object propertyValue) { checkPropertyNameToFilterOnIsNotNull(); List<E> newFilteredIterable = new ArrayList<E>(); for (E element : filteredIterable) { Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValue.getClass(), element); if (!areEqual(propertyValueOfCurrentElement, propertyValue)) { newFilteredIterable.add(element); } } this.filteredIterable = newFilteredIterable; return this; }
/** * Filters the underlying iterable to keep object with property (specified by {@link #with(String)}) <b>equals to</b> given * value. * <p> * Typical usage : * * <pre> * filter(employees).with("name").equalsTo("Luke").get(); * </pre> * * @param propertyValue the filter value. * @return this {@link Filters} to chain other filter operation. * @throws NullPointerException if the property name to filter on has not been set. */ public Filters<E> equalsTo(Object propertyValue) { checkPropertyNameToFilterOnIsNotNull(); List<E> newFilteredIterable = new ArrayList<E>(); for (E element : filteredIterable) { // As we don't know the propertyValue class, we use Object.class Class<? extends Object> propertyValueClass = propertyValue == null ? Object.class : propertyValue.getClass(); Object propertyValueOfCurrentElement = propertySupport.propertyValueOf(propertyNameToFilterOn, propertyValueClass, element); if (areEqual(propertyValueOfCurrentElement, propertyValue)) { newFilteredIterable.add(element); } } this.filteredIterable = newFilteredIterable; return this; }