View Javadoc

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