Make Exported just be SquirrelJMEVendorApi.
[SquirrelJME.git] / modules / collections / src / main / java / net / multiphasicapps / collections / UnmodifiableIterable.java
blobab1ad50a2cb37afb90b35da19d1a36448b18ac21
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net.multiphasicapps.collections;
12 import cc.squirreljme.runtime.cldc.util.UnmodifiableIterator;
13 import java.util.Iterator;
15 /**
16 * Wraps an iterable which makes it not able to be modified.
18 * @param <T> The type to iterate through.
19 * @since 2021/04/25
21 public final class UnmodifiableIterable<T>
22 implements Iterable<T>
24 /** The iterable used. */
25 private final Iterable<T> iterable;
27 /**
28 * Initializes the unmodifiable iterable.
30 * @param __it The iterable used.
31 * @throws NullPointerException On null arguments.
32 * @since 2021/04/25
34 UnmodifiableIterable(Iterable<T> __it)
35 throws NullPointerException
37 if (__it == null)
38 throw new NullPointerException("NARG");
40 this.iterable = __it;
43 /**
44 * {@inheritDoc}
45 * @since 2021/04/25
47 @Override
48 public Iterator<T> iterator()
50 return UnmodifiableIterator.<T>of(this.iterable);
53 /**
54 * Returns an unmodifiable iterable from the given one.
56 * @param <T> The type used.
57 * @param __it The iterator to wrap.
58 * @return The iterable but it cannot be modified.
59 * @throws NullPointerException On null arguments.
60 * @since 2021/04/25
62 public static <T> Iterable<T> of(Iterable<T> __it)
63 throws NullPointerException
65 if (__it == null)
66 throw new NullPointerException("NARG");
68 return new UnmodifiableIterable<>(__it);