/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.server.storage.datastore;

import com.google.cloud.datastore.Value;
import com.google.protobuf.Any;
import org.spine3.client.ColumnFilter;
import org.spine3.protobuf.TypeConverter;
import org.spine3.server.entity.storage.Column;
import org.spine3.server.entity.storage.ColumnTypeRegistry;
import org.spine3.server.storage.datastore.type.DatastoreColumnType;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @author Dmytro Dashenkov
 */
final class ColumnHandler {

    private final ColumnTypeRegistry<? extends DatastoreColumnType> registry;

    static ColumnHandler wrap(ColumnTypeRegistry<? extends DatastoreColumnType> registry) {
        return new ColumnHandler(registry);
    }

    private ColumnHandler(ColumnTypeRegistry<? extends DatastoreColumnType> registry) {
        this.registry = registry;
    }

    Value<?> toValue(Column column, ColumnFilter columnFilter) {
        checkNotNull(column);
        checkNotNull(columnFilter);

        final DatastoreColumnType type = registry.get(column);
        checkArgument(type != null, "Column of unknown type: %s.", column);

        final Any filterValue = columnFilter.getValue();
        final Object filterValueUnpacked = TypeConverter.toObject(filterValue, column.getType());

        @SuppressWarnings("unchecked") // Concrete type is unknown on compile time.
        final Value<?> result = type.toValue(type.convertColumnValue(filterValueUnpacked));
        return result;
    }
}

@@ -1524,16 +1524,192 @@
 l;%0A%0A/**%0A
+ * A wrapper above the %7B@link ColumnTypeRegistry%7D preforming the transformations defined by%0A * the %7B@link org.spine3.server.entity.storage.ColumnType ColumnType%7D interface.%0A *%0A
  * @auth
@@ -1840,16 +1840,142 @@
 istry;%0A%0A
+    /**%0A     * Creates a new instance of %7B@code ColumnHandler%7D on top of the given%0A     * %7B@link ColumnTypeRegistry%7D.%0A     */%0A
     stat
@@ -2234,24 +2234,378 @@
 try;%0A    %7D%0A%0A
+    /**%0A     * Extracts the filter parameter from the given %7B@link ColumnFilter%7D and converts it into%0A     * the Datastore %7B@link Value%7D.%0A     *%0A     * @param column       the %7B@link Column%7D targeted by the given filter%0A     * @param columnFilter the filter%0A     * @return new instance of %7B@link Value%7D representing the value of the given filter%0A     */%0A
     Value%3C?%3E

Add some Javadoc to the ColumnHandler.