alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (VertexSequence.java)

This example Java source code file (VertexSequence.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

igraph, ivertexsequence, nosuchelementexception, override, unsupportedoperationexception, util, vertexsequence

The VertexSequence.java Java example source code

package org.deeplearning4j.graph.graph;

import org.deeplearning4j.graph.api.IGraph;
import org.deeplearning4j.graph.api.Vertex;
import org.deeplearning4j.graph.api.IVertexSequence;

import java.util.NoSuchElementException;

/**A vertex sequence represents a sequences of vertices in a graph
 * @author Alex Black
 */
public class VertexSequence<V> implements IVertexSequence {
    private final IGraph<V,?> graph;
    private int[] indices;
    private int currIdx = 0;

    public VertexSequence(IGraph<V, ?> graph, int[] indices){
        this.graph = graph;
        this.indices = indices;
    }

    @Override
    public int sequenceLength() {
        return indices.length;
    }

    @Override
    public boolean hasNext() {
        return currIdx < indices.length;
    }

    @Override
    public Vertex<V> next() {
        if(!hasNext()) throw new NoSuchElementException();
        return graph.getVertex(indices[currIdx++]);
    }

    @Override
    public void remove(){
        throw new UnsupportedOperationException();
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java VertexSequence.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.