8 package cz.vutbr.fit.knot.annotations.entity.attribute;
12 import java.math.BigDecimal;
13 import java.util.ArrayList;
15 import javax.persistence.DiscriminatorValue;
16 import javax.persistence.Entity;
17 import javax.persistence.NamedQueries;
18 import javax.persistence.NamedQuery;
33 @DiscriminatorValue(
"GeoPoint")
35 @NamedQuery(name =
"Attribute.findByGeoLat", query =
"SELECT a FROM Attribute a WHERE a.geoLat = :geoLat"),
36 @NamedQuery(name =
"Attribute.findByGeoLong", query =
"SELECT a FROM Attribute a WHERE a.geoLong = :geoLong")
56 this.simpleType =
"GeoPoint";
58 this.geoLong = geoLong;
59 this.refAnnotation = refAnnotation;
69 return new GeoPoint(geoLat, geoLong);
79 this.geoLat = ((
GeoPoint) value).getLatitude();
80 this.geoLong = ((
GeoPoint) value).getLongitude();
101 if (geoLat == null || geoLong == null) {
105 +
"<geo:lat>" + geoLat.toPlainString() +
"</geo:lat> "
106 +
"<geo:long>" + geoLong.toPlainString() +
"</geo:long>"
116 public void setRawValues(Object values)
throws IllegalArgumentException {
117 @SuppressWarnings(
"unchecked") ArrayList<Object> valuesArray = (ArrayList<Object>)values;
118 @SuppressWarnings(
"unchecked") Map<String,String> tag = (Map<String,String>)valuesArray.get(0);
120 String latitude = tag.get(
"geo:lat");
121 String longitude = tag.get(
"geo:long");
124 this.geoLat =
new BigDecimal(latitude);
125 this.geoLong =
new BigDecimal(longitude);
126 }
catch (NumberFormatException e) {
127 throw new IllegalArgumentException(
"Latitude or Longitude is not valid Decimal value.");
156 public void setStringValue(String GPointEncoded)
throws IllegalArgumentException {
158 if (GPointEncoded.equals(
"null")) {
163 String[] Points = GPointEncoded.split(
" ");
164 if (Points.length == 2) {
166 this.geoLat =
new BigDecimal(Points[0]);
167 this.geoLong =
new BigDecimal(Points[1]);
168 }
catch (NumberFormatException e) {
169 throw new IllegalArgumentException(
"Latitude or Longitude is not valid Decimal value.");
172 throw new IllegalArgumentException(
"Too many words in String.");
177 public void setStringValue(String latitude, String longitude)
throws IllegalArgumentException{
178 if(latitude == null && longitude == null){
182 if(latitude == null || longitude == null){
183 throw new IllegalArgumentException(
"Latitude or Longitude value is null");
187 this.geoLat =
new BigDecimal(latitude);
188 this.geoLong =
new BigDecimal(longitude);
189 }
catch (NumberFormatException e) {
190 throw new IllegalArgumentException(
"Latitude or Longitude is not valid Decimal value.");
203 StringBuilder sb =
new StringBuilder();
204 if (this.geoLat != null) {
205 sb.append(this.geoLat.toString());
208 if (this.geoLong != null) {
209 sb.append(this.geoLong.toString());
211 return sb.toString();
249 public GeoPoint(BigDecimal latitude, BigDecimal longitude) {
250 this.latitude = latitude;
251 this.longitude = longitude;
278 this.latitude = value;
287 this.longitude = value;
String getXmlAttributeName()
Abstract class representing more complex attribute.
void setLongitude(BigDecimal value)
void setStringValue(String latitude, String longitude)
void setRawValues(Object values)
void setLatitude(BigDecimal value)
BigDecimal getLongitude()
This class represents GeoPoint value.
String getTypeOntologyUri()
void setStringValue(String GPointEncoded)
static final String GEO_POINT_URI
GeoPoint(BigDecimal latitude, BigDecimal longitude)
void setValue(Object value)
GeoPointAttribute(String name, BigDecimal geoLat, BigDecimal geoLong, Annotation refAnnotation)
Class representing attribute of type GeoPoint.
Class representing annotation.