mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Utility methods to get details of property changes (map comparison).
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@34824 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,9 +22,9 @@ import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Property map helper class.
|
||||
@@ -101,4 +101,112 @@ public class PropertyMap extends HashMap<QName, Serializable>
|
||||
// Done
|
||||
return new Pair<Map<QName, Serializable>, Map<QName, Serializable>>(beforeDelta, afterDelta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get properties which were added as part of a change.
|
||||
*
|
||||
* @param before the properties before (may be <code>null</code>).
|
||||
* @param after the properties after (may be <code>null</code>).
|
||||
* @return a map of values that were added along with their new values.
|
||||
*
|
||||
* @since Odin
|
||||
*/
|
||||
public static Map<QName, Serializable> getAddedProperties(Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
|
||||
|
||||
if (before != null && after != null)
|
||||
{
|
||||
result.putAll(after);
|
||||
result.keySet().removeAll(before.keySet());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get properties which were removed as part of a change.
|
||||
*
|
||||
* @param before the properties before (may be <code>null</code>).
|
||||
* @param after the properties after (may be <code>null</code>).
|
||||
* @return a map of values that were removed along with their old values.
|
||||
*
|
||||
* @since Odin
|
||||
*/
|
||||
public static Map<QName, Serializable> getRemovedProperties(Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
|
||||
|
||||
if (before != null && after != null)
|
||||
{
|
||||
result.putAll(before);
|
||||
result.keySet().removeAll(after.keySet());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get properties which were changed (but not added or removed) as part of a change.
|
||||
*
|
||||
* @param before the properties before (may be <code>null</code>).
|
||||
* @param after the properties after (may be <code>null</code>).
|
||||
* @return a map of values that were changed along with their new values.
|
||||
*
|
||||
* @since Odin
|
||||
*/
|
||||
public static Map<QName, Serializable> getChangedProperties(Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
|
||||
|
||||
if (before != null && after != null)
|
||||
{
|
||||
Map<QName, Serializable> intersection = new HashMap<QName, Serializable>();
|
||||
|
||||
intersection.putAll(after);
|
||||
intersection.keySet().retainAll(before.keySet());
|
||||
|
||||
for (Entry<QName, Serializable> entry : intersection.entrySet())
|
||||
{
|
||||
if ( ! EqualsHelper.nullSafeEquals(before.get(entry.getKey()), after.get(entry.getKey())))
|
||||
{
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get properties which were unchanged as part of a change.
|
||||
*
|
||||
* @param before the properties before (may be <code>null</code>).
|
||||
* @param after the properties after (may be <code>null</code>).
|
||||
* @return a map of values that were unchanged along with their values.
|
||||
*
|
||||
* @since Odin
|
||||
*/
|
||||
public static Map<QName, Serializable> getUnchangedProperties(Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||
{
|
||||
Map<QName, Serializable> result = new HashMap<QName, Serializable>();
|
||||
|
||||
if (before != null && after != null)
|
||||
{
|
||||
Map<QName, Serializable> intersection = new HashMap<QName, Serializable>();
|
||||
|
||||
intersection.putAll(before);
|
||||
intersection.keySet().retainAll(after.keySet());
|
||||
|
||||
for (Entry<QName, Serializable> entry : intersection.entrySet())
|
||||
{
|
||||
if ( EqualsHelper.nullSafeEquals(before.get(entry.getKey()), after.get(entry.getKey())))
|
||||
{
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user