1 /**
2 * Copyright 2008 Atlassian Pty Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.atlassian.util.concurrent;
18
19 import java.util.NoSuchElementException;
20
21 /**
22 * A Supplier of objects of a single type. Semantically, this could be a
23 * Factory, Generator, Builder, Closure, Producer or something else entirely. No
24 * guarantees are implied by this interface. Implementations may return null if
25 * no objects are available, can optionally block until elements are available
26 * or throw {@link NoSuchElementException}.
27 * <p>
28 * Thread safety of a Supplier is not mandated by this interface, although
29 * serious care and consideration should be taken with any implementations that
30 * are not.
31 *
32 * @param <T> the type of object supplied.
33 * @see Google Collection's Supplier com.google.common.base.Supplier for a
34 * similar interface.
35 */
36 public interface Supplier<T> {
37 /**
38 * Produce an object. Retrieve an instance of the appropriate type. The
39 * returned object may or may not be a new instance, depending on the
40 * implementation.
41 *
42 * @return the product, may be null if there are no objects available.
43 * @throws NoSuchElementException if the supply has been exhausted.
44 */
45 T get();
46 }