Given a Cartesian (two-dimensional) coordinate system like the following:

![kartesian coordinate system](https://i.stack.imgur.com/fG8rq.png)

Is it possible - and if, how - to calculate a unique, sortable index for each field? This means that, using the x and y coordinate, I want to calculate a index number ascending from left to right, top down. E.g.:

![unique numeric indexes](https://i.stack.imgur.com/OEQhs.png)

(only) the following conditions must be met:

* Index numbers must be unique (even for larger systems)
* Numbers must be ascending (but not necessarily consecutive) from left to right and from top to bottom
* Must be full, positive Integer values
* Must be realizable in Java

**What I found out yet:** Addition, Multiplication and Power (e.g. x\*y or x^y) doesn't work because different fields get the same index.

Method Body could look like the following:

```java
public Integer getIndex(Integer xCoordinate, Integer yCoordinate) {
  // ...
}

```

BTW: Coordinates are always positive (0 <= x < n)

Thanks for any advice.

SOLUTION:
---------

I solved the problem without calculating an index and used the simple comparable proposed by Teepeemm (see comments)