本文整理匯總了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;
}