Skip to content
Browse files
Document the Position comparison order
* Add JavaDoc
* Reverse ordering
* Add unit test
  • Loading branch information
tmaret committed Jan 3, 2019
1 parent 6668996 commit baa5cc7757a8fe7d2c19225faa6ce7d2256b13bd
Showing 3 changed files with 48 additions and 1 deletion.
@@ -21,6 +21,12 @@
* Position in a the topic.
* E.g. For a kafka implementation this would be a list of (partition, offset) as we do not support partitions
* this could simply be like an offset.
* The {@code Position} positions are ordered. The relative order between
* two positions can be computed by invoking {@code Comparable#compareTo}.
* Comparing this position with a specified position will return a negative
* integer, zero, or a positive integer as this position happened before,
* happened concurrently, or happened after the specified position.
public interface Position extends Comparable<Position> {

@@ -38,6 +38,6 @@ public String positionToString() {

public int compareTo(Position p) {
return, offset);
return, ((MemoryPosition)p).offset);
@@ -0,0 +1,41 @@
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The SF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MemoryPositionTest {

public void testCompareTo() throws Exception {
assertEquals(0, comparePositions(position(5), position(5)));
assertEquals(1, comparePositions(position(10), position(5)));
assertEquals(-1, comparePositions(position(2), position(5)));

private int comparePositions(MemoryPosition position1, MemoryPosition position2) {
return position1.compareTo(position2);

private MemoryPosition position(long offset) {
return new MemoryPosition(offset);


0 comments on commit baa5cc7

Please sign in to comment.