{"action":"created","issue":{"url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/103","labels_url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/103/comments","events_url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/103/events","html_url":"https://github.com/SQiShER/java-object-diff/issues/103","id":44324717,"number":103,"title":"Is there a way to specify an \"EqualsFactory\"","user":{"login":"zeitos","id":1010275,"avatar_url":"https://avatars.githubusercontent.com/u/1010275?v=3","gravatar_id":"","url":"https://api.github.com/users/zeitos","html_url":"https://github.com/zeitos","followers_url":"https://api.github.com/users/zeitos/followers","following_url":"https://api.github.com/users/zeitos/following{/other_user}","gists_url":"https://api.github.com/users/zeitos/gists{/gist_id}","starred_url":"https://api.github.com/users/zeitos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zeitos/subscriptions","organizations_url":"https://api.github.com/users/zeitos/orgs","repos_url":"https://api.github.com/users/zeitos/repos","events_url":"https://api.github.com/users/zeitos/events{/privacy}","received_events_url":"https://api.github.com/users/zeitos/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SQiShER/java-object-diff/labels/difficulty:%20hard","name":"difficulty: hard","color":"009800"},{"url":"https://api.github.com/repos/SQiShER/java-object-diff/labels/frequency:%20high","name":"frequency: high","color":"eb6420"},{"url":"https://api.github.com/repos/SQiShER/java-object-diff/labels/type:%20new%20feature","name":"type: new feature","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-09-29T17:47:52Z","updated_at":"2015-06-09T05:52:48Z","closed_at":null,"body":"Hi, \r\n   I took a look at the library and really liked it, I'm thinking about using it but I need a couple of extensions (that I might write if they are not available right now) one of which is:\r\n\r\nI need a way to specify an equals method for objects that do not override equals and hashCode, from the quick look I took at the code that's not possible but before writing it I wanted to check.\r\n\r\n\r\nThanks!\r\n"},"comment":{"url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/comments/110232530","html_url":"https://github.com/SQiShER/java-object-diff/issues/103#issuecomment-110232530","issue_url":"https://api.github.com/repos/SQiShER/java-object-diff/issues/103","id":110232530,"user":{"login":"NagyGa1","id":7298930,"avatar_url":"https://avatars.githubusercontent.com/u/7298930?v=3","gravatar_id":"","url":"https://api.github.com/users/NagyGa1","html_url":"https://github.com/NagyGa1","followers_url":"https://api.github.com/users/NagyGa1/followers","following_url":"https://api.github.com/users/NagyGa1/following{/other_user}","gists_url":"https://api.github.com/users/NagyGa1/gists{/gist_id}","starred_url":"https://api.github.com/users/NagyGa1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NagyGa1/subscriptions","organizations_url":"https://api.github.com/users/NagyGa1/orgs","repos_url":"https://api.github.com/users/NagyGa1/repos","events_url":"https://api.github.com/users/NagyGa1/events{/privacy}","received_events_url":"https://api.github.com/users/NagyGa1/received_events","type":"User","site_admin":false},"created_at":"2015-06-09T05:52:48Z","updated_at":"2015-06-09T05:52:48Z","body":"@SQiShER Ok, how about this:\r\n * New interface for configuration purposes:\r\n   ```java\r\n   public interface EqualsFactory {\r\n\r\n        public boolean accepts(final Class<?> type);\r\n\r\n        public boolean equals(final Object _this, final Object o);\r\n\r\n        public int hashCode(final Object _this);\r\n\r\n   }\r\n   ```\r\n * CollectionDiffer#compare() currently works on `Collection<?>`. Would change those internally to `Collection<EqualsWrapper<?>>`, or maybe even `Set<EqualsWrapper<?>>`.\r\n * EqualsWrapper would just wrap the object and call its equals / hashCode(), or call a client supplied EqualsFactory:\r\n    ```java\r\n/**\r\n * Wraps an object and allows to specify custom equals by an EqualsFactory.\r\n */\r\npublic class EqualsWrapper {\r\n\r\n\tprivate Object o;\r\n\r\n\tprivate EqualsFactory equalsFactory;\r\n\r\n\t/**\r\n\t * \r\n\t * @param o\r\n\t *            the object to wrap\r\n\t * @param equalsFactory\r\n\t *            may be null, this case the object's own hashCode() and\r\n\t *            equals() will be used.\r\n\t */\r\n\tpublic EqualsWrapper(final Object o, final EqualsFactory equalsFactory) {\r\n\t\tthis.o = o;\r\n\t\tthis.equalsFactory = equalsFactory;\r\n\t}\r\n\r\n\tpublic Object getO() {\r\n\t\treturn o;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int hashCode() {\r\n\t\tif(equalsFactory == null) {\r\n\t\t\treturn o.hashCode();\r\n\t\t} else {\r\n\t\t\treturn equalsFactory.hashCode(o);\r\n\t\t}\r\n\t}\r\n\t@Override\r\n\tpublic boolean equals(final Object obj) {\r\n\t\tif(equalsFactory == null) {\r\n\t\t\treturn o.equals(obj);\r\n\t\t} else {\r\n\t\t\treturn equalsFactory.equals(o, obj);\r\n\t\t}\r\n\t}\r\n}\r\n    ```\r\n\r\nMaybe could make `EqualsWrapper` part of `Instances`? Then probably no need to change `CollectionDiffer` or `Collections`."}}