當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。