svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.geometry / org.gvsig.expressionevaluator.geometry.lib / org.gvsig.expressionevaluator.geometry.lib.api / src / main / java / org / gvsig / expressionevaluator / spi / AbstractGeometryFunction.java @ 44644
History | View | Annotate | Download (3.98 KB)
1 |
package org.gvsig.expressionevaluator.spi; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.InputStream; |
5 |
import java.net.URI; |
6 |
import java.net.URISyntaxException; |
7 |
import java.net.URL; |
8 |
import java.time.LocalDateTime; |
9 |
import java.time.ZoneId; |
10 |
import java.time.temporal.TemporalAccessor; |
11 |
import java.util.ArrayList; |
12 |
import java.util.Date; |
13 |
import java.util.List; |
14 |
import java.util.Locale; |
15 |
import java.util.Objects; |
16 |
import org.apache.commons.io.IOUtils; |
17 |
import org.apache.commons.lang3.BooleanUtils; |
18 |
import org.apache.commons.lang3.Range; |
19 |
import org.apache.commons.lang3.StringUtils; |
20 |
import org.apache.commons.math.util.MathUtils; |
21 |
import org.gvsig.expressionevaluator.Code; |
22 |
import org.gvsig.expressionevaluator.Codes; |
23 |
import org.gvsig.expressionevaluator.Function; |
24 |
import org.gvsig.expressionevaluator.I18N; |
25 |
import org.gvsig.expressionevaluator.Interpreter; |
26 |
import org.gvsig.fmap.geom.Geometry; |
27 |
import org.gvsig.fmap.geom.primitive.Point; |
28 |
import org.json.JSONArray; |
29 |
import org.json.JSONObject; |
30 |
|
31 |
@SuppressWarnings("UseSpecificCatch") |
32 |
public abstract class AbstractGeometryFunction |
33 |
extends AbstractFunction
|
34 |
implements Function
|
35 |
{ |
36 |
|
37 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType, boolean sqlCompatible) { |
38 |
super(group, name, argc, description, template, descriptionArgs, returnType, sqlCompatible);
|
39 |
} |
40 |
|
41 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) { |
42 |
this(group, name, argc, description, template, descriptionArgs, returnType, false); |
43 |
} |
44 |
|
45 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs) { |
46 |
this(group, name, argc, description, template, null, null); |
47 |
} |
48 |
|
49 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template) { |
50 |
this(group, name, argc, description, template, null, null); |
51 |
} |
52 |
|
53 |
protected AbstractGeometryFunction(String group, String name, Range argc) { |
54 |
this(group, name, argc, null, null, null, null); |
55 |
} |
56 |
|
57 |
|
58 |
protected Geometry getGeom(Object[] args, int n) { |
59 |
return this.getGeom(args, n, false); |
60 |
} |
61 |
|
62 |
protected Geometry getGeom(Object[] args, int n, boolean allowNull) { |
63 |
if( args.length < n ) {
|
64 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
65 |
} |
66 |
Object value = args[n];
|
67 |
if( value == null ) { |
68 |
if( allowNull ) {
|
69 |
return null; |
70 |
} |
71 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
72 |
} |
73 |
if( !(value instanceof Geometry) ) { |
74 |
String type = value.getClass().getCanonicalName();
|
75 |
throw new IllegalArgumentException( |
76 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
77 |
I18N.Expected_XexpectedX_and_found_XfoundX("Geometry",type)
|
78 |
); |
79 |
} |
80 |
return (Geometry)value;
|
81 |
} |
82 |
|
83 |
protected Point getPoint(Object[] args, int n) { |
84 |
if( args.length < n ) {
|
85 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
86 |
} |
87 |
Object value = args[n];
|
88 |
if( value == null ) { |
89 |
return null; |
90 |
} |
91 |
if( !(value instanceof Point) ) { |
92 |
String type = value.getClass().getCanonicalName();
|
93 |
throw new IllegalArgumentException( |
94 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
95 |
I18N.Expected_XexpectedX_and_found_XfoundX("Point",type)
|
96 |
); |
97 |
} |
98 |
return (Point)value; |
99 |
} |
100 |
|
101 |
} |