<commit_before>/*
 * Copyright (c) 2008-2014 MongoDB, Inc.
 *
 * 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 org.mongodb.operation;

import org.bson.codecs.Decoder;
import org.bson.types.BsonDocument;
import org.bson.types.BsonString;
import org.mongodb.MongoFuture;
import org.mongodb.MongoNamespace;
import org.mongodb.binding.AsyncReadBinding;
import org.mongodb.binding.ReadBinding;
import org.mongodb.protocol.QueryProtocol;

import java.util.EnumSet;
import java.util.List;

import static org.mongodb.assertions.Assertions.notNull;
import static org.mongodb.operation.QueryOperationHelper.queryResultToList;
import static org.mongodb.operation.QueryOperationHelper.queryResultToListAsync;

/**
 * An operation that gets the indexes that have been created on a collection.
 *
 * @since 3.0
 */
public class GetIndexesOperation<T> implements AsyncReadOperation<List<T>>, ReadOperation<List<T>> {
    private final MongoNamespace collectionNamespace;
    private final Decoder<T> decoder;

    public GetIndexesOperation(final MongoNamespace collectionNamespace, final Decoder<T> decoder) {
        this.collectionNamespace = notNull("collectionNamespace", collectionNamespace);
        this.decoder = decoder;
    }

    @Override
    public List<T> execute(final ReadBinding binding) {
        return queryResultToList(getIndexNamespace(), getProtocol(), decoder, binding);
    }

    @Override
    public MongoFuture<List<T>> executeAsync(final AsyncReadBinding binding) {
        return queryResultToListAsync(getIndexNamespace(), getProtocol(), decoder, binding);
    }

    private BsonDocument asQueryDocument() {
        return new BsonDocument("ns", new BsonString(collectionNamespace.getFullName()));
    }

    private MongoNamespace getIndexNamespace() {
        return new MongoNamespace(collectionNamespace.getDatabaseName(), "system.indexes");
    }

    private QueryProtocol<T> getProtocol() {
        return new QueryProtocol<T>(getIndexNamespace(), EnumSet.noneOf(QueryFlag.class), 0, 0, asQueryDocument(), null, decoder);
    }

}
<commit_msg>GetIndexesOperation Javadoc improvements<commit_after>/*
 * Copyright (c) 2008-2014 MongoDB, Inc.
 *
 * 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 org.mongodb.operation;

import org.bson.codecs.Decoder;
import org.bson.types.BsonDocument;
import org.bson.types.BsonString;
import org.mongodb.MongoFuture;
import org.mongodb.MongoNamespace;
import org.mongodb.binding.AsyncReadBinding;
import org.mongodb.binding.ReadBinding;
import org.mongodb.protocol.QueryProtocol;

import java.util.EnumSet;
import java.util.List;

import static org.mongodb.assertions.Assertions.notNull;
import static org.mongodb.operation.QueryOperationHelper.queryResultToList;
import static org.mongodb.operation.QueryOperationHelper.queryResultToListAsync;

/**
 * An operation that gets the indexes that have been created on a collection.  For flexibility,
 * the type of each document returned is generic.
 *
 * @param <T> the document type for each index
 *
 * @since 3.0
 */
public class GetIndexesOperation<T> implements AsyncReadOperation<List<T>>, ReadOperation<List<T>> {
    private final MongoNamespace collectionNamespace;
    private final Decoder<T> decoder;

    /**
     * Construct a new instance
     *
     * @param collectionNamespace the namespace of the collection to get the indexes for
     * @param decoder the decoder for the indexes
     */
    public GetIndexesOperation(final MongoNamespace collectionNamespace, final Decoder<T> decoder) {
        this.collectionNamespace = notNull("collectionNamespace", collectionNamespace);
        this.decoder = decoder;
    }

    @Override
    public List<T> execute(final ReadBinding binding) {
        return queryResultToList(getIndexNamespace(), getProtocol(), decoder, binding);
    }

    @Override
    public MongoFuture<List<T>> executeAsync(final AsyncReadBinding binding) {
        return queryResultToListAsync(getIndexNamespace(), getProtocol(), decoder, binding);
    }

    private BsonDocument asQueryDocument() {
        return new BsonDocument("ns", new BsonString(collectionNamespace.getFullName()));
    }

    private MongoNamespace getIndexNamespace() {
        return new MongoNamespace(collectionNamespace.getDatabaseName(), "system.indexes");
    }

    private QueryProtocol<T> getProtocol() {
        return new QueryProtocol<T>(getIndexNamespace(), EnumSet.noneOf(QueryFlag.class), 0, 0, asQueryDocument(), null, decoder);
    }

}

{'fraction_non_alphanumeric': 0.09021601016518424, 'fraction_numerical': 0.005808676710836813, 'mean_word_length': 4.471698113207547, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692399', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1439, 'n_words': 453}