Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.util.Iterator;

import java.util.NoSuchElementException;

public class Main {
    public static <T> Iterable<T> replicate(final T value, final int count) {
        return new Iterable<T>() {
            @Override
            public Iterator<T> iterator() {
                return new Iterator<T>() {
                    int remaining = count;

                    @Override
                    public boolean hasNext() {
                        return remaining > 0;
                    }

                    @Override
                    public T next() {
                        if (remaining-- <= 0)
                            throw new NoSuchElementException();
                        return value;
                    }

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