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

models.internal.impl.DefaultQueryResult Maven / Gradle / Ivy

There is a newer version: 0.9.2
Show newest version
/**
 * Copyright 2015 Groupon.com
 *
 * 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 models.internal.impl;

import com.arpnetworking.logback.annotations.LogValue;
import com.arpnetworking.steno.LogValueMapFactory;
import models.internal.QueryResult;

import java.util.List;
import java.util.Optional;

/**
 * Default internal model implementation for a query result.
 *
 * @param  The result value type.
 *
 * @author Ville Koskela (vkoskela at groupon dot com)
 */
public final class DefaultQueryResult implements QueryResult {

    /**
     * Public constructor.
     *
     * @param values The List of Host instances.
     * @param total The total number of matching Host instances.
     */
    public DefaultQueryResult(final List values, final long total) {
        _values = values;
        _total = total;
        _etag = Optional.empty();
    }

    /**
     * Public constructor.
     *
     * @param values The List of Host instances.
     * @param total The total number of matching Host instances.
     * @param etag The etag.
     */
    public DefaultQueryResult(final List values, final long total, final String etag) {
        _values = values;
        _total = total;
        _etag = Optional.of(etag);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List values() {
        return _values;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public long total() {
        return _total;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional etag() {
        return _etag;
    }

    /**
     * Generate a Steno log compatible representation.
     *
     * @return Steno log compatible representation.
     */
    @LogValue
    public Object toLogValue() {
        return LogValueMapFactory.builder(this)
                .put("values", _values)
                .put("total", _total)
                .put("etag", _etag)
                .build();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return toLogValue().toString();
    }

    private final List _values;
    private final long _total;
    private final Optional _etag;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy