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

io.squark.yggdrasil.core.context.YggdrasilNamingEnumeration.kt Maven / Gradle / Ivy

package io.squark.yggdrasil.core.context

import javax.naming.NamingEnumeration
import javax.naming.NamingException

/**
 * Naming enumerator for use with YggdrasilContext in the faux JNDI implementation
 *
 * Created by Erik Håkansson on 2017-04-01.
 * Copyright 2017
 */
internal class YggdrasilNamingEnumeration constructor(list: Collection) : NamingEnumeration {

  var enumerator: Iterator? = list.iterator()
  var closed = false

  override fun hasMore(): Boolean {
    checkNotClosed()
    return enumerator!!.hasNext()
  }

  override fun close() {
    if (!closed) {
      enumerator = null
      closed = true
    }
  }

  override fun next(): T {
    checkNotClosed()
    return enumerator!!.next()
  }

  override fun hasMoreElements(): Boolean {
    checkNotClosed()
    return enumerator!!.hasNext()
  }

  override fun nextElement(): T {
    checkNotClosed()
    return enumerator!!.next()
  }

  private fun checkNotClosed() {
    if (closed) throw NamingException("Enumeration is closed")
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy