timoninmaxim commented on a change in pull request #8490: URL: https://github.com/apache/ignite/pull/8490#discussion_r568740505
########## File path: modules/core/src/main/java/org/apache/ignite/cache/query/index/SingleCursor.java ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.ignite.cache.query.index; + +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.lang.GridCursor; + +/** + * Cursor that holds single value only. + * @param <T> class of value to return. + */ +public class SingleCursor<T> implements GridCursor<T> { + /** Value to return */ + private final T val; + + /** Counter ot check wherther value is already got. */ + private final AtomicInteger currIdx = new AtomicInteger(-1); + + /** */ + public SingleCursor(T val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean next() { + return currIdx.incrementAndGet() == 0; + } + + /** {@inheritDoc} */ + @Override public T get() throws IgniteCheckedException { + if (currIdx.get() <= 0) Review comment: Yes, it looks pretty strange. But it's the same logic as org.h2.index.SingleRowCursor does ([Link](https://github.com/h2database/h2database/blob/version-1.4.197/h2/src/main/org/h2/index/SingleRowCursor.java)) Also we have some tests (or logic) that differently works with SingleCursor. Some of them just use get, some of them make `next -> get` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
