--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2012 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.maps.tile;
+
+/**
+ * @author Tuukka Lehtonen
+ *
+ */
+public class TileKey {
+
+ /**
+ * Valid values within {0, 1, 2,... , n}. When the value is 0, the only
+ * valid (x,y) values are in {(0,0), (1,0)}, meaning half of the whole
+ * globe. Every time the value of level increases by one, the map is
+ * subdivided by 4 in the x direction and by two in the y direction, i.e.
+ * into eight equal size parts.
+ */
+ private final int level;
+
+ private final int x;
+
+ private final int y;
+
+ private final int hash;
+
+ public TileKey(int level, int x, int y) {
+ this.level = level;
+ this.x = x;
+ this.y = y;
+ this.hash = hash();
+ }
+
+ private int hash() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + level;
+ result = prime * result + x;
+ result = prime * result + y;
+ return result;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final TileKey other = (TileKey) obj;
+ if (level != other.level)
+ return false;
+ if (x != other.x)
+ return false;
+ if (y != other.y)
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "TileKey [level=" + level + ", x=" + x + ", y=" + y + "]";
+ }
+
+}