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 * <p>
32 * See also Google Collection's Supplier
33 * <code>com.google.common.base.Supplier</code> for a similar interface.
34 *
35 * @param <T> the type of object supplied.
36 */
37 public interface Supplier<T> {
38 /**
39 * Produce an object. Retrieve an instance of the appropriate type. The
40 * returned object may or may not be a new instance, depending on the
41 * implementation.
42 *
43 * @return the product, may be null if there are no objects available.
44 * @throws NoSuchElementException if the supply has been exhausted.
45 */
46 T get();
47 }