View Javadoc

1   /*
2    * Grapht, an open source dependency injector.
3    * Copyright 2014-2015 various contributors (see CONTRIBUTORS.txt)
4    * Copyright 2010-2014 Regents of the University of Minnesota
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as
8    * published by the Free Software Foundation; either version 2.1 of the
9    * License, or (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14   * details.
15   *
16   * You should have received a copy of the GNU General Public License along with
17   * this program; if not, write to the Free Software Foundation, Inc., 51
18   * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19   */
20  package org.grouplens.grapht.util;
21  
22  import javax.inject.Provider;
23  
24  /**
25   * A class with several inner classes implementing Provider for testing
26   * purposes.
27   */
28  public class TestingProviders {
29  
30      public static class Target implements Cloneable{}
31      public static class GenericTarget<T>{}
32  
33      /*
34       * The simplest form of provider. This has no generics or anything else sophisticated.
35       */
36      public static class SimpleProvider implements Provider<Object>{
37          public Target get(){
38              return null;
39          }
40      }
41      /*****************************************************************************/
42  
43      /*
44       * Creates the situation that TypedProviders are most needed.
45       *
46       * The Provider is parametrized over a type variable which is subject to type erasure
47       */
48      public static abstract class AbstractProvider<T> implements Provider<T>{
49          public T get(){
50              return null;
51          }
52      }
53      public static abstract class AbstractProvider2<T> extends AbstractProvider<T>{}
54  
55      public static class SubtypedProvider extends AbstractProvider<Target>{}
56  
57      public static class SubtypedProvider2 extends AbstractProvider2<Target>{}
58  
59     /*****************************************************************************/
60  
61     /*
62      * Same as the above, instead of abstract classes, provider is found up the interface hierarchy.
63      */
64     public static interface InterfaceProvider<T> extends Provider<T>{}
65  
66     public static interface InterfaceProvider2<T> extends InterfaceProvider<T>{}
67  
68      public static class ImplementedProvider implements InterfaceProvider<Target>{
69          public Target get(){
70              return null;
71          }
72      }
73  
74      public static class ImplementedProvider2 implements InterfaceProvider2<Target>{
75          public Target get(){
76              return null;
77          }
78      }
79  
80      /*****************************************************************************/
81  
82      /*
83       * These are Providers with unbound type variables. These are **not** supported.
84       */
85      public static class BoundedProvider<T extends Target> implements Provider<T>{
86          public T get(){
87              return null;
88          }
89      }
90  
91  
92      public static class UnboundedProvider<T> implements Provider<T>{
93          public T get(){
94              return null;
95          }
96      }
97  
98      public static class MultiBoundProvider<T extends Target & Cloneable> implements Provider<T>{
99          public T get(){
100             return null;
101         }
102     }
103 }