home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (SynchronizedSequenceIterator.java)

This example Java source code file (SynchronizedSequenceIterator.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

override, sequence, sequenceelement, sequenceiterator, synchronizedsequenceiterator

The SynchronizedSequenceIterator.java Java example source code

package org.deeplearning4j.models.sequencevectors.iterators;

import lombok.NonNull;
import org.deeplearning4j.models.sequencevectors.interfaces.SequenceIterator;
import org.deeplearning4j.models.sequencevectors.sequence.Sequence;
import org.deeplearning4j.models.sequencevectors.sequence.SequenceElement;

/**
 * Synchronized version of AbstractSeuqenceIterator, implemented on top of it.
 * Suitable for cases with non-strict multithreading environment, since it's just synchronized wrapper
 *
 * @author raver119@gmail.com
 */
public class SynchronizedSequenceIterator<T extends SequenceElement> implements SequenceIterator {
    protected SequenceIterator<T> underlyingIterator;

    /**
     * Creates SynchronizedSequenceIterator on top of any SequenceIterator
     * @param iterator
     */
    public SynchronizedSequenceIterator(@NonNull SequenceIterator<T> iterator) {
        this.underlyingIterator = iterator;
    }

    /**
     * Checks, if there's any more sequences left in data source
     * @return
     */
    @Override
    public synchronized boolean hasMoreSequences() {
        return underlyingIterator.hasMoreSequences();
    }

    /**
     * Returns next sequence from data source
     *
     * @return
     */
    @Override
    public synchronized Sequence<T> nextSequence() {
        return underlyingIterator.nextSequence();
    }

    /**
     * This method resets underlying iterator
     */
    @Override
    public synchronized void reset() {
        underlyingIterator.reset();
    }
}

Other Java examples (source code examples)

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



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 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.