Skip to content

Commit

Permalink
simplified GroupExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
timowest committed Oct 7, 2011
1 parent 103a6a0 commit c157221
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 63 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
target
test-output
.classpath
.project
.settings
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2011 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.group;

import java.util.ArrayList;
Expand All @@ -12,7 +17,6 @@
import com.mysema.query.Projectable;
import com.mysema.query.ResultTransformer;
import com.mysema.query.types.Expression;
import com.mysema.query.types.Operation;
import com.mysema.query.types.expr.SimpleExpression;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (c) 2011 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.group;

import java.util.ArrayList;
Expand All @@ -12,6 +17,9 @@
import com.mysema.query.types.FactoryExpressionUtils;

/**
* GroupByBuilder is a fluent builder for GroupBy instances. This class is not to be used directly,
* but via GroupBy.
*
* @author tiwe
*
* @param <K>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package com.mysema.query.group;

/**
* A statefull collector of column values for a group.
* A stateful collector of column values for a group.
*
* @author sasa
* @param <R> Target type (e.g. List, Set)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author sasa
*
* @param <T> Expression type
* @param <R> Target type (e.g. T, Set&lt;T> or List&lt;T>)
* @param <R> Target type (e.g. T, Set&lt;T&gt; or List&lt;T&gt;)
*/
public interface GroupDefinition<T, R> {

Expand All @@ -28,7 +28,7 @@ public interface GroupDefinition<T, R> {
Expression<T> getExpression();

/**
* @return a new stateful GroupCollector to collect values belonging to this group.
* @return a new GroupCollector to collect values belonging to this group.
*/
GroupCollector<R> createGroupCollector();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,42 @@
package com.mysema.query.group;

import java.util.List;

import com.mysema.query.types.Expression;
import com.mysema.query.types.Operation;
import com.mysema.query.types.OperationImpl;
import com.mysema.query.types.Operator;
import com.mysema.query.types.OperatorImpl;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.SimpleExpression;
import com.mysema.query.types.expr.SimpleOperation;

/**
* GroupExpression combines a GroupDefinition and related Expressions
*
* @author tiwe
*
* @param <T>
*/
public class GroupExpression<T> extends SimpleExpression<T> implements Operation<T> {
public class GroupExpression<T> extends SimpleOperation<T> {

private static final long serialVersionUID = -339842770639127388L;

private static final Operator<Object> GROUP_EXPRESSION = new OperatorImpl<Object>("GROUP_EXPRESSION", Object.class);

private final GroupDefinition<?,T> definition;

private final Operation< T> opMixin;

@SuppressWarnings("unchecked")
public GroupExpression(Class<? extends T> type, GroupDefinition<?,T> definition, Expression<?>... args) {
super(type);
super((Class)type, GROUP_EXPRESSION, args);
this.definition = definition;
this.opMixin = new OperationImpl(type, GROUP_EXPRESSION, args);
}

@Override
public boolean equals(Object o) {
return opMixin.equals(o);
}

@Override
public int hashCode() {
return opMixin.hashCode();
}

@Override
public <R, C> R accept(Visitor<R, C> v, C context) {
return v.visit(opMixin, context);
}

public GroupDefinition<?, T> getDefinition() {
return definition;
}

@Override
public Expression<?> getArg(int index) {
return opMixin.getArg(index);
}

@Override
public List<Expression<?>> getArgs() {
return opMixin.getArgs();
}


@Override
public Operator<? super T> getOperator() {
return opMixin.getOperator();
public boolean equals(Object o) {
if (o instanceof GroupExpression<?>) {
return super.equals(o) && ((GroupExpression<?>)o).getDefinition().equals(definition);
} else {
return false;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
*
/*
* Copyright (c) 2011 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.group;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static BooleanExpression create(Operator<? super Boolean> op, Expression<

private final Operation<Boolean> opMixin;

BooleanOperation(Operator<? super Boolean> op, Expression<?>... args) {
protected BooleanOperation(Operator<? super Boolean> op, Expression<?>... args) {
this(op, Arrays.asList(args));
}

BooleanOperation(Operator<? super Boolean> op, List<Expression<?>> args) {
protected BooleanOperation(Operator<? super Boolean> op, List<Expression<?>> args) {
opMixin = new OperationImpl<Boolean>(Boolean.class, op, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public static <D extends Comparable<?>> ComparableExpression<D> create(Class<D>

private final Operation<T> opMixin;

ComparableOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
protected ComparableOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

ComparableOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
protected ComparableOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public static <D extends Comparable<?>> DateExpression<D> create(Class<D> type,

private final Operation<T> opMixin;

DateOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
protected DateOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

DateOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
protected DateOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public static <D extends Comparable<?>> DateTimeExpression<D> create(Class<D> ty

private final Operation<T> opMixin;

DateTimeOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
protected DateTimeOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

DateTimeOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
protected DateTimeOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public static <D extends Enum<D>> EnumExpression<D> create(Class<? extends D> ty

private final Operation<T> opMixin;

EnumOperation(Class<? extends T> type, Operator<? super T> op, Expression<?>... args) {
protected EnumOperation(Class<? extends T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

EnumOperation(Class<? extends T> type, Operator<? super T> op, List<Expression<?>> args) {
protected EnumOperation(Class<? extends T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public static <D extends Number & Comparable<?>> NumberExpression<D> create(Clas

private final Operation<T> opMixin;

NumberOperation(Class<? extends T> type, Operator<? super T> op, Expression<?>... args) {
protected NumberOperation(Class<? extends T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

NumberOperation(Class<? extends T> type, Operator<? super T> op, List<Expression<?>> args) {
protected NumberOperation(Class<? extends T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public static <D> SimpleExpression<D> create(Class<D> type, Operator<? super D>

private final Operation< T> opMixin;

SimpleOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
protected SimpleOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

SimpleOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
protected SimpleOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public static StringExpression create(Operator<? super String> op, Expression<?>

private final Operation<String> opMixin;

StringOperation(Operator<? super String> op, Expression<?>... args) {
protected StringOperation(Operator<? super String> op, Expression<?>... args) {
this(op, Arrays.asList(args));
}

StringOperation(Operator<? super String> op, List<Expression<?>> args) {
protected StringOperation(Operator<? super String> op, List<Expression<?>> args) {
this.opMixin = new OperationImpl<String>(String.class, op, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public static <D extends Comparable<?>> TimeExpression<D> create(Class<D> type,

private final Operation<T> opMixin;

TimeOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
protected TimeOperation(Class<T> type, Operator<? super T> op, Expression<?>... args) {
this(type, op, Arrays.asList(args));
}

TimeOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
protected TimeOperation(Class<T> type, Operator<? super T> op, List<Expression<?>> args) {
super(type);
this.opMixin = new OperationImpl<T>(type, op, args);
}
Expand Down

0 comments on commit c157221

Please sign in to comment.