private Map<TopicPartition, Long> checkOffsetsRange(Map<TopicPartition, Long> requestedOffsets) {
            Map<TopicPartition, LogOffsetResult> logStartOffsets = getLogStartOffsets(requestedOffsets.keySet());
            Map<TopicPartition, LogOffsetResult> logEndOffsets = getLogEndOffsets(requestedOffsets.keySet());

            Map<TopicPartition, Long> res = new HashMap<>();

            requestedOffsets.forEach((topicPartition, offset) -> {
                LogOffsetResult logEndOffset = logEndOffsets.get(topicPartition);

                if (logEndOffset != null) {
                    if (logEndOffset instanceof LogOffset && offset > ((LogOffset) logEndOffset).value) {
                        long endOffset = ((LogOffset) logEndOffset).value;
                        LOGGER.warn("New offset (" + offset + ") is higher than latest offset for topic partition " + topicPartition + ". Value will be set to " + endOffset);
                        res.put(topicPartition, endOffset);
                    } else {
                        LogOffsetResult logStartOffset = logStartOffsets.get(topicPartition);

                        if (logStartOffset instanceof LogOffset && offset < ((LogOffset) logStartOffset).value) {
                            long startOffset = ((LogOffset) logStartOffset).value;
                            LOGGER.warn("New offset (" + offset + ") is lower than earliest offset for topic partition " + topicPartition + ". Value will be set to " + startOffset);
                            res.put(topicPartition, startOffset);
                        } else
                            res.put(topicPartition, offset);
                    }
                } else {
                    // the control should not reach here
                    throw new IllegalStateException("Unexpected non-existing offset value for topic partition " + topicPartition);
                }
            });

            return res;
        }
Returns states of the specified consumer groups and partition assignment states
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java