added javadocs

This commit is contained in:
Timo Westkämper 2009-11-05 09:41:45 +00:00
parent a62741eb5f
commit 57f13de5fa
9 changed files with 180 additions and 47 deletions

View File

@ -20,18 +20,42 @@ public abstract class EDateOrTime<D extends Comparable> extends EComparable<D> {
super(type);
}
/**
* Create a <code>this &gt; right</code> expression
*
* @param right
* @return
*/
public EBoolean after(D right) {
return gt(right);
}
/**
* Create a <code>this &gt; right</code> expression
*
* @param right
* @return
*/
public EBoolean after(Expr<D> right) {
return gt(right);
}
/**
* Create a <code>this &lt; right</code> expression
*
* @param right
* @return
*/
public EBoolean before(D right) {
return lt(right);
}
/**
* Create a <code>this &lt; right</code> expression
*
* @param right
* @return
*/
public EBoolean before(Expr<D> right) {
return lt(right);
}

View File

@ -116,19 +116,21 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
return random;
}
private volatile ENumber<D> abs, sum, min, max;
private volatile ENumber<D> abs, sum, min, max, floor, ceil;
private volatile ENumber<Double> avg, sqrt;
private volatile ENumber<D> negation;
private volatile ENumber<D> round, floor, ceil;
private volatile ENumber<Integer> round;
public ENumber(Class<? extends D> type) {
super(type);
}
/**
* Get the absolute value of this expression
*
* @return abs(this)
*/
public ENumber<D> abs() {
@ -139,6 +141,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the sum of this and right
*
* @param right
* @return this + right
*/
@ -147,6 +151,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the sum of this and right
*
* @param right
* @return this + right
*/
@ -155,6 +161,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the average value of this expression (aggregation)
*
* @return avg(this)
*/
public ENumber<Double> avg(){
@ -211,6 +219,10 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Returns the smallest (closest to negative infinity)
* <code>double</code> value that is greater than or equal to the
* argument and is equal to a mathematical integer
*
* @return ceil(this)
* @see java.lang.Math#ceil(double)
*/
@ -222,18 +234,22 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the result of the operation this / right
*
* @param right
* @return this / right
*/
public <N extends Number & Comparable<?>> ENumber<Double> div(Expr<N> right) {
public <N extends Number & Comparable<?>> ENumber<Double> divide(Expr<N> right) {
return ONumber.create(Double.class, Ops.DIV, this, right);
}
/**
* Get the result of the operation this / right
*
* @param right
* @return this / right
*/
public <N extends Number & Comparable<?>> ENumber<Double> div(N right) {
public <N extends Number & Comparable<?>> ENumber<Double> divide(N right) {
return ONumber.create(Double.class, Ops.DIV, this, ENumber.create(right));
}
@ -259,6 +275,10 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Returns the largest (closest to positive infinity)
* <code>double</code> value that is less than or equal to the
* argument and is equal to a mathematical integer.
*
* @return floor(this)
* @see java.lang.Math#floor(double)
*/
@ -386,6 +406,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the maximum value of this expression (aggregation)
*
* @return max(this)
*/
public ENumber<D> max(){
@ -396,6 +418,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the minimum value of this expression (aggregation)
*
* @return min(this)
*/
public ENumber<D> min(){
@ -406,18 +430,22 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the result of the operation this * right
*
* @param right
* @return this * right
*/
public <N extends Number & Comparable<?>> ENumber<D> mult(Expr<N> right) {
public <N extends Number & Comparable<?>> ENumber<D> multiply(Expr<N> right) {
return ONumber.create(getType(), Ops.MULT, this, right);
}
/**
* Get the result of the operation this * right
*
* @param right
* @return this * right
*/
public ENumber<D> mult(Number right) {
public ENumber<D> multiply(Number right) {
return ONumber.create(getType(), Ops.MULT, this, ENumber.create(right));
}
@ -428,19 +456,21 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
*/
public ENumber<D> negate(){
if (negation == null){
negation = mult(-1);
negation = multiply(-1);
}
return negation;
}
/**
* Returns the closest <code>int</code> to the argument.
*
* @return round(this)
* @see java.lang.Math#round(double)
* @see java.lang.Math#round(float)
*/
public ENumber<D> round() {
public ENumber<Integer> round() {
if (round == null){
round = ONumber.create(getType(), MathOps.ROUND, this);
round = ONumber.create(Integer.class, MathOps.ROUND, this);
}
return round;
}
@ -456,7 +486,8 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Returns the square root of this numeric expressions
* Get the square root of this numeric expressions
*
* @return sqrt(this)
*/
public ENumber<Double> sqrt(){
@ -467,22 +498,28 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
}
/**
* Get the difference of this and right
*
* @param right
* @return this - right
*/
public <N extends Number & Comparable<?>> ENumber<D> sub(Expr<N> right) {
public <N extends Number & Comparable<?>> ENumber<D> subtract(Expr<N> right) {
return ONumber.create(getType(), Ops.SUB, this, right);
}
/**
* Get the difference of this and right
*
* @param right
* @return this - right
*/
public ENumber<D> sub(Number right) {
public ENumber<D> subtract(Number right) {
return ONumber.create(getType(), Ops.SUB, this, ENumber.create(right));
}
/**
* Get the sum of this expression (aggregation)
*
* @return sum(this)
*/
public ENumber<D> sum(){

View File

@ -72,17 +72,17 @@ public class ENumberConst<D extends Number & Comparable<?>> extends ENumber<D> i
}
@Override
public ENumber<D> sub(Number right) {
public ENumber<D> subtract(Number right) {
return ENumber.create(MathUtils.difference(constant, right));
}
@SuppressWarnings("unchecked")
@Override
public <N extends Number & Comparable<?>> ENumber<D> sub(Expr<N> right) {
public <N extends Number & Comparable<?>> ENumber<D> subtract(Expr<N> right) {
if (right instanceof Constant){
return sub(((Constant<Number>)right).getConstant());
return subtract(((Constant<Number>)right).getConstant());
}else{
return super.sub(right);
return super.subtract(right);
}
}

View File

@ -75,6 +75,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the concatenation of this and str
*
* @param str
* @return this + str
*/
@ -83,6 +85,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the concatenation of this and str
*
* @param str
* @return this + str
*/
@ -91,6 +95,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the character at the given index
*
* @param i
* @return this.charAt(i)
* @see java.lang.String#charAt(int)
@ -100,6 +106,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the character at the given index
*
* @param i
* @return this.charAt(i)
* @see java.lang.String#charAt(int)
@ -109,6 +117,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the concatenation of this and str
*
* @param str
* @return this + str
*/
@ -117,6 +127,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the concatenation of this and str
*
* @param str
* @return this + str
*/
@ -125,6 +137,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if the given String is contained
*
* @param str
* @return this.contains(str)
* @see java.lang.String#contains(CharSequence)
@ -134,6 +148,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if the given String is contained
*
* @param str
* @return this.contains(str)
* @see java.lang.String#contains(CharSequence)
@ -143,6 +159,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if this ends with str
*
* @param str
* @return this.endsWith(str)
* @see java.lang.String#endsWith(String)
@ -152,8 +170,10 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if this ends with str
*
* @param str
* @param caseSensitive
* @param caseSensitive case sensitivity of operation
* @return
* @see java.lang.String#endsWith(String)
*/
@ -166,6 +186,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if this ends with str
*
* @param str
* @return this.endsWith(str)
* @see java.lang.String#endsWith(String)
@ -175,6 +197,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Returns true if this ends with str
*
* @param str
* @param caseSensitive
* @return
@ -185,6 +209,9 @@ public abstract class EString extends EComparable<String> {
}
/**
* Compares this {@code EString} to another {@code EString}, ignoring case
* considerations.
*
* @param str
* @return this.equalsIgnoreCase(str)
* @see java.lang.String#equalsIgnoreCase(String)
@ -194,6 +221,9 @@ public abstract class EString extends EComparable<String> {
}
/**
* Compares this {@code EString} to another {@code EString}, ignoring case
* considerations.
*
* @param str
* @return this.equalsIgnoreCase(str)
* @see java.lang.String#equalsIgnoreCase(String)
@ -203,6 +233,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the index of the given substring in this String
*
* @param str
* @return this.indexOf(str)
* @see java.lang.String#indexOf(String)
@ -212,6 +244,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the index of the given substring in this String
*
* @param str
* @return this.indexOf(str)
* @see java.lang.String#indexOf(String)
@ -221,6 +255,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the index of the given substring in this String, starting from the given index
*
* @param str
* @param i
* @return this.indexOf(str, i)
@ -232,6 +268,8 @@ public abstract class EString extends EComparable<String> {
/**
* Get the index of the given substring in this String, starting from the given index
*
* @param str
* @param i
* @return
@ -239,7 +277,10 @@ public abstract class EString extends EComparable<String> {
public ENumber<Integer> indexOf(Expr<String> str, int i) {
return ONumber.create(Integer.class, Ops.INDEX_OF_2ARGS, this, str, ENumber.create(i));
}
/**
* Return true if this String is empty
*
* @return this.isEmpty()
* @see java.lang.String#isEmpty()
*/
@ -251,6 +292,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this String is not empty
*
* @return !this.isEmpty()
* @see java.lang.String#isEmpty()
*/
@ -258,8 +301,9 @@ public abstract class EString extends EComparable<String> {
return isEmpty().not();
}
/**
* Return the length of this String
*
* @return this.length()
* @see java.lang.String#length()
*/
@ -291,6 +335,7 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the lower case form
*
* @return this.toLowerCase()
* @see java.lang.String#toLowerCase()
@ -303,6 +348,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this String matches the given regular expression
*
* @param regex
* @return this.matches(right)
* @see java.lang.String#matches(String)
@ -312,6 +359,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this String matches the given regular expression
*
* @param regex
* @return this.matches(regex)
* @see java.lang.String#matches(String)
@ -321,6 +370,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Prepend the given String and return the result
*
* @param str
* @return str + this
*/
@ -329,6 +380,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Prepend the given String and return the result
*
* @param str
* @return str + this
*/
@ -348,6 +401,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this starts with str
*
* @param str
* @return this.startsWith(str)
* @see java.lang.String#startsWith(String)
@ -357,6 +412,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this starts with str
*
* @param str
* @param caseSensitive
* @return
@ -371,6 +428,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this starts with str
*
* @param str
* @return this.startsWith(str)
* @see java.lang.String#startsWith(String)
@ -380,6 +439,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Return true if this starts with str
*
* @param str
* @param caseSensitive
* @return
@ -397,6 +458,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the given substring
*
* @param beginIndex
* @return this.substring(beginIndex)
* @see java.lang.String#substring(int)
@ -406,6 +469,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the given substring
*
* @param beginIndex
* @param endIndex
* @return this.substring(beginIndex, endIndex)
@ -416,6 +481,7 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the lower case form
*
* @return this.toLowerCase()
* @see java.lang.String#toLowerCase()
@ -425,6 +491,7 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the upper case form
*
* @return
* @see java.lang.String#toUpperCase()
@ -434,6 +501,9 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get a copy of the string, with leading and trailing whitespace
* omitted.
*
* @return
* @see java.lang.String#trim()
*/
@ -445,6 +515,8 @@ public abstract class EString extends EComparable<String> {
}
/**
* Get the upper case form
*
* @return
* @see java.lang.String#toUpperCase()
*/

View File

@ -131,8 +131,8 @@ public class MatchingFilters {
HashSet<EBoolean> rv = new HashSet<EBoolean>();
rv.add(expr.eq(other));
rv.add(expr.goe(other));
rv.add(expr.gt(other.sub(1)));
rv.add(expr.gt(other.sub(2)));
rv.add(expr.gt(other.subtract(1)));
rv.add(expr.gt(other.subtract(2)));
rv.add(expr.loe(other));
rv.add(expr.lt(other.add(1)));
rv.add(expr.lt(other.add(2)));

View File

@ -82,10 +82,10 @@ public class Projections {
HashSet<ENumber<?>> rv = new HashSet<ENumber<?>>();
rv.add(expr.abs());
rv.add(expr.add(other));
rv.add(expr.div(other));
rv.add(expr.mult(other));
rv.add(expr.divide(other));
rv.add(expr.multiply(other));
rv.add(expr.sqrt());
rv.add(expr.sub(other));
rv.add(expr.subtract(other));
return rv;
}

View File

@ -247,9 +247,9 @@ public class FeaturesTest extends AbstractQueryTest{
// toString("cat.kittens as kitten", cat.kittens.as(kitten));
toString("cat.bodyWeight + :a1", cat.bodyWeight.add(10));
toString("cat.bodyWeight - :a1", cat.bodyWeight.sub(10));
toString("cat.bodyWeight * :a1", cat.bodyWeight.mult(10));
toString("cat.bodyWeight / :a1", cat.bodyWeight.div(10));
toString("cat.bodyWeight - :a1", cat.bodyWeight.subtract(10));
toString("cat.bodyWeight * :a1", cat.bodyWeight.multiply(10));
toString("cat.bodyWeight / :a1", cat.bodyWeight.divide(10));
// toString("cat.bodyWeight as bw", cat.bodyWeight.as("bw"));

View File

@ -15,32 +15,32 @@ public class MathTest extends AbstractQueryTest{
@Test
public void test(){
PNumber<Integer> path = QCat.cat.bodyWeight;
toString("(cat.bodyWeight - sum(cat.bodyWeight)) * cat.bodyWeight", path.sub(path.sum()).mult(path));
toString("(cat.bodyWeight - sum(cat.bodyWeight)) * cat.bodyWeight", path.subtract(path.sum()).multiply(path));
}
@Test
public void testArithmeticOperationsInFunctionalWay() {
toString("cat.bodyWeight + :a1", cat.bodyWeight.add(10));
toString("cat.bodyWeight - :a1", cat.bodyWeight.sub(10));
toString("cat.bodyWeight * :a1", cat.bodyWeight.mult(10));
toString("cat.bodyWeight / :a1", cat.bodyWeight.div(10));
toString("cat.bodyWeight - :a1", cat.bodyWeight.subtract(10));
toString("cat.bodyWeight * :a1", cat.bodyWeight.multiply(10));
toString("cat.bodyWeight / :a1", cat.bodyWeight.divide(10));
toString("cat.bodyWeight + :a1 < :a1", cat.bodyWeight.add(10).lt(10));
toString("cat.bodyWeight - :a1 < :a1", cat.bodyWeight.sub(10).lt(10));
toString("cat.bodyWeight * :a1 < :a1", cat.bodyWeight.mult(10).lt(10));
toString("cat.bodyWeight / :a1 < :a2", cat.bodyWeight.div(10).lt(10d));
toString("cat.bodyWeight - :a1 < :a1", cat.bodyWeight.subtract(10).lt(10));
toString("cat.bodyWeight * :a1 < :a1", cat.bodyWeight.multiply(10).lt(10));
toString("cat.bodyWeight / :a1 < :a2", cat.bodyWeight.divide(10).lt(10d));
toString("(cat.bodyWeight + :a1) * :a2", cat.bodyWeight.add(10).mult(20));
toString("(cat.bodyWeight - :a1) * :a2", cat.bodyWeight.sub(10).mult(20));
toString("cat.bodyWeight * :a1 + :a2", cat.bodyWeight.mult(10).add(20));
toString("cat.bodyWeight * :a1 - :a2", cat.bodyWeight.mult(10).sub(20));
toString("(cat.bodyWeight + :a1) * :a2", cat.bodyWeight.add(10).multiply(20));
toString("(cat.bodyWeight - :a1) * :a2", cat.bodyWeight.subtract(10).multiply(20));
toString("cat.bodyWeight * :a1 + :a2", cat.bodyWeight.multiply(10).add(20));
toString("cat.bodyWeight * :a1 - :a2", cat.bodyWeight.multiply(10).subtract(20));
QCat c1 = new QCat("c1");
QCat c2 = new QCat("c2");
QCat c3 = new QCat("c3");
toString("c1.id + c2.id * c3.id", c1.id.add(c2.id.mult(c3.id)));
toString("c1.id * (c2.id + c3.id)", c1.id.mult(c2.id.add(c3.id)));
toString("(c1.id + c2.id) * c3.id", c1.id.add(c2.id).mult(c3.id));
toString("c1.id + c2.id * c3.id", c1.id.add(c2.id.multiply(c3.id)));
toString("c1.id * (c2.id + c3.id)", c1.id.multiply(c2.id.add(c3.id)));
toString("(c1.id + c2.id) * c3.id", c1.id.add(c2.id).multiply(c3.id));
}
@ -48,9 +48,9 @@ public class MathTest extends AbstractQueryTest{
public void testMathematicalOperations() {
// mathematical operators +, -, *, /
cat.bodyWeight.add(kitten.bodyWeight);
cat.bodyWeight.sub(kitten.bodyWeight);
cat.bodyWeight.mult(kitten.bodyWeight);
cat.bodyWeight.div(kitten.bodyWeight);
cat.bodyWeight.subtract(kitten.bodyWeight);
cat.bodyWeight.multiply(kitten.bodyWeight);
cat.bodyWeight.divide(kitten.bodyWeight);
}
}

View File

@ -397,7 +397,7 @@ public class ParserTest implements Constants {
// parse( "select item from Item item, Order ord\n"
// + "where ord.items[ size(ord.items) - 1 ] = item" );
query().select(item).from(item, ord).where(
ord.items(ord.items.size().sub(1)).eq(item))
ord.items(ord.items.size().subtract(1)).eq(item))
.parse();
//
// parse( "from eg.DomesticCat cat where upper(cat.name) like 'FRI%'" );
@ -681,7 +681,7 @@ public class ParserTest implements Constants {
// parse( "from Animal an where sqrt(an.bodyWeight)/2 > 10" );
query().from(an).where(an.bodyWeight.sqrt().gt(10.0)).parse();
query().from(an).where(an.bodyWeight.sqrt().div(2d).gt(10.0))
query().from(an).where(an.bodyWeight.sqrt().divide(2d).gt(10.0))
.parse();
// parse(
// "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null"
@ -708,7 +708,7 @@ public class ParserTest implements Constants {
query().from(qat).orderBy(qat.toes.avg().asc()).parse();
// parse( "from Animal an order by sqrt(an.bodyWeight)/2" );
query().from(qat).orderBy(an.bodyWeight.sqrt().div(2.0).asc()).parse();
query().from(qat).orderBy(an.bodyWeight.sqrt().divide(2.0).asc()).parse();
}
@Test