File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\mvstore\rtree\SpatialKey.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.mvstore.rtree;
8
9 import java.util.Arrays;
10
11 /**
12 * A unique spatial key.
13 */
14 public class SpatialKey {
15
16 private final long id;
17 private final float[] minMax;
18
19 /**
20 * Create a new key.
21 *
22 * @param id the id
23 * @param minMax min x, max x, min y, max y, and so on
24 */
25 public SpatialKey(long id, float... minMax) {
26 this.id = id;
27 this.minMax = minMax;
28 }
29
30 /**
31 * Get the minimum value for the given dimension.
32 *
33 * @param dim the dimension
34 * @return the value
35 */
36 public float min(int dim) {
37 return minMax[dim + dim];
38 }
39
40 /**
41 * Set the minimum value for the given dimension.
42 *
43 * @param dim the dimension
44 * @param x the value
45 */
46 public void setMin(int dim, float x) {
47 minMax[dim + dim] = x;
48 }
49
50 /**
51 * Get the maximum value for the given dimension.
52 *
53 * @param dim the dimension
54 * @return the value
55 */
56 public float max(int dim) {
57 return minMax[dim + dim + 1];
58 }
59
60 /**
61 * Set the maximum value for the given dimension.
62 *
63 * @param dim the dimension
64 * @param x the value
65 */
66 public void setMax(int dim, float x) {
67 minMax[dim + dim + 1] = x;
68 }
69
70 public long getId() {
71 return id;
72 }
73
74 public String toString() {
75 StringBuilder buff = new StringBuilder();
76 buff.append(id).append(": (");
77 for (int i = 0; i < minMax.length; i += 2) {
78 if (i > 0) {
79 buff.append(", ");
80 }
81 buff.append(minMax[i]).append('/').append(minMax[i + 1]);
82 }
83 return buff.append(")").toString();
84 }
85
86 public int hashCode() {
87 return (int) ((id >>> 32) ^ id);
88 }
89
90 public boolean equals(Object other) {
91 if (!(other instanceof SpatialKey)) {
92 return false;
93 }
94 SpatialKey o = (SpatialKey) other;
95 return Arrays.equals(minMax, o.minMax);
96 }
97
98 }
99