public void getSubRecords( MultiResultSet results, PredicateType predicateType, Long searchedValue) { Set<Long> values = null; boolean notEqual = false; switch (predicateType) { case LESSER: values = sortedSet.headSet(searchedValue, false); break; case LESSER_EQUAL: values = sortedSet.headSet(searchedValue, true); break; case GREATER: values = sortedSet.tailSet(searchedValue, false); break; case GREATER_EQUAL: values = sortedSet.tailSet(searchedValue, true); break; case NOT_EQUAL: values = sortedSet; notEqual = true; break; } if (values != null) { for (Long value : values) { if (notEqual && searchedValue.longValue() == value.longValue()) { // skip this value if predicateType is NOT_EQUAL continue; } ConcurrentMap<Long, Record> records = mapRecords.get(value); if (records != null) { results.addResultSet(value, records.values()); } } } }