comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/ExternalIndexConverter.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.raster;
10
11 import org.apache.log4j.Logger;
12
13 /**
14 * Converts the interal color index of a polygon to the external index
15 * defined by the corresponding palette entry.
16 *
17 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
18 */
19 public class ExternalIndexConverter
20 implements JTSMultiPolygonProducer.ValueConverter
21 {
22 private static Logger log = Logger.getLogger(
23 ExternalIndexConverter.class);
24
25 /**
26 * The palette where to find the color indices.
27 */
28 protected Palette palette;
29
30 /**
31 * Default constructor.
32 */
33 public ExternalIndexConverter() {
34 }
35
36 /**
37 * Constrcutor to create an ExternalIndexConverter with
38 * a given palette.
39 * @param palette The palette where to find the color indices.
40 */
41 public ExternalIndexConverter(Palette palette) {
42 this.palette = palette;
43 }
44
45 /**
46 * Maps the color index of a polygon to the external index
47 * defined by the corresponing palette entry.
48 * @param value The value to convert
49 * @return The mapped value or the original value if
50 * no corresponing palette entry was found.
51 */
52 public Integer convert(Integer value) {
53 if (value == null) {
54 return value;
55 }
56
57 int v = value.intValue();
58
59 if (v == -1) {
60 return value;
61 }
62
63 Palette.Entry entry = palette.getEntryByIndex(v);
64
65 if (entry == null) {
66 log.warn("cannot find palette entry for index: " + v);
67 return value;
68 }
69
70 return Integer.valueOf(entry.getExternalIndex());
71 }
72 }
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org