comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportCrossSectionLine.java @ 4705:3199dbc20e22

Documentation added.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 19 Dec 2012 11:37:59 +0100
parents 2f874d14ac68
children 52c3a9d14441
comparison
equal deleted inserted replaced
4704:115afdaf3e85 4705:3199dbc20e22
10 import java.util.List; 10 import java.util.List;
11 import java.util.Comparator; 11 import java.util.Comparator;
12 import java.util.Map; 12 import java.util.Map;
13 import java.util.TreeMap; 13 import java.util.TreeMap;
14 14
15 /**
16 * A CrossSectionLine (containing points) ready to be transformed into a mapped
17 * object and written to db (used in importer).
18 */
15 public class ImportCrossSectionLine 19 public class ImportCrossSectionLine
16 { 20 {
17 public static final Comparator<CrossSectionPoint> INDEX_CMP = 21 public static final Comparator<CrossSectionPoint> INDEX_CMP =
18 new Comparator<CrossSectionPoint>() { 22 new Comparator<CrossSectionPoint>() {
19 public int compare(CrossSectionPoint a, CrossSectionPoint b) { 23 public int compare(CrossSectionPoint a, CrossSectionPoint b) {
53 57
54 public void storeDependencies() { 58 public void storeDependencies() {
55 storePoints(); 59 storePoints();
56 } 60 }
57 61
62
63 /** Write a line and its points. */
58 protected void storePoints() { 64 protected void storePoints() {
59 CrossSectionLine csl = getPeer(); 65 CrossSectionLine csl = getPeer();
60 66
61 Map<CrossSectionPoint, CrossSectionPoint> map = 67 Map<CrossSectionPoint, CrossSectionPoint> map =
62 new TreeMap<CrossSectionPoint, CrossSectionPoint>(INDEX_CMP); 68 new TreeMap<CrossSectionPoint, CrossSectionPoint>(INDEX_CMP);
63 69
64 // build index for faster collision lookup 70 // Build index for faster (index) collision lookup.
65 List<CrossSectionPoint> ps = csl.getPoints(); 71 List<CrossSectionPoint> ps = csl.getPoints();
66 if (ps != null) { 72 if (ps != null) {
67 for (CrossSectionPoint point: ps) { 73 for (CrossSectionPoint point: ps) {
68 map.put(point, point); 74 map.put(point, point);
69 } 75 }
72 Session session = 78 Session session =
73 ImporterSession.getInstance().getDatabaseSession(); 79 ImporterSession.getInstance().getDatabaseSession();
74 80
75 CrossSectionPoint key = new CrossSectionPoint(); 81 CrossSectionPoint key = new CrossSectionPoint();
76 82
83 // Somehow it looks as if even with the map it is still possible that
84 // multiple points with same id enter hibernate (and then violate a
85 // constraint). -> TODO
77 for (XY xy: points) { 86 for (XY xy: points) {
78 key.setColPos(xy.getIndex()); 87 key.setColPos(xy.getIndex());
79 CrossSectionPoint csp = map.get(key); 88 CrossSectionPoint csp = map.get(key);
80 if (csp == null) { // create new 89 if (csp == null) { // create new
81 csp = new CrossSectionPoint( 90 csp = new CrossSectionPoint(

http://dive4elements.wald.intevation.org