svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src / org / gvsig / geocoding / address / impl / DefaultAddress.java @ 28375
History | View | Annotate | Download (3.67 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L. main development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.address.impl; |
29 |
|
30 |
import org.gvsig.geocoding.address.Address; |
31 |
import org.gvsig.geocoding.address.AddressComponent; |
32 |
import org.gvsig.geocoding.address.Literal; |
33 |
import org.gvsig.tools.persistence.PersistenceException; |
34 |
import org.gvsig.tools.persistence.PersistentState; |
35 |
|
36 |
/**
|
37 |
* Address class implementation, this class has the elements to locate one place
|
38 |
*
|
39 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
40 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
41 |
*/
|
42 |
public class DefaultAddress implements Address { |
43 |
|
44 |
private static final String MAINLITERAL = "mainliteral"; |
45 |
private Literal mainLiteral = new DefaultLiteral(); |
46 |
|
47 |
/**
|
48 |
* Default address constructor
|
49 |
*
|
50 |
*/
|
51 |
public DefaultAddress() {
|
52 |
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Constructor with literal parameter
|
57 |
*
|
58 |
* @param main
|
59 |
*/
|
60 |
public DefaultAddress(Literal main) {
|
61 |
this();
|
62 |
this.mainLiteral = main;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Get the address main literal
|
67 |
*
|
68 |
* @return
|
69 |
*/
|
70 |
public Literal getMainLiteral() {
|
71 |
return mainLiteral;
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* set the address main literal
|
76 |
*
|
77 |
* @param literal
|
78 |
*/
|
79 |
public void setMainLiteral(Literal literal) { |
80 |
this.mainLiteral = literal;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Add new component to address main literal
|
85 |
*
|
86 |
* @param component
|
87 |
*/
|
88 |
public void addAddressComponent(AddressComponent component) { |
89 |
mainLiteral.add(component); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Clear all address main literal elements
|
94 |
*/
|
95 |
public void clearAddress() { |
96 |
mainLiteral.clear(); |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Compare this address with other address
|
101 |
*/
|
102 |
public int compareTo(Address address) { |
103 |
boolean equal = true; |
104 |
Literal literal = this.getMainLiteral();
|
105 |
Literal otherLiteral = address.getMainLiteral(); |
106 |
for (int i = 0; i < literal.size(); i++) { |
107 |
DefaultAddressComponent comp = (DefaultAddressComponent) literal |
108 |
.get(i); |
109 |
DefaultAddressComponent othercomp = (DefaultAddressComponent) otherLiteral |
110 |
.get(i); |
111 |
String value = comp.getValue();
|
112 |
String othervalue = othercomp.getValue();
|
113 |
if (value.compareTo(othervalue) != 0) { |
114 |
equal = false;
|
115 |
} |
116 |
} |
117 |
if (equal) {
|
118 |
return 1; |
119 |
} else
|
120 |
return -1; |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Saves the internal state of the object on the provided PersistentState
|
125 |
* object.
|
126 |
*
|
127 |
* @param state
|
128 |
*/
|
129 |
public void saveToState(PersistentState state) throws PersistenceException { |
130 |
state.set(MAINLITERAL, this.mainLiteral);
|
131 |
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Set the state of the object from the state passed as parameter.
|
136 |
*
|
137 |
* @param state
|
138 |
*/
|
139 |
public void setState(PersistentState state) throws PersistenceException { |
140 |
this.mainLiteral = (Literal) state.get(MAINLITERAL);
|
141 |
|
142 |
} |
143 |
} |