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 Factory, Generator,
23 * Builder, Closure, Producer or something else entirely. No guarantees are implied by this
24 * interface. Implementations may return null if no objects are available, can optionally block
25 * until elements are available or throw {@link NoSuchElementException}.
26 * <p>
27 * Thread safety of a Supplier is not mandated by this interface, although serious care and
28 * consideration should be taken with any implementations that are not.
29 *
30 * @param <T> the type of object supplied.
31 * @see com.google.common.base.Supplier for a similar interface.
32 */
33 public interface Supplier<T> {
34 /**
35 * Produce an object. Retrieve an instance of the appropriate type. The returned object may or
36 * may not be a new instance, depending on the implementation.
37 *
38 * @return the product, may be null if there are no objects available.
39 * @throws NoSuchElementException if the supply has been exhausted.
40 */
41 T get();
42 }