Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/ExternalIndexConverter.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | feae2f9d6c6f |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.raster; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 /** | |
6 * Converts the interal color index of a polygon to the external index | |
7 * defined by the corresponding palette entry. | |
8 * | |
9 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
10 */ | |
11 public class ExternalIndexConverter | |
12 implements JTSMultiPolygonProducer.ValueConverter | |
13 { | |
14 private static Logger log = Logger.getLogger( | |
15 ExternalIndexConverter.class); | |
16 | |
17 /** | |
18 * The palette where to find the color indices. | |
19 */ | |
20 protected Palette palette; | |
21 | |
22 /** | |
23 * Default constructor. | |
24 */ | |
25 public ExternalIndexConverter() { | |
26 } | |
27 | |
28 /** | |
29 * Constrcutor to create an ExternalIndexConverter with | |
30 * a given palette. | |
31 * @param palette The palette where to find the color indices. | |
32 */ | |
33 public ExternalIndexConverter(Palette palette) { | |
34 this.palette = palette; | |
35 } | |
36 | |
37 /** | |
38 * Maps the color index of a polygon to the external index | |
39 * defined by the corresponing palette entry. | |
40 * @param value The value to convert | |
41 * @return The mapped value or the original value if | |
42 * no corresponing palette entry was found. | |
43 */ | |
44 public Integer convert(Integer value) { | |
45 if (value == null) { | |
46 return value; | |
47 } | |
48 | |
49 int v = value.intValue(); | |
50 | |
51 if (v == -1) { | |
52 return value; | |
53 } | |
54 | |
55 Palette.Entry entry = palette.getEntryByIndex(v); | |
56 | |
57 if (entry == null) { | |
58 log.warn("cannot find palette entry for index: " + v); | |
59 return value; | |
60 } | |
61 | |
62 return Integer.valueOf(entry.getExternalIndex()); | |
63 } | |
64 } | |
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |