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 net.jcip.annotations.ThreadSafe;
20
21 /**
22 * A Function that resolves Descriptors (of type D) to a Resource (of type R).
23 * <p>
24 * Semantically, this could be a Factory, Generator, Builder, Closure,
25 * Transformer, Resolver or something else entirely. No particular guarantees
26 * are implied by this interface apart from idempotence (see below).
27 * Specifically, implementations may or may not return or accept null and can
28 * optionally block until elements are available or throw
29 * {@link RuntimeException runtime exceptions} if the input is not acceptable
30 * for some reason. Any clients that require a firmer contract should subclass
31 * this interface and document their requirements.
32 * <p>
33 * It is expected that for any two calls to {@link #get(Object)} D the returned
34 * resource will be semantically the same, ie. that the call is effectively
35 * idempotent. Any implementation that violates this should document the fact.
36 * It is not necessary that the resolved object is the same instance or even
37 * implements {@link Object#equals(Object)} and {@link Object#hashCode()}
38 * however.
39 * <p>
40 * As this interface requires idempotence implementations should be reentrant
41 * and thread-safe.
42 *
43 * @param <D> the descriptor type.
44 * @param <R> the resource type it resolves to.
45 */
46 @ThreadSafe
47 public interface Function<D, R> {
48 /**
49 * Resolves an output <R> where an input <D> is given.
50 *
51 * @param input an object of type D.
52 * @return the output of type R.
53 */
54 R get(D input);
55 }