Source:
private <T extends Item> Collection<T> executeQuery(final AttributeQuery query, final Class<T> itemClass) { final Map<ItemId, T> allItems = getAllItems(itemClass); final Collection<T> matches = new ArrayList<>(); for (final T item : allItems.values()) { final String attribute = query.getAttributeName(); try { final Method getter = new PropertyDescriptor(attribute, item.getClass()).getReadMethod(); final Object itemPropertyValue = getter.invoke(item); final Class<?> itemPropertyType = getter.getReturnType(); final Condition condition = query.getCondition(); final Set<String> values = condition.getValues(); String singleValue = null; if (values != null && !values.isEmpty()) { singleValue = values.iterator().next(); } final boolean isSingleItemProperty = !Collection.class.isAssignableFrom(itemPropertyType); String singleItemPropertyValue = null; if (isSingleItemProperty) { singleItemPropertyValue = String.valueOf(itemPropertyValue); } switch (query.getCondition().getComparisonOperator()) { case NULL: if (itemPropertyValue == null) { matches.add(item); } break; case NOT_NULL: if (itemPropertyValue != null) { matches.add(item); } break; case LESS_THAN_OR_EQUALS: if (isSingleItemProperty && singleItemPropertyValue.compareTo(singleValue) <= 0) { matches.add(item); } break; case GREATER_THAN_OR_EQUALS: if (isSingleItemProperty && singleItemPropertyValue.compareTo(singleValue) >= 0) { matches.add(item); } break; case EQUALS: if (isSingleItemProperty && singleItemPropertyValue.equals(singleValue)) { matches.add(item); } else if (values.equals(itemPropertyValue)) { matches.add(item); } break; default: break; } } catch (final Exception e) { e.printStackTrace(); throw new IllegalStateException("No getter for property [" + attribute + "] on class: [" + item.getClass() + "]"); } } return matches; }

Target:
private <T extends Item> Collection<T> executeQuery(final AttributeQuery query, final Class<T> itemClass) { final Map<ItemId, T> allItems = getAllItems(itemClass); final Collection<T> matches = new ArrayList<>(); for (final T item : allItems.values()) { final String attribute = query.getAttributeName(); try { final Method getter = new PropertyDescriptor(attribute, item.getClass()).getReadMethod(); final Object itemPropertyValue = getter.invoke(item); final Class<?> itemPropertyType = getter.getReturnType(); final Condition condition = query.getCondition(); final Set<String> values = condition.getValues(); String singleValue = null; if (values != null && !values.isEmpty()) { singleValue = values.iterator().next(); } final boolean isSingleItemProperty = !Collection.class.isAssignableFrom(itemPropertyType); String singleItemPropertyValue = null; if (isSingleItemProperty) { singleItemPropertyValue = String.valueOf(itemPropertyValue); } switch (query.getCondition().getComparisonOperator()) { case NULL: if (itemPropertyValue == null) { matches.add(item); } break; case NOT_NULL: if (itemPropertyValue != null) { matches.add(item); } break; case LESS_THAN_OR_EQUALS: if (isSingleItemProperty && singleItemPropertyValue.compareTo(singleValue) <= 0) { matches.add(item); } break; case GREATER_THAN_OR_EQUALS: if (isSingleItemProperty && singleItemPropertyValue.compareTo(singleValue) >= 0) { matches.add(item); } break; case EQUALS: if (isSingleItemProperty && singleItemPropertyValue.equals(singleValue)) { matches.add(item); } else if (values.equals(itemPropertyValue)) { matches.add(item); } break; default: break; } } catch (final Exception e) { throw new IllegalStateException("No getter for property [" + attribute + "] on class: [" + item.getClass() + "]"); } } return matches; }