public final void matchEvent(EventBean theEvent, Collection<FilterHandle> matches) { Object attributeValue = lookupable.getGetter().get(theEvent); EventEvaluator evaluator = null; constantsMapRWLock.readLock().lock(); try { evaluator = constantsMap.get(attributeValue); } finally { constantsMapRWLock.readLock().unlock(); } // No listener found for the value, return if (evaluator == null) { return; } evaluator.matchEvent(theEvent, matches); }
public final void matchEvent(EventBean theEvent, Collection<FilterHandle> matches) { Object propertyValue = lookupable.getGetter().get(theEvent); if (propertyValue == null) { return; } // A undefine lower bound indicates an empty index if (lowerBounds == null) { return; } FilterOperator filterOperator = this.getFilterOperator(); Double propertyValueDouble = ((Number) propertyValue).doubleValue(); // Based on current lower and upper bounds check if the property value falls outside - shortcut // submap generation if ((filterOperator == FilterOperator.GREATER) && (propertyValueDouble <= lowerBounds)) { return; } else if ((filterOperator == FilterOperator.GREATER_OR_EQUAL) && (propertyValueDouble < lowerBounds)) { return; } else if ((filterOperator == FilterOperator.LESS) && (propertyValueDouble >= upperBounds)) { return; } else if ((filterOperator == FilterOperator.LESS_OR_EQUAL) && (propertyValueDouble > upperBounds)) { return; } // Look up in table constantsMapRWLock.readLock().lock(); try { // Get the head or tail end of the map depending on comparison type Map<Object, EventEvaluator> subMap; if ((filterOperator == FilterOperator.GREATER) || (filterOperator == FilterOperator.GREATER_OR_EQUAL)) { // At the head of the map are those with a lower numeric constants subMap = constantsMap.headMap(propertyValue); } else { subMap = constantsMap.tailMap(propertyValue); } // All entries in the subMap are elgibile, with an exception EventEvaluator exactEquals = null; if (filterOperator == FilterOperator.LESS) { exactEquals = constantsMap.get(propertyValue); } for (EventEvaluator matcher : subMap.values()) { // For the LESS comparison type we ignore the exactly equal case // The subMap is sorted ascending, thus the exactly equals case is the first if (exactEquals != null) { exactEquals = null; continue; } matcher.matchEvent(theEvent, matches); } if (filterOperator == FilterOperator.GREATER_OR_EQUAL) { EventEvaluator matcher = constantsMap.get(propertyValue); if (matcher != null) { matcher.matchEvent(theEvent, matches); } } } finally { constantsMapRWLock.readLock().unlock(); } }