/*
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * 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.
 * </p>
 */

package com.dangdang.ddframe.rdb.sharding.merger.groupby;

import com.dangdang.ddframe.rdb.sharding.parsing.parser.context.OrderItem;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 分组值对象.
 * 
 * @author zhangliang
 */
@RequiredArgsConstructor
public final class GroupByValue {
    
    private final ResultSet resultSet;
    
    private final List<OrderItem> groupByItems;
    
    /**
     * 获取分组值集合.
     * 
     * @return 分组值集合
     * @throws SQLException SQL异常
     */
    public List<Comparable<?>> getGroupValues() throws SQLException {
        List<Comparable<?>> result = new ArrayList<>(groupByItems.size());
        for (OrderItem each : groupByItems) {
            Object value = resultSet.getObject(each.getIndex());
            Preconditions.checkState(value instanceof Comparable, "Group by value must implements Comparable");
            result.add((Comparable<?>) value);
        }
        return result;
    }
}

@@ -802,38 +802,54 @@
  lombok.
-RequiredArgsConstructo
+EqualsAndHashCode;%0Aimport lombok.Gette
 r;%0A%0Aimpo
@@ -1002,31 +1002,33 @@
 */%0A@
-RequiredArgsConstructor
+Getter%0A@EqualsAndHashCode
 %0Apub
@@ -1085,192 +1085,242 @@
 nal 
-ResultSet resultSet;%0A    %0A    private final List%3COrderItem%3E groupByItems;%0A    %0A    /**%0A     * %E8%8E%B7%E5%8F%96%E5%88%86%E7%BB%84%E5%80%BC%E9%9B%86%E5%90%88.%0A     * %0A     * @return %E5%88%86%E7%BB%84%E5%80%BC%E9%9B%86%E5%90%88%0A     * @throws SQLException SQL%E5%BC%82%E5%B8%B8%0A     */
+List%3CComparable%3C?%3E%3E groupValues;%0A    %0A    public GroupByValue(final ResultSet resultSet, final List%3COrderItem%3E groupByItems) throws SQLException %7B%0A        groupValues = getGroupByValues(resultSet, groupByItems);%0A    %7D%0A    
 %0A    p
-ublic
+rivate
  Lis
@@ -1344,23 +1344,86 @@
 getGroup
+By
 Values(
+final ResultSet resultSet, final List%3COrderItem%3E groupByItems
 ) throws

refactor merger into ShardingResultSet 26th version, refactor GroupByValue