当前位置: 首页>>代码示例>>Java>>正文


Java Provider.get方法代码示例

本文整理汇总了Java中javax.inject.Provider.get方法的典型用法代码示例。如果您正苦于以下问题:Java Provider.get方法的具体用法?Java Provider.get怎么用?Java Provider.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.inject.Provider的用法示例。


在下文中一共展示了Provider.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import javax.inject.Provider; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("Unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:22,代码来源:ViewModelFactory.java

示例2: testSingleton

import javax.inject.Provider; //导入方法依赖的package包/类
@Test
public void testSingleton() {
    final Provider<MySingleton> provider = injector.getProvider(MySingleton.class);
    assertNotNull(provider);

    final MySingleton instance = provider.get();
    assertNotNull(instance);

    final Provider<MySingleton> provider2 = injector.getProvider(MySingleton.class);
    assertNotNull(provider2);
    assertEquals(provider, provider2);

    final MySingleton instance2 = provider2.get();
    assertNotNull(instance2);
    assertEquals(instance, instance2);
    assertTrue(instance == instance2);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:18,代码来源:InjectorTest.java

示例3: create

import javax.inject.Provider; //导入方法依赖的package包/类
@NonNull
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:23,代码来源:ViewModelFactory.java

示例4: create

import javax.inject.Provider; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);

    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }

    if (creator == null) {
        throw new IllegalArgumentException("Unknown model class " + modelClass);
    }

    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AndrejJurkin,项目名称:udacity-baking-app-mvvm-rxjava-dagger,代码行数:25,代码来源:ViewModelFactory.java

示例5: get

import javax.inject.Provider; //导入方法依赖的package包/类
@Override
public AndroidInjector<T> get(T instance) {
    //noinspection SuspiciousMethodCalls
    Provider<AndroidInjector.Factory<? extends T>> factoryProvider = injectorFactories.get(instance.getClass());
    if (factoryProvider == null) {
        throw new IllegalArgumentException("No injector available for " + instance);
    }

    @SuppressWarnings("unchecked")
    AndroidInjector.Factory<T> factory = (AndroidInjector.Factory<T>) factoryProvider.get();

    return checkNotNull(
            factory.create(instance),
            "%s.create(I) should not return null.",
            factory.getClass().getCanonicalName());
}
 
开发者ID:d4rken,项目名称:ommvplib,代码行数:17,代码来源:ComponentSource.java

示例6: create

import javax.inject.Provider; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:22,代码来源:GithubViewModelFactory.java

示例7: create

import javax.inject.Provider; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = mCreators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : mCreators
                .entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:amitkma,项目名称:android-architecture-boilerplate,代码行数:23,代码来源:ViewModelFactory.java

示例8: CachedMaterializationProvider

import javax.inject.Provider; //导入方法依赖的package包/类
public CachedMaterializationProvider(MaterializationDescriptorProvider provider,
                                     Provider<SabotContext> contextProvider, AccelerationService accel) {
  this.provider = Preconditions.checkNotNull(provider, "provider is required");
  this.accel = Preconditions.checkNotNull(accel, "acceleration service is required");
  Preconditions.checkNotNull(contextProvider, "context is required");

  final SabotContext context = contextProvider.get();
  storageRegistry = context.getStorage();
  namespaceService = context.getNamespaceService(SystemUser.SYSTEM_USERNAME);

  this.options = context.getOptionManager();

  final UserSession session = systemSession(options);

  this.queryContext = new QueryContext(session, context, new AttemptId().toQueryId());

  final long refreshDelay = options.getOption(MATERIALIZATION_CACHE_REFRESH_DURATION);

  enabled = options.getOption(MATERIALIZATION_CACHE_ENABLED);
  cached.set(EMPTY_MAP);

  initUpdater(refreshDelay);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:CachedMaterializationProvider.java

示例9: testProviderFieldInjection

import javax.inject.Provider; //导入方法依赖的package包/类
@Test
public void testProviderFieldInjection() {
    final Provider<ProviderFieldInjection> providerInjectionProvider = injector.getProvider(ProviderFieldInjection.class);
    assertNotNull(providerInjectionProvider);

    final ProviderFieldInjection providerInjection = providerInjectionProvider.get();
    assertNotNull(providerInjection);
    assertNotNull(providerInjection.provider);

    final C instance1 = providerInjection.provider.get();
    assertNotNull(instance1);

    final C instance2 = providerInjection.provider.get();
    assertNotNull(instance2);
    assertNotEquals(instance1, instance2);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:17,代码来源:InjectorTest.java

示例10: Car

import javax.inject.Provider; //导入方法依赖的package包/类
@Inject
public Car(Provider<Seat> seatProvider) {
	Seat driver = seatProvider.get();
	logger.info(driver + "");
	Seat passenger = seatProvider.get();
	logger.info(passenger + "");
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:8,代码来源:Car.java

示例11: extensions

import javax.inject.Provider; //导入方法依赖的package包/类
@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
private static ExtensionSet extensions(
        final Provider<Map<FsScheme, FsDriver>> provider) {
    if (provider instanceof TArchiveDetector)
        return new ExtensionSet(((TArchiveDetector) provider).extensions);
    final Map<FsScheme, FsDriver> map = provider.get();
    final ExtensionSet set = new ExtensionSet();
    for (final Entry<FsScheme, FsDriver> entry : map.entrySet())
        if (entry.getValue().isArchiveDriver())
            set.add(entry.getKey().toString());
    return set;
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:13,代码来源:TArchiveDetector.java

示例12: transform

import javax.inject.Provider; //导入方法依赖的package包/类
@Override
public Optional<M> transform(Provider<Optional<M>> provider) {
    // Provision these or die trying
    requiresProviders.forEach(Provider::get);

    // If any of these are empty, so are we
    if(!dependsProviders.stream().allMatch(p -> p.get().isPresent())) {
        return Optional.empty();
    }

    // Try to provision these, but we don't care if they are empty
    followsProviders.forEach(Provider::get);

    return provider.get();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:16,代码来源:ModuleDependencyTransformer.java

示例13: dynamic

import javax.inject.Provider; //导入方法依赖的package包/类
public static MethodHandleInvoker dynamic(Provider<?> targeter) {
    return new MethodHandleInvoker() {
        @Override protected Object targetFor(Method method) {
            return targeter.get();
        }
    };
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:MethodHandleInvoker.java

示例14: unwrappingExceptions

import javax.inject.Provider; //导入方法依赖的package包/类
public static <T, E extends Throwable> T unwrappingExceptions(Class<E> exception, Provider<T> block) throws E {
    try {
        return block.get();
    } catch(ProvisionException e) {
        throw unwrapException(exception, e);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:Injection.java

示例15: provide

import javax.inject.Provider; //导入方法依赖的package包/类
public <T> T provide(Key<T> key, Provider<T> provider) {
    T t = (T) map.get(key);
    if(t != null) return t;

    t = provider.get();
    if(!Scopes.isCircularProxy(t)) {
        store(key, t);
    }

    return t;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:12,代码来源:InjectionStore.java


注:本文中的javax.inject.Provider.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。