root / branches / Mobile_Compatible_Hito_1 / libFMap_data / src / org / gvsig / data / vectorial / filter / DivideImpl.java @ 21563
History | View | Annotate | Download (2.47 KB)
1 |
/*
|
---|---|
2 |
* GeoTools - OpenSource mapping toolkit
|
3 |
* http://geotools.org
|
4 |
* (C) 2006, GeoTools Project Managment Committee (PMC)
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation;
|
9 |
* version 2.1 of the License.
|
10 |
*
|
11 |
* This library 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 GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*/
|
16 |
package org.gvsig.data.vectorial.filter; |
17 |
|
18 |
import org.opengis.filter.expression.Divide; |
19 |
import org.opengis.filter.expression.Expression; |
20 |
import org.opengis.filter.expression.ExpressionVisitor; |
21 |
|
22 |
/**
|
23 |
* Implementation of divide expression.
|
24 |
*
|
25 |
* @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
|
26 |
*
|
27 |
*/
|
28 |
public class DivideImpl implements Divide { |
29 |
Expression exp1;
|
30 |
Expression exp2;
|
31 |
public DivideImpl(Expression expr1, Expression expr2) { |
32 |
exp1=expr1; |
33 |
exp2=expr2; |
34 |
} |
35 |
|
36 |
public Object evaluate(Object feature) { |
37 |
|
38 |
double leftDouble = FilterUtils.number( getExpression1().evaluate(feature) );
|
39 |
double rightDouble = FilterUtils.number( getExpression2().evaluate(feature) );
|
40 |
|
41 |
return new Double(leftDouble / rightDouble); |
42 |
} |
43 |
|
44 |
public Object accept(ExpressionVisitor visitor, Object extraData) { |
45 |
return visitor.visit(this,extraData); |
46 |
} |
47 |
|
48 |
/**
|
49 |
* Compares this expression to the specified object. Returns true if the
|
50 |
*
|
51 |
* @param obj - the object to compare this expression against.
|
52 |
*
|
53 |
* @return true if specified object is equal to this expression; false
|
54 |
* otherwise.
|
55 |
*/
|
56 |
public boolean equals(Object obj) { |
57 |
if (obj instanceof SubtractImpl) { |
58 |
SubtractImpl other = (SubtractImpl) obj; |
59 |
|
60 |
return exp1.equals(other.exp1)
|
61 |
&& exp2.equals(other.exp2); |
62 |
|
63 |
} else {
|
64 |
return false; |
65 |
} |
66 |
} |
67 |
|
68 |
|
69 |
public String toString() { |
70 |
return "(" + getExpression1().toString() + "-" + getExpression2().toString()+ ")"; |
71 |
} |
72 |
|
73 |
/**
|
74 |
* We are not using context
|
75 |
*/
|
76 |
public Object evaluate(Object arg0, Class arg1) { |
77 |
return evaluate(arg0);
|
78 |
} |
79 |
|
80 |
public Expression getExpression1() { |
81 |
return exp1;
|
82 |
} |
83 |
|
84 |
public Expression getExpression2() { |
85 |
return exp2;
|
86 |
} |
87 |
|
88 |
} |