Debian Codegraph @

src/uk/me/parabola/imgfmt/app/trergn/Overview.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2006 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 09-Dec-2006
16 */
17 package uk.me.parabola.imgfmt.app.trergn;
18
19 import uk.me.parabola.imgfmt.app.ImgFileWriter;
20
21 /**
22 * This is for polyline, polygon and point overviews. A simple record that
23 * holds the type of an object and the highest level at which it is found.
24 *
25 * It kind of declares which objects will appear in the map and if they
26 * are not included here they will not be shown.
27 *
28 * @author Steve Ratcliffe
29 */
30 public abstract class Overview implements Comparable<Overview> {
31 public static final int POINT_KIND = 1;
32 public static final int LINE_KIND = 2;
33 public static final int SHAPE_KIND = 3;
34
35 private final int kind; // The kind of overview; point, line etc.
36 private final int extType;
37 private final int type;
38 private final int subType;
39 private final int minResolution;
40 private final int size;
41
42 private int maxLevel;
43
44 protected Overview(int kind, int fullType, int minres) {
45 this.kind = kind;
46
47 this.extType = fullType >> 16;
48 this.type = (fullType >> 8) & 0xff;
49 this.subType = fullType & 0xff;
50 this.minResolution = minres;
51
52 if (kind == POINT_KIND)
53 size = 3;
54 else
55 size = 2;
56 }
57
58 public void write(ImgFileWriter file) {
59 if (extType == 0) {
60 file.put1u(type);
61 file.put1u(maxLevel);
62 if (size > 2)
63 file.put1u(subType);
64 } else {
65 file.put1u(type);
66 file.put1u(maxLevel);
67 file.put1u(subType);
68 file.put1u(0);
69 }
70 }
71
72 /**
73 * Returns a hash code value for the object.
74 *
75 * @return a hash code value for this object.
76 * @see Object#equals(Object)
77 */
78 public int hashCode() {
79 return (kind << 7) + (type << 3) + subType;
80 }
81
82 /**
83 * Indicates whether some other object is "equal to" this one.
84 *
85 * @param obj the reference object with which to compare.
86 * @return <code>true</code> if this object is the same as the obj
87 * argument; <code>false</code> otherwise.
88 * @see #hashCode()
89 */
90 public boolean equals(Object obj) {
91 if (!(obj instanceof Overview))
92 return false;
93
94 Overview ov = (Overview) obj;
95 return (ov.kind == kind &&
96 ov.extType == extType &&
97 ov.type == type &&
98 ov.subType == subType);
99 }
100
101 public int getKind() {
102 return kind;
103 }
104
105 /**
106 * Compares this object with the specified object for order. Returns a
107 * negative integer, zero, or a positive integer as this object is less
108 * than, equal to, or greater than the specified object.
109 *
110 * @param ov the object to be compared.
111 * @return a negative integer, zero, or a positive integer as this object
112 * is less than, equal to, or greater than the specified object.
113 * @throws ClassCastException if the specified object's type prevents it
114 * from being compared to this object.
115 */
116 public int compareTo(Overview ov) {
117 if (kind != ov.kind) {
118 return kind > ov.kind ? 1 : -1;
119 }
120
121 if(extType != ov.extType) {
122 return extType > ov.extType? 1: -1;
123 }
124
125 int res;
126 if (type == ov.type) {
127 if (subType == ov.subType)
128 res = 0;
129 else if (subType > ov.subType)
130 res = 1;
131 else
132 res = -1;
133 } else {
134 if (type == ov.type)
135 res = 0;
136 else if (type > ov.type)
137 res = 1;
138 else
139 res = -1;
140 }
141 return res;
142 }
143
144 public void setMaxLevel(int maxLevel) {
145 this.maxLevel = maxLevel;
146 }
147
148 public int getMinResolution() {
149 return minResolution;
150 }
151
152 public boolean hasExtType() {
153 return extType != 0;
154 }
155 }