I just realized I could use the "from" CE to avoid this entire mess.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fenderbosch, Eric Sent: Tuesday, July 15, 2008 10:38 AM To: rules-users@lists.jboss.org Subject: [rules-users] Design Question (hashCode/equals/fact maintenance) I'm just looking for a bit of verification that this is a reasonable solution. This just feels like a hack and there's probably a better way that I'm just not seeing. Alternate ideas are welcome and appreciated. Thanks in advance. The objective is to find the best workers for a job: Jobs have a location. Workers have a location. Scores are calculated based on miles and minutes of a route from the worker to a job. When a job or worker location changes, then the route should be recalculated so that scores can be recalculated. It is possible for a location to get re-inserted that might be the functionally the same as a previous location for a job/worker, but a different instance. In this case, the route should not be recalculated and the old scores should remain. assert behavior = equality logical override = discard maintain tms = true remove identies = true shadow proxies are enabled public class JobLatitudeLongitude { private String jobId; private double latitude; private double longitude; private long timestamp = System.currentTimeMillis(); // getters & setters omitted for brevity public int hashCode() { return jobId.hashCode(); } public boolean equals(Object obj) { // not null or type safe, just simple version for brevity JobLatitudeLongitude other = (JobLatitudeLongitude) obj; return this.jobId.equals(other.jobId) && this.timestamp == other.timestamp; // would "return false;" work ??? } } rule "retract redundant job latitude/longitude facts" // if more than one lat/long with same position for a job, keep the oldest salience 600 when older : JobLatitudeLongitude() newer : JobLatitudeLongitude(jobId == older.jobId, latitude == older.latitude, longitude == older.longitude, timestamp >= older.timestamp) then retract(newer); end rule "retract old job latitude/longitude facts" // if more than one lat/long with different position for a job, keep the newest salience 600 when older : JobLatitudeLongitude() newer : JobLatitudeLongitude(jobId == older.jobId, latitude != older.latitude, longitude != older.longitude, timestamp >= older.timestamp) then retract(older); end rule "add Route fact" salience 450 when jobLatitudeLongitude : JobLatitudeLongitude() workerLatitudeLongitude : WorkerLatitudeLongitude() then // calculateRoute is an imported function Route route = calculateRoute(workerLatitudeLongitude, jobLatitudeLongitude); insertLogical(route); end _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users