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

org.jnosql.artemis.document.query.ArtemisDocumentQuery Maven / Gradle / Ivy

/*
 *  Copyright (c) 2017 Otávio Santana and others
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   and Apache License v2.0 which accompanies this distribution.
 *   The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 *   and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
 *
 *   You may elect to redistribute this code under either of these licenses.
 *
 *   Contributors:
 *
 *   Otavio Santana
 */
package org.jnosql.artemis.document.query;

import org.jnosql.diana.api.Sort;
import org.jnosql.diana.api.document.DocumentCondition;
import org.jnosql.diana.api.document.DocumentQuery;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

class ArtemisDocumentQuery implements DocumentQuery {
    private final List sorts;
    private final long limit;
    private final long start;
    private final DocumentCondition condition;
    private final String documentCollection;

    ArtemisDocumentQuery(List sorts, long limit, long start, DocumentCondition condition, String documentCollection) {
        this.sorts = sorts;
        this.limit = limit;
        this.start = start;
        this.condition = condition;
        this.documentCollection = documentCollection;
    }

    @Override
    public long getMaxResults() {
        return limit;
    }

    @Override
    public long getFirstResult() {
        return start;
    }

    @Override
    public String getDocumentCollection() {
        return documentCollection;
    }

    @Override
    public Optional getCondition() {
        return Optional.ofNullable(condition);
    }

    @Override
    public List getSorts() {
        return sorts;
    }

    @Override
    public List getDocuments() {
        return Collections.emptyList();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof DocumentQuery)) {
            return false;
        }
        DocumentQuery that = (DocumentQuery) o;
        return limit == that.getMaxResults() &&
                start == that.getFirstResult() &&
                Objects.equals(sorts, that.getSorts()) &&
                Objects.equals(condition, that.getCondition().orElse(null)) &&
                Objects.equals(documentCollection, that.getDocumentCollection());
    }

    @Override
    public int hashCode() {
        return Objects.hash(limit, start, documentCollection, condition, sorts, Collections.emptyList());
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ArtemisDocumentQuery{");
        sb.append("maxResult=").append(limit);
        sb.append(", firstResult=").append(start);
        sb.append(", documentCollection='").append(documentCollection).append('\'');
        sb.append(", condition=").append(condition);
        sb.append(", sorts=").append(sorts);
        sb.append(", documents=").append(Collections.emptyList());
        sb.append('}');
        return sb.toString();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy