abhishekrb19 commented on code in PR #16719: URL: https://github.com/apache/druid/pull/16719#discussion_r1693343592
########## processing/src/main/java/org/apache/druid/collections/CircularList.java: ########## @@ -0,0 +1,97 @@ +/* + * 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.druid.collections; + +import javax.annotation.concurrent.NotThreadSafe; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Set; + +/** + * A circular list that is backed by an ordered list of elements containing no duplicates. The list is ordered by the + * supplied comparator. Callers are responsible for terminating the iterator explicitly. + * <p> + * This class is not thread-safe and must be used from a single thread. + */ +@NotThreadSafe +public class CircularList<T> implements Iterable<T> +{ + private final List<T> collection = new ArrayList<>(); + private final Comparator<? super T> comparator; + private int currentPosition; + + public CircularList(final Set<T> elements, Comparator<? super T> comparator) Review Comment: >We should be able to iterate over any list in a circular fashion using this class. Whether the list is sorted or not or has duplicates or not should be up to the caller. True that. We can perhaps revisit the class name and its usage once we have other use cases. I think it should be relatively straightforward to adjust. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
