2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
;
9 import gov
.nasa
.worldwind
.geom
.*;
13 * @version $Id: TileKey.java 511 2007-01-17 07:26:02Z ericdalgliesh $
15 public class TileKey
implements Comparable
<TileKey
>
17 private final int level
;
18 private final int row
;
19 private final int col
;
20 private final String cacheName
;
21 private final int hash
;
28 * @throws IllegalArgumentException if <code>level</code>, <code>row</code> or <code>column</code> is negative or if
29 * <code>cacheName</code> is null or empty
31 public TileKey(int level
, int row
, int col
, String cacheName
)
35 String msg
= WorldWind
.retrieveErrMsg("TileKey.levelIsLessThanZero");
36 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
37 throw new IllegalArgumentException(msg
);
41 String msg
= WorldWind
.retrieveErrMsg("generic.rowIndexOutOfRange");
42 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
43 throw new IllegalArgumentException(msg
);
47 String msg
= WorldWind
.retrieveErrMsg("generic.columnIndexOutOfRange");
48 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
49 throw new IllegalArgumentException(msg
);
51 if (cacheName
== null || cacheName
.length() < 1)
53 String msg
= WorldWind
.retrieveErrMsg("TileKey.cacheNameIsNullOrEmpty");
54 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
55 throw new IllegalArgumentException(msg
);
60 this.cacheName
= cacheName
;
61 this.hash
= this.computeHash();
68 * @throws IllegalArgumentException if any parameter is null
70 public TileKey(Angle latitude
, Angle longitude
, Level level
)
72 if (latitude
== null || longitude
== null)
74 String msg
= WorldWind
.retrieveErrMsg("nullValue.AngleIsNull");
75 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
76 throw new IllegalArgumentException(msg
);
80 String msg
= WorldWind
.retrieveErrMsg("nullValue.LevelIsNull");
81 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
82 throw new IllegalArgumentException(msg
);
84 this.level
= level
.getLevelNumber();
85 this.row
= Tile
.computeRow(level
.getTileDelta().getLatitude(), latitude
);
86 this.col
= Tile
.computeColumn(level
.getTileDelta().getLongitude(), longitude
);
87 this.cacheName
= level
.getCacheName();
88 this.hash
= this.computeHash();
93 * @throws IllegalArgumentException if <code>tile</code> is null
95 public TileKey(gov
.nasa
.worldwind
.Tile tile
)
99 String msg
= WorldWind
.retrieveErrMsg("nullValue.TileIsNull");
100 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
101 throw new IllegalArgumentException(msg
);
103 this.level
= tile
.getLevelNumber();
104 this.row
= tile
.getRow();
105 this.col
= tile
.getColumn();
106 this.cacheName
= tile
.getCacheName();
107 this.hash
= this.computeHash();
110 public int getLevelNumber()
120 public int getColumn()
125 public String
getCacheName()
130 private int computeHash()
134 result
= 29 * result
+ this.row
;
135 result
= 29 * result
+ this.col
;
136 result
= 29 * result
+ (this.cacheName
!= null ?
this.cacheName
.hashCode() : 0);
143 * @throws IllegalArgumentException if <code>key</code> is null
145 public final int compareTo(TileKey key
)
149 String msg
= WorldWind
.retrieveErrMsg("nullValue.KeyIsNull");
150 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, msg
);
151 throw new IllegalArgumentException(msg
);
154 // No need to compare Sectors because they are redundant with row and column
155 if (key
.level
== this.level
&& key
.row
== this.row
&& key
.col
== this.col
)
158 if (this.level
< key
.level
) // Lower-res levels compare lower than higher-res
160 if (this.level
> key
.level
)
163 if (this.row
< key
.row
)
165 if (this.row
> key
.row
)
168 if (this.col
< key
.col
)
171 return 1; // tile.col must be > this.col because equality was tested above
175 public boolean equals(Object o
)
179 if (o
== null || getClass() != o
.getClass())
182 final TileKey tileKey
= (TileKey
) o
;
184 if (this.col
!= tileKey
.col
)
186 if (this.level
!= tileKey
.level
)
188 if (this.row
!= tileKey
.row
)
191 return !(this.cacheName
!= null ?
!this.cacheName
.equals(tileKey
.cacheName
) : tileKey
.cacheName
!= null);
195 public int hashCode()
201 public String
toString()
203 return this.cacheName
+ "/" + this.level
+ "/" + this.row
+ "/" + col
;