/** * Create a new LensKit recommender. Most code does not need to call this constructor, but * rather use {@link #build(LenskitConfiguration)} or a {@link LenskitRecommenderEngine}. * * @param graph This recommender's configuration graph. */ public LenskitRecommender(DAGNode<Component, Dependency> graph) { injector = new StaticInjector(graph); }
@Override public void close() { injector.close(); }
/** * Get a particular qualified component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param qual The qualifying annotation of the component class. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Annotation qual, Class<T> cls) { try { return injector.getInstance(qual, cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
@Nullable @Override public <T> T tryGetInstance(Annotation qualifier, Class<T> type) throws InjectionException { return tryGetInstance(Qualifiers.match(qualifier), type); }
public <T> T tryGetInstance(Class<? extends Annotation> qual, Class<T> type) throws InjectionException { return tryGetInstance(Qualifiers.match(qual), type); }
/** * Get a particular qualified component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param qual The qualifying annotation of the component class. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Class<? extends Annotation> qual, Class<T> cls) { try { return injector.tryGetInstance(qual, cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
/** * Create a new LensKit recommender. Most code does not need to call this constructor, but * rather use {@link #build(LenskitConfiguration)} or a {@link LenskitRecommenderEngine}. * * @param graph This recommender's configuration graph. */ public LenskitRecommender(DAGNode<Component, Dependency> graph) { injector = new StaticInjector(graph); }
@Override public void close() { injector.close(); }
/** * Get a particular qualified component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param qual The qualifying annotation of the component class. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Annotation qual, Class<T> cls) { try { return injector.getInstance(qual, cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
/** * Get a particular component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Class<T> cls) { try { return injector.tryGetInstance(cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
/** * Test that we can bind a file parameter to a string and have it work. * * @throws InjectionException if there is an (unexpected) injection failure. */ @Test @Ignore("this test is no longer effective") @SuppressWarnings("unchecked") public void testSetFile() throws InjectionException { LenskitConfiguration config = new LenskitConfiguration(); config.clearRoots(); // config.bind(EventFormat.class).to(Formats.ml100kFormat()); RecommenderGraphBuilder rgb = new RecommenderGraphBuilder(); rgb.addConfiguration(config); try (Injector inj = new StaticInjector(rgb.buildGraph())) { // File f = inj.getInstance(AnnotationBuilder.of(EventFile.class).build(), File.class); // assertThat(f.getName(), equalTo("ratings.foodat")); } } }
@Override public <T> T getInstance(Annotation qualifier, Class<T> type) throws InjectionException { T obj = tryGetInstance(Qualifiers.match(qualifier), type); if (obj == null) { throw new ResolutionException("no resolution available for " + type + " with qualifier " + qualifier); } else { return obj; } }
@Override public <T> T getInstance(Class<T> type) throws InjectionException { T obj = tryGetInstance(Qualifiers.matchDefault(), type); if (obj == null) { throw new ResolutionException("no resolution available for " + type); } else { return obj; } }
@Nullable @Override public <T> T tryGetInstance(Annotation qualifier, Class<T> type) throws InjectionException { return tryGetInstance(Qualifiers.match(qualifier), type); }
public <T> T tryGetInstance(Class<? extends Annotation> qual, Class<T> type) throws InjectionException { return tryGetInstance(Qualifiers.match(qual), type); }
/** * Get a particular component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Class<T> cls) { try { return injector.tryGetInstance(cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
/** * Get a particular qualified component from the recommender session. Generally you * want to use one of the type-specific getters; this method only exists for * specialized applications which need deep access to the recommender * components. * * @param <T> The type of component to get. * @param qual The qualifying annotation of the component class. * @param cls The component class to get. * @return The instance of the specified component. */ @Nullable public <T> T get(Class<? extends Annotation> qual, Class<T> cls) { try { return injector.tryGetInstance(qual, cls); } catch (InjectionException e) { throw new RecommenderBuildException("error instantiating component", e); } }
@Override public <T> T getInstance(Annotation qualifier, Class<T> type) throws InjectionException { T obj = tryGetInstance(Qualifiers.match(qualifier), type); if (obj == null) { throw new ResolutionException("no resolution available for " + type + " with qualifier " + qualifier); } else { return obj; } }
@Override public <T> T getInstance(Class<T> type) throws InjectionException { T obj = tryGetInstance(Qualifiers.matchDefault(), type); if (obj == null) { throw new ResolutionException("no resolution available for " + type); } else { return obj; } }