mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
#614 Add license headers and javadocs
This commit is contained in:
parent
afa20018e8
commit
16cd6d9697
@ -1,3 +1,16 @@
|
||||
/*
|
||||
* Copyright 2014, Mysema Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.group;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2012, Mysema Ltd
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -39,18 +39,17 @@ public class GAvg<T extends Number & Comparable<T>> extends AbstractGroupExpress
|
||||
private BigDecimal sum = BigDecimal.ZERO;
|
||||
|
||||
@Override
|
||||
public void add(T t) {
|
||||
public void add(T t) {
|
||||
count++;
|
||||
if (t != null) {
|
||||
sum = sum.add(new BigDecimal(t.toString()));
|
||||
sum = sum.add(new BigDecimal(t.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
BigDecimal avg = sum.divide(BigDecimal.valueOf(count));
|
||||
return (T) MathUtils.cast(avg, (Class<T>) getType());
|
||||
return MathUtils.cast(avg, (Class<T>) getType());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2011, Mysema Ltd
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -19,6 +19,10 @@ import java.util.Map;
|
||||
|
||||
import com.mysema.commons.lang.Pair;
|
||||
|
||||
/**
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
*/
|
||||
class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
|
||||
private static final long serialVersionUID = 7106389414200843920L;
|
||||
@ -32,7 +36,7 @@ class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
return new GroupCollector<Pair<K,V>, Map<K, V>>() {
|
||||
|
||||
private final Map<K, V> map = new LinkedHashMap<K, V>();
|
||||
|
||||
|
||||
@Override
|
||||
public void add(Pair<K,V> pair) {
|
||||
map.put(pair.getFirst(), pair.getSecond());
|
||||
@ -42,26 +46,26 @@ class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
public Map<K, V> get() {
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
static class Mixin<K, V, T, U, R extends Map<? super T, ? super U>> extends AbstractGroupExpression<Pair<K, V>, R> {
|
||||
|
||||
private static final long serialVersionUID = 1939989270493531116L;
|
||||
|
||||
private class GroupCollectorImpl implements GroupCollector<Pair<K, V>, R> {
|
||||
|
||||
|
||||
private final GroupCollector<Pair<T, U>, R> groupCollector;
|
||||
|
||||
|
||||
private final Map<K, GroupCollector<K, T>> keyCollectors = new LinkedHashMap<K, GroupCollector<K, T>>();
|
||||
|
||||
|
||||
private final Map<GroupCollector<K, T>, GroupCollector<V, U>> valueCollectors = new HashMap<GroupCollector<K, T>, GroupCollector<V, U>>();
|
||||
|
||||
|
||||
public GroupCollectorImpl() {
|
||||
this.groupCollector = mixin.createGroupCollector();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void add(Pair<K, V> pair) {
|
||||
K first = pair.getFirst();
|
||||
@ -75,7 +79,7 @@ class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
if (valueCollector == null) {
|
||||
valueCollector = valueExpression.createGroupCollector();
|
||||
valueCollectors.put(keyCollector, valueCollector);
|
||||
}
|
||||
}
|
||||
V second = pair.getSecond();
|
||||
valueCollector.add(second);
|
||||
}
|
||||
@ -93,12 +97,12 @@ class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final GroupExpression<Pair<T, U>, R> mixin;
|
||||
|
||||
|
||||
private final GroupExpression<K, T> keyExpression;
|
||||
private final GroupExpression<V, U> valueExpression;
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Mixin(GroupExpression<K, T> keyExpression, GroupExpression<V, U> valueExpression, AbstractGroupExpression<Pair<T, U>, R> mixin) {
|
||||
super((Class) mixin.getType(), QPair.create(keyExpression.getExpression(), valueExpression.getExpression()));
|
||||
@ -111,7 +115,7 @@ class GMap<K, V> extends AbstractGroupExpression<Pair<K, V>, Map<K, V>> {
|
||||
public GroupCollector<Pair<K, V>, R> createGroupCollector() {
|
||||
return new GroupCollectorImpl();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,27 +1,46 @@
|
||||
/*
|
||||
* Copyright 2014, Mysema Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.mysema.query.group;
|
||||
|
||||
/**
|
||||
* @param <E>
|
||||
* @param <F>
|
||||
* @param <R>
|
||||
*/
|
||||
public class MixinGroupExpression<E, F, R> extends AbstractGroupExpression<E, R> {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -5419707469727395643L;
|
||||
|
||||
private class GroupCollectorImpl implements GroupCollector<E, R> {
|
||||
|
||||
|
||||
private final GroupCollector<F, R> mixinGroupCollector;
|
||||
|
||||
|
||||
private GroupCollector<E, F> groupCollector;
|
||||
|
||||
|
||||
public GroupCollectorImpl() {
|
||||
mixinGroupCollector = mixin.createGroupCollector();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void add(E input) {
|
||||
if (groupCollector == null) {
|
||||
groupCollector = groupExpression.createGroupCollector();
|
||||
}
|
||||
groupCollector.add(input);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public R get() {
|
||||
if (groupCollector != null) {
|
||||
@ -35,9 +54,9 @@ public class MixinGroupExpression<E, F, R> extends AbstractGroupExpression<E, R>
|
||||
}
|
||||
|
||||
private final GroupExpression<F, R> mixin;
|
||||
|
||||
|
||||
private final GroupExpression<E, F> groupExpression;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public MixinGroupExpression(GroupExpression<E, F> groupExpression, GroupExpression<F, R> mixin) {
|
||||
super((Class) mixin.getType(), groupExpression.getExpression());
|
||||
@ -48,6 +67,6 @@ public class MixinGroupExpression<E, F, R> extends AbstractGroupExpression<E, R>
|
||||
@Override
|
||||
public GroupCollector<E, R> createGroupCollector() {
|
||||
return new GroupCollectorImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user