-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: README.md
- Loading branch information
Showing
69 changed files
with
3,681 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...-compare/src/main/java/de/alpharogroup/compare/object/CompareObjectQuietlyExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* The MIT License | ||
* | ||
* Copyright (C) 2015 Asterios Raptis | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package de.alpharogroup.compare.object; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.beanutils.BeanComparator; | ||
import org.apache.commons.beanutils.BeanUtils; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* The class {@link CompareObjectQuietlyExtensions} provide methods for compare an object with | ||
* another given object. | ||
*/ | ||
@UtilityClass | ||
@Slf4j | ||
public final class CompareObjectQuietlyExtensions | ||
{ | ||
|
||
/** | ||
* Compares the given object over the given property quietly. | ||
* | ||
* @param sourceOjbect | ||
* the source ojbect | ||
* @param objectToCompare | ||
* the object to compare | ||
* @param property | ||
* the property | ||
* @return the int | ||
*/ | ||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
public static int compareToQuietly(final Object sourceOjbect, final Object objectToCompare, | ||
final String property) | ||
{ | ||
Map<?, ?> beanDescription = null; | ||
try | ||
{ | ||
beanDescription = BeanUtils.describe(sourceOjbect); | ||
} | ||
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) | ||
{ | ||
log.error("BeanUtils.describe(sourceOjbect) throws an exception...", e); | ||
return 0; | ||
} | ||
Map<?, ?> clonedBeanDescription = null; | ||
try | ||
{ | ||
clonedBeanDescription = BeanUtils.describe(objectToCompare); | ||
} | ||
catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) | ||
{ | ||
log.error("BeanUtils.describe(objectToCompare) throws an exception...", e); | ||
return 0; | ||
} | ||
final Object sourceAttribute = beanDescription.get(property); | ||
final Object changedAttribute = clonedBeanDescription.get(property); | ||
if (sourceAttribute == null && changedAttribute == null) | ||
{ | ||
return 0; | ||
} | ||
if (sourceAttribute != null && changedAttribute == null) | ||
{ | ||
return 1; | ||
} | ||
else if (sourceAttribute == null && changedAttribute != null) | ||
{ | ||
return -1; | ||
} | ||
return new BeanComparator(property).compare(sourceOjbect, objectToCompare); | ||
} | ||
|
||
} |
Oops, something went wrong.