1 package com.atlassian.util.concurrent;
2
3 import static com.atlassian.util.concurrent.Assertions.notNull;
4
5 public final class Functions {
6
7
8
9
10
11
12
13
14 public static <D, R> Function<D, R> fromSupplier(final @NotNull Supplier<R> supplier) {
15 return new FromSupplier<D, R>(supplier);
16 }
17
18 private static class FromSupplier<D, R> implements Function<D, R> {
19 private final Supplier<R> supplier;
20
21 FromSupplier(final Supplier<R> supplier) {
22 this.supplier = notNull("supplier", supplier);
23 }
24
25 public R get(final D input) {
26 return supplier.get();
27 }
28 };
29
30
31
32
33
34
35
36 public static <T> Function<T, T> identity() {
37 return new Identity<T>();
38 }
39
40 private static class Identity<T> implements Function<T, T> {
41 public T get(final T input) {
42 return input;
43 }
44 }
45
46
47 private Functions() {}
48
49 }