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

com.datadog.gradle.plugin.licenses.utils.NodeListSequence.kt Maven / Gradle / Ivy

The newest version!
/*
 * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
 * This product includes software developed at Datadog (https://www.datadoghq.com/).
 * Copyright 2016-Present Datadog, Inc.
 */

package com.datadog.gradle.plugin.licenses.utils

import org.w3c.dom.Node
import org.w3c.dom.NodeList
import kotlin.collections.Iterator as KIterator

internal class NodeListSequence(
    private val nodeList: NodeList,
) : Sequence {

    override fun iterator(): KIterator {
        return Iterator(nodeList)
    }

    class Iterator(
        private val nodeList: NodeList,
    ) : KIterator {
        private var i = 0
        override fun hasNext() = i < nodeList.length
        override fun next(): Node = if (i < nodeList.length) {
            nodeList.item(i++)
        } else {
            throw NoSuchElementException("There's no next element!")
        }
    }
}

internal fun NodeList.asSequence() = NodeListSequence(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy