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

models.internal.impl.DefaultExpressionQuery 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.Loggable;
import com.arpnetworking.metrics.portal.expressions.ExpressionRepository;
import com.google.common.base.MoreObjects;
import models.internal.Expression;
import models.internal.ExpressionQuery;
import models.internal.QueryResult;

import java.util.Optional;

/**
 * Default internal model implementation for an expression query.
 *
 * @author Ville Koskela (vkoskela at groupon dot com)
 */
@Loggable
public final class DefaultExpressionQuery implements ExpressionQuery {

    /**
     * Public constructor.
     *
     * @param repository The ExpressionRepository
     */
    public DefaultExpressionQuery(final ExpressionRepository repository) {
        _repository = repository;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExpressionQuery contains(final Optional contains) {
        _contains = contains;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExpressionQuery cluster(final Optional cluster) {
        _cluster = cluster;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExpressionQuery service(final Optional service) {
        _service = service;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExpressionQuery limit(final int limit) {
        _limit = limit;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ExpressionQuery offset(final Optional offset) {
        _offset = offset;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public QueryResult execute() {
        return _repository.query(this);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional getContains() {
        return _contains;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional getCluster() {
        return _cluster;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional getService() {
        return _service;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getLimit() {
        return _limit;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional getOffset() {
        return _offset;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("id", Integer.toHexString(System.identityHashCode(this)))
                .add("class", this.getClass())
                .add("Repository", _repository)
                .add("Contains", _contains)
                .add("Cluster", _cluster)
                .add("Service", _service)
                .add("Limit", _limit)
                .add("Offset", _offset)
                .toString();
    }

    private final ExpressionRepository _repository;
    private Optional _contains = Optional.empty();
    private Optional _cluster = Optional.empty();
    private Optional _service = Optional.empty();
    private int _limit = DEFAULT_LIMIT;
    private Optional _offset = Optional.empty();

    private static final int DEFAULT_LIMIT = 1000;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy