Skip to content

Commit

Permalink
[eclipse-ee4j#630]Forgot one class
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pinsky <[email protected]>
  • Loading branch information
api-from-the-ion committed Nov 13, 2023
1 parent ac9da78 commit ef0ccdd
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson.serializers.model;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public class TwoObjectsComparer {
public final String propertyName;
public final Object firstObjectValue;
public final Object secondObjectValue;

public static <T> Optional<TwoObjectsComparer> getDifferentFieldInTwoObjects(T thisObject, T otherObject) {
return otherObject == null ? Optional.empty() : Arrays.stream(thisObject.getClass().getFields()).map(f -> {
try {
return new TwoObjectsComparer(f.getName(), f.get(thisObject), f.get(otherObject));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}).filter(o -> !Objects.equals(o.firstObjectValue, o.secondObjectValue)).findFirst();
}

private TwoObjectsComparer(String name, Object firstObjectValue, Object secondObjectValue) {
this.propertyName = name;
this.firstObjectValue = firstObjectValue;
this.secondObjectValue = secondObjectValue;
}

@Override
public String toString() {
return "propertyName: " + propertyName + " firstObjectValue: " + firstObjectValue + " secondObjectValue: " + secondObjectValue;
}
}

0 comments on commit ef0ccdd

Please sign in to comment.