本文整理汇总了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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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 + "");
}
示例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;
}
示例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();
}
示例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();
}
};
}
示例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);
}
}
示例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;
}