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

com.querydsl.core.group.GroupByProjection Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
 *
 * 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.querydsl.core.group;

import com.querydsl.core.types.Expression;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * GroupByProjection provides projection of the Group results via the transform template method
 *
 * @author tiwe
 * @param 
 * @param 
 */
public abstract class GroupByProjection extends GroupByMap {

  public GroupByProjection(Expression key, Expression... expressions) {
    super(key, expressions);
  }

  @Override
  protected Map transform(Map groups) {
    Map results = new LinkedHashMap<>((int) Math.ceil(groups.size() / 0.75), 0.75f);
    for (Map.Entry entry : groups.entrySet()) {
      results.put(entry.getKey(), transform(entry.getValue()));
    }
    return results;
  }

  /**
   * Creates a result object from the given group
   *
   * @param group group instance to transform
   * @return transformed group
   */
  protected abstract V transform(Group group);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy