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

org.projectnessie.versioned.paging.PaginationIterator Maven / Gradle / Ivy

/*
 * Copyright (C) 2023 Dremio
 *
 * 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.projectnessie.versioned.paging;

import java.util.Iterator;
import java.util.NoSuchElementException;

public interface PaginationIterator extends Iterator, AutoCloseable {

  String tokenForCurrent();

  String tokenForEntry(T entry);

  @Override
  void close();

  @SuppressWarnings("unchecked")
  static  PaginationIterator of(T... values) {
    return new PaginationIterator() {
      int idx = 0;

      @Override
      public String tokenForCurrent() {
        return null;
      }

      @Override
      public String tokenForEntry(T entry) {
        return null;
      }

      @Override
      public void close() {}

      @Override
      public boolean hasNext() {
        return idx < values.length;
      }

      @Override
      public T next() {
        return values[idx++];
      }
    };
  }

  static  PaginationIterator empty() {
    return new PaginationIterator() {
      @Override
      public String tokenForCurrent() {
        return null;
      }

      @Override
      public String tokenForEntry(T entry) {
        return null;
      }

      @Override
      public void close() {}

      @Override
      public boolean hasNext() {
        return false;
      }

      @Override
      public T next() {
        throw new NoSuchElementException();
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy