Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort parameters before diff in IBaseDataObjectDiffHelper #523

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/main/java/emissary/core/IBaseDataObjectDiffHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
import java.nio.channels.SeekableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;

public class IBaseDataObjectDiffHelper {
Expand All @@ -25,7 +28,7 @@ private IBaseDataObjectDiffHelper() {}

/**
* This method compares two IBaseDataObject's and adds any differences to the provided string list.
*
*
* @param ibdo1 the first IBaseDataObject to compare.
* @param ibdo2 the second IBaseDataObject to compare.
* @param differences the string list differences are to be added to.
Expand Down Expand Up @@ -56,7 +59,7 @@ public static void diff(final IBaseDataObject ibdo1, final IBaseDataObject ibdo2
}

diff(ibdo1.getFontEncoding(), ibdo2.getFontEncoding(), "fontEncoding", differences);
diff(ibdo1.getParameters(), ibdo2.getParameters(), "parameters", differences);
diff(sortParameters(ibdo1.getParameters()), sortParameters(ibdo2.getParameters()), "parameters", differences);
sambish5 marked this conversation as resolved.
Show resolved Hide resolved
diff(ibdo1.getNumChildren(), ibdo2.getNumChildren(), "numChildren", differences);
diff(ibdo1.getNumSiblings(), ibdo2.getNumSiblings(), "numSiblings", differences);
diff(ibdo1.getBirthOrder(), ibdo2.getBirthOrder(), "birthOrder", differences);
Expand All @@ -83,7 +86,7 @@ public static void diff(final IBaseDataObject ibdo1, final IBaseDataObject ibdo2

/**
* This method compares two lists of IBaseDataObject's and adds any differences to the provided string list.
*
*
* @param ibdoList1 the first list of IBaseDataObjects to compare.
* @param ibdoList2 the second list of IBaseDataObjects to compare.
* @param identifier a string that helps identify the context of comparing these two list of IBaseDataObjects.
Expand Down Expand Up @@ -118,7 +121,7 @@ public static void diff(final List<IBaseDataObject> ibdoList1, final List<IBaseD
/**
* This method compares two {@link SeekableByteChannelFactory} (SBCF) objects and adds any differences to the provided
* string list.
*
*
* @param sbcf1 the first SBCF to compare.
* @param sbcf2 the second SBCF to compare.
* @param identifier an identifier to describe the context of this SBCF comparison.
Expand Down Expand Up @@ -150,7 +153,7 @@ public static void diff(final SeekableByteChannelFactory sbcf1, final SeekableBy

/**
* This method compares two Objects and adds any differences to the provided string list.
*
*
* @param object1 the first Object to compare.
* @param object2 the second Object to compare.
* @param identifier an identifier to describe the context of this Object comparison.
Expand All @@ -168,7 +171,7 @@ public static void diff(final Object object1, final Object object2, final String

/**
* This method compares two integers and adds any differences to the provided string list.
*
*
* @param integer1 the first integer to compare.
* @param integer2 the second integer to compare.
* @param identifier an identifier to describe the context of this integer comparison.
Expand All @@ -186,7 +189,7 @@ public static void diff(final int integer1, final int integer2, final String ide

/**
* This method compares two booleans and adds any differences to the provided string list.
*
*
* @param boolean1 the first boolean to compare.
* @param boolean2 the second boolean to compare.
* @param identifier an identifier to describe the context of this boolean comparison.
Expand All @@ -204,7 +207,7 @@ public static void diff(final boolean boolean1, final boolean boolean2, final St

/**
* This method compares two maps and adds any differences to the provided string list.
*
*
* @param map1 the first map to compare.
* @param map2 the second map to compare.
* @param identifier an identifier to describe the context of this map comparison.
Expand All @@ -223,4 +226,22 @@ public static void diff(final Map<String, byte[]> map1, final Map<String, byte[]
}
}


/**
* This method is used to sort the given map of parameters by key.
*
* @param parameters the map of parameters from IBaseDataObject to sort
* @return map of sorted parameters
*/
public static Map<String, Collection<Object>> sortParameters(Map<String, Collection<Object>> parameters) {
List<Entry<String, Collection<Object>>> list = new ArrayList<>(parameters.entrySet());
list.sort(Entry.comparingByKey());

Map<String, Collection<Object>> sortedParams = new HashMap<>();
for (Entry<String, Collection<Object>> curParam : list) {
sortedParams.put(curParam.getKey(), curParam.getValue());
}

return sortedParams;
}
}