All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mysema.query.group.GroupBy Maven / Gradle / Ivy

There is a newer version: 3.7.4
Show newest version
/*
 * 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
 * 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.List;
import java.util.Map;
import java.util.Set;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import com.mysema.commons.lang.Pair;
import com.mysema.query.types.Expression;
import com.mysema.query.types.QList;

/**
 * Groups results by the first expression.
 *
 * @author sasa
 * @author tiwe
 *
 */
public final class GroupBy {

    /**
     * Create a new GroupByBuilder for the given key expression
     *
     * @param key
     * @return
     */
    public static  GroupByBuilder groupBy(Expression key) {
        return new GroupByBuilder(key);
    }

    /**
     * Create a new GroupByBuilder for the given key expressions
     *
     * @param keys
     * @return
     */
    public static GroupByBuilder> groupBy(Expression... keys) {
        return new GroupByBuilder>(new QList(keys));
    }

    /**
     * Create a new aggregating min expression
     *
     * @param expression
     * @return
     */
    public static > AbstractGroupExpression min(Expression expression) {
        return new GMin(expression);
    }

    /**
     * Create a new aggregating sum expression
     *
     * @param expression
     * @return
     */
    public static > AbstractGroupExpression sum(Expression expression) {
        return new GSum(expression);
    }

    /**
     * Create a new aggregating avg expression
     *
     * @param expression
     * @return
     */
    public static > AbstractGroupExpression avg(Expression expression) {
        return new GAvg(expression);
    }

    /**
     * Create a new aggregating max expression
     *
     * @param expression
     * @return
     */
    public static > AbstractGroupExpression max(Expression expression) {
        return new GMax(expression);
    }

    /**
     * Create a new aggregating list expression
     *
     * @param expression
     * @return
     */
    public static  AbstractGroupExpression> list(Expression expression) {
        return new GList(expression);
    }

    public static  AbstractGroupExpression> list(GroupExpression groupExpression) {
        return new MixinGroupExpression>(groupExpression, new GList(groupExpression));
    }

    /**
     * Create a new aggregating set expression
     *
     * @param expression
     * @return
     */
    public static  AbstractGroupExpression> set(Expression expression) {
        return new GSet(expression);
    }

    public static  GroupExpression> set(GroupExpression groupExpression) {
        return new MixinGroupExpression>(groupExpression, new GSet(groupExpression));
    }

    /**
     * Create a new aggregating map expression
     *
     * @param key
     * @param value
     * @return
     */
    @WithBridgeMethods(value=Expression.class,castRequired=true)
    public static  AbstractGroupExpression,Map> map(Expression key, Expression value) {
        return new GMap(QPair.create(key, value));
    }

    public static  AbstractGroupExpression, Map> map(GroupExpression key, Expression value) {
        return map(key, new GOne(value));
    }

    public static  AbstractGroupExpression, Map> map(Expression key, GroupExpression value) {
        return map(new GOne(key), value);
    }

    public static  AbstractGroupExpression, Map> map(GroupExpression key, GroupExpression value) {
        return new GMap.Mixin>(key, value, new GMap(QPair.create(key, value)));
    }

    private GroupBy() {}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy