annotate flys-backend/src/main/java/de/intevation/flys/importer/IdValueKey.java @ 498:8ab04de0b879

Importer: Cache the discharge table values, too. flys-backend/trunk@1852 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 08 May 2011 17:55:49 +0000
parents
children d50cd3a632e0
rev   line source
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.importer;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import de.intevation.flys.model.WstColumnValue;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import de.intevation.flys.model.DischargeTableValue;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 public class IdValueKey {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 protected int id;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 protected double a;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 protected double b;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 public IdValueKey(WstColumnValue value) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 this.id = value.getWstColumn().getId();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 this.a = value.getPosition().doubleValue();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 this.b = value.getW().doubleValue();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public IdValueKey(DischargeTableValue value) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 this.id = value.getDischargeTable().getId();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 this.a = value.getQ().doubleValue();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 this.b = value.getW().doubleValue();
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public IdValueKey(int id, double a, double b) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 this.id = id;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 this.a = a;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this.b = b;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 private static final int hashDouble(double d) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 long v = Double.doubleToLongBits(d);
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 return (int)(v^(v>>>32));
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public int hashCode() {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 int a = id;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 int b = hashDouble(a);
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 int c = hashDouble(b);
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 return (a | (b << 10) | (c << 20));
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public boolean equals(Object obj) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 if (!(obj instanceof IdValueKey)) {
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 return false;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 IdValueKey other = (IdValueKey) obj;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return id == other.id
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 && a == other.a
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 && b == other.b;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org