Java 类com.google.common.collect.MutableClassToInstanceMap 实例源码

项目:FinanceAnalytics    文件:ComponentMapProvider.java   
@Override
public ComponentMap get() {

  ClassToInstanceMap<Object> components = MutableClassToInstanceMap.create();

  components.putInstance(HolidaySource.class, _holidaySource);
  components.putInstance(ConfigSource.class, _configSource);
  components.putInstance(HistoricalTimeSeriesSource.class, _htsSource);
  components.putInstance(ConventionBundleSource.class, _conventionBundleSource);
  components.putInstance(HistoricalTimeSeriesResolver.class, _htsResolver);
  components.putInstance(SecuritySource.class, _securitySource);
  components.putInstance(ConventionSource.class, _conventionSource);
  components.putInstance(RegionSource.class, _regionSource);
  components.putInstance(PositionSource.class, _positionSource);
  components.putInstance(MarketDataSnapshotSource.class, _snapshotSource);
  components.putInstance(LegalEntitySource.class, _legalEntitySource);
  components.putInstance(ExchangeSource.class, _exchangeSource);

  ComponentMap componentMap = ComponentMap.of(components);
  ServiceContext serviceContext = ServiceContext.of(componentMap.getComponents())
      .with(VersionCorrectionProvider.class,
            new FixedInstantVersionCorrectionProvider(Instant.now()));
  ThreadLocalServiceContext.init(serviceContext);

  return componentMap;
}
项目:java-util-examples    文件:ClassToInstanceMapExample.java   
@Test
public void classToINstanceMap_example () {

    Person person = new Person("Jackson");
    Jobs jobs = new Jobs("IT person");
    Address address = new  Address("505 Williams Street");

    ClassToInstanceMap<Object> classToInstanceMap = MutableClassToInstanceMap.create();
    classToInstanceMap.put(Person.class, person);
    classToInstanceMap.put(Jobs.class, jobs);
    classToInstanceMap.put(Address.class, address);

    logger.info(classToInstanceMap);

    assertEquals("IT person", classToInstanceMap.getInstance(Jobs.class).getJobName());
}
项目:bazel    文件:BuildConfiguration.java   
/**
 * Returns a copy of this configuration only including the given fragments (which the current
 * configuration is assumed to have).
 */
public BuildConfiguration clone(
    FragmentClassSet fragmentClasses, RuleClassProvider ruleClassProvider) {

  ClassToInstanceMap<Fragment> fragmentsMap = MutableClassToInstanceMap.create();
  for (Fragment fragment : fragments.values()) {
    if (fragmentClasses.fragmentClasses().contains(fragment.getClass())) {
      fragmentsMap.put(fragment.getClass(), fragment);
    }
  }
  BuildOptions options = buildOptions.trim(
      getOptionsClasses(fragmentsMap.keySet(), ruleClassProvider));
  BuildConfiguration newConfig =
      new BuildConfiguration(
          directories,
          fragmentsMap,
          options,
          mainRepositoryName.strippedName());
  return newConfig;
}
项目:levelup-java-examples    文件:ClassToInstanceMapExample.java   
@Test
public void classToINstanceMap_example () {

    Person person = new Person("Jackson");
    Jobs jobs = new Jobs("IT person");
    Address address = new  Address("505 Williams Street");

    ClassToInstanceMap<Object> classToInstanceMap = MutableClassToInstanceMap.create();
    classToInstanceMap.put(Person.class, person);
    classToInstanceMap.put(Jobs.class, jobs);
    classToInstanceMap.put(Address.class, address);

    logger.info(classToInstanceMap);

    assertEquals("IT person", classToInstanceMap.getInstance(Jobs.class).getJobName());
}
项目:GitHub    文件:StaticEnvironment.java   
void init(Set<? extends TypeElement> annotations, RoundEnvironment round, ProcessingEnvironment processing) {
  this.components = MutableClassToInstanceMap.create();
  this.processing = processing;
  this.round = round;
  this.annotations = ImmutableSet.copyOf(annotations);
  this.initialized = true;
}
项目:beam    文件:ProxyInvocationHandler.java   
private ProxyInvocationHandler(
    Map<String, BoundValue> options, Map<String, JsonNode> jsonOptions) {
  this.options = options;
  this.jsonOptions = jsonOptions;
  this.knownInterfaces = new HashSet<>(PipelineOptionsFactory.getRegisteredOptions());
  gettersToPropertyNames = Maps.newHashMap();
  settersToPropertyNames = Maps.newHashMap();
  interfaceToProxyCache = MutableClassToInstanceMap.create();
}
项目:guava-demo    文件:ClassToInstanceSample.java   
public static void main(String[] args) {
    ClassToInstanceMap<Number> numbers = MutableClassToInstanceMap.create();

    numbers.putInstance(Integer.class, Integer.valueOf(0));
    numbers.putInstance(Double.class, Double.valueOf(1));
    numbers.putInstance(Float.class, Float.valueOf(3));

    double myNum = numbers.getInstance(Double.class);
    System.out.println(myNum);
}
项目:FinanceAnalytics    文件:MockUtils.java   
private static MutableClassToInstanceMap<Object> doMock(List<Class<?>> classes, boolean isStrict) {

  MutableClassToInstanceMap<Object> mocks = MutableClassToInstanceMap.create();
  for (Class<?> clazz : classes) {
    if (isStrict) {
      mocks.put(clazz, strictMock(clazz));
    } else {
      mocks.put(clazz, mock(clazz));
    }
  }

  return mocks;
}
项目:tensorics-core    文件:ImmutableOptionRegistry.java   
private <T1 extends Option<T1>> ImmutableOptionRegistry(Collection<T> options) {
    /*
     * we first have to create a mutable map, because the collection might contain options of the same class, where
     * later ones will override previous ones. This would not be allowed by the builder of the immutable map.
     */
    ClassToInstanceMap<T> mutableOptions = MutableClassToInstanceMap.create();
    addToMap(mutableOptions, options);
    this.options = ImmutableClassToInstanceMap.copyOf(mutableOptions);
}
项目:sette-tool    文件:SetteAnnotationUtils.java   
/**
 * Gets the map of SETTE annotations.
 *
 * @param element
 *            an annotated element
 * @return a map of SETTE annotations
 */
public static ClassToInstanceMap<Annotation> getSetteAnnotations(
        @NonNull AnnotatedElement element) {
    ClassToInstanceMap<Annotation> setteAnnots = MutableClassToInstanceMap.create();

    Arrays.stream(element.getAnnotations())
            .filter(SetteAnnotationUtils::isSetteAnnotation)
            .forEach(a -> setteAnnots.put(a.annotationType(), a));

    return setteAnnots;
}
项目:OpenBMLParser    文件:BehaviourBlock.java   
public BehaviourBlock(BMLBehaviorAttributeExtension... bmlBehaviorAttributeExtensions)
{
    this.bmlBehaviorAttributeExtensions = MutableClassToInstanceMap.create();
    for (BMLBehaviorAttributeExtension ext : bmlBehaviorAttributeExtensions)
    {
        this.bmlBehaviorAttributeExtensions.put(ext.getClass(), ext);
    }
    requiredBlocks = new ArrayList<RequiredBlock>();
    constraintBlocks = new ArrayList<ConstraintBlock>();
    behaviours = new ArrayList<Behaviour>();
}
项目:immutables    文件:StaticEnvironment.java   
void init(Set<? extends TypeElement> annotations, RoundEnvironment round, ProcessingEnvironment processing) {
  this.components = MutableClassToInstanceMap.create();
  this.processing = processing;
  this.round = round;
  this.annotations = ImmutableSet.copyOf(annotations);
  this.initialized = true;
}
项目:rigel    文件:ContentItemFactory.java   
public <T extends ContentItem> ImmutableList<T> fromResponse(QueryResponse response, ContentItem.Schema<T> forcedSchema, FieldSet... additionalFields) {
    ClassToInstanceMap<FieldDataSource<?>> context = MutableClassToInstanceMap.create();
    context.put(QueryResponseDataSource.class, new QueryResponseDataSource(response));

    Builder<T> builder = ImmutableList.builder();
    for(SolrDocument doc : response.getResults()) {
        context.put(SolrDocDataSource.class, new SolrDocDataSource(doc));
        context.put(SchemaDataSource.class, new SchemaDataSource(forcedSchema));
        builder.add(buildItem(forcedSchema, context, additionalFields));
    }
    return builder.build();
}
项目:rigel    文件:ContentItemFactory.java   
public <T extends ContentItem> ImmutableList<T> fromDocumentList(SolrDocumentList list, ContentItem.Schema<T> forcedSchema, FieldSet... additionalFields) {
    ClassToInstanceMap<FieldDataSource<?>> context = MutableClassToInstanceMap.create();
    Builder<T> builder = ImmutableList.builder();
    for(SolrDocument doc : list) {
        context.put(SolrDocDataSource.class, new SolrDocDataSource(doc));
        context.put(SchemaDataSource.class, new SchemaDataSource(forcedSchema));
        builder.add(buildItem(forcedSchema, context, additionalFields));
    }
    return builder.build();
}
项目:rigel    文件:ContentItemFactory.java   
public ImmutableList<ContentItem> fromResponse(QueryResponse response, FieldSet... additionalFields) {
    ClassToInstanceMap<FieldDataSource<?>> context = MutableClassToInstanceMap.create();
    context.put(QueryResponseDataSource.class, new QueryResponseDataSource(response));

    Builder<ContentItem> builder = ImmutableList.builder();
    for(SolrDocument doc : response.getResults()) {
        ContentItem.Schema<?> schema = getSchemaForDocument(doc);
        context.put(SchemaDataSource.class, new SchemaDataSource(schema));
        context.put(SolrDocDataSource.class, new SolrDocDataSource(doc));
        builder.add(buildItem(schema, context, additionalFields));
    }
    return builder.build();
}
项目:rigel    文件:ContentItemFactory.java   
public ImmutableList<ContentItem> fromDocumentList(SolrDocumentList list, FieldSet... additionalFields) {
    ClassToInstanceMap<FieldDataSource<?>> context = MutableClassToInstanceMap.create();
    Builder<ContentItem> builder = ImmutableList.builder();
    for(SolrDocument doc : list) {
        ContentItem.Schema<?> schema = getSchemaForDocument(doc);
        context.put(SchemaDataSource.class, new SchemaDataSource(schema));
        context.put(SolrDocDataSource.class, new SolrDocDataSource(doc));
        builder.add(buildItem(schema, context, additionalFields));
    }
    return builder.build();
}
项目:hashsdn-controller    文件:BindingContextUtils.java   
public SingleConsumerContextImpl(ClassToInstanceMap<BindingAwareService> serviceProvider) {
    this.alreadyRetrievedServices = MutableClassToInstanceMap.create();
    this.serviceProvider = serviceProvider;
}
项目:hashsdn-controller    文件:DomBrokerImplModule.java   
@Override
public java.lang.AutoCloseable createInstance() {
    // The services are provided via blueprint so retrieve then from the OSGi service registry for
    // backwards compatibility.

    final List<AutoCloseable> closeables = new ArrayList<>();
    DOMNotificationService domNotificationService = newTracker(
            DOMNotificationService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);

    DOMNotificationPublishService domNotificationPublishService = newTracker(
            DOMNotificationPublishService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);

    DOMRpcService domRpcService = newTracker(
            DOMRpcService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);

    DOMRpcProviderService domRpcProvider = newTracker(
            DOMRpcProviderService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES);

    DOMMountPointService mountService = newTracker(DOMMountPointService.class, closeables).
            waitForService(WaitingServiceTracker.FIVE_MINUTES);

    SchemaService globalSchemaService = newTracker(SchemaService.class, closeables).
            waitForService(WaitingServiceTracker.FIVE_MINUTES);

    final DOMDataBroker dataBroker = getAsyncDataBrokerDependency();

    final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();

    services.putInstance(DOMNotificationService.class, domNotificationService);
    services.putInstance(DOMNotificationPublishService.class, domNotificationPublishService);

    final SchemaService schemaService = getSchemaServiceImpl(globalSchemaService);
    services.putInstance(SchemaService.class, schemaService);

    services.putInstance(DOMDataBroker.class, dataBroker);

    services.putInstance(DOMRpcService.class, domRpcService);
    services.putInstance(DOMRpcProviderService.class, domRpcProvider);

    services.putInstance(DOMMountPointService.class, mountService);

    BrokerImpl broker = new BrokerImpl(domRpcService, domRpcProvider, services);
    broker.setDeactivator(() -> {
        for (AutoCloseable ac : closeables) {
            try {
                ac.close();
            } catch (Exception e) {
                LOG.warn("Exception while closing {}", ac, e);
            }
        }
    });

    return broker;
}
项目:ldp4j    文件:ServiceRegistry.java   
public ServiceRegistry() {
    this.services=MutableClassToInstanceMap.<Service>create();
    this.builders=new LinkedHashMap<Class<?>, ServiceBuilder<?>>();
    this.delegate=RuntimeDelegate.getInstance();
}
项目:ldp4j    文件:TemplateManager.java   
private TemplateManagerBuilder() {
    this.handlerClasses=Lists.newArrayList();
    this.handlers=MutableClassToInstanceMap.<ResourceHandler>create();
}
项目:ServerListPlus    文件:ClassToInstanceStorage.java   
public static <B> ClassToInstanceStorage<B> create() {
    return create(MutableClassToInstanceMap.<B>create());
}
项目:ServerListPlus    文件:ClassToInstanceStorage.java   
public static <B> ClassToInstanceStorage<B> createLinked() {
    return create(MutableClassToInstanceMap.create(new LinkedHashMap<Class<? extends B>, B>()));
}
项目:hashsdn-controller    文件:BindingTestContext.java   
private void startDomBroker() {
    checkState(this.executor != null);

    this.domRouter = new DOMRpcRouter();
    this.mockSchemaService.registerSchemaContextListener(this.domRouter);

    final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create();
    services.put(DOMRpcService.class, this.domRouter);

    this.biBrokerImpl = new BrokerImpl(this.domRouter,services);

}
项目:FinanceAnalytics    文件:MockUtils.java   
/**
 * Returns a map of mock instances, indexed by class.
 * @param classes the classes to use to mock
 * @return a map of class to mock
 */
public static MutableClassToInstanceMap<Object> mocks(Class<?>...classes ) {
  return doMock(Arrays.asList(classes), false);
}
项目:FinanceAnalytics    文件:MockUtils.java   
/**
 * Returns a map of mock instances, indexed by class.
 * @param classes the classes to use to mock
 * @return a map of class to mock
 */
public static MutableClassToInstanceMap<Object> mocks(List<Class<?>> classes ) {
  return doMock(classes, false);
}
项目:FinanceAnalytics    文件:MockUtils.java   
/**
 * Returns a map of strict mock instances, indexed by class.
 * @param classes the classes to use to mock
 * @return a map of class to mock
 */
public static MutableClassToInstanceMap<Object> strictMocks(List<Class<?>> classes ) {
  return doMock(classes, true);
}
项目:FinanceAnalytics    文件:MockUtils.java   
/**
 * Returns a map of strict mock instances, indexed by class.
 * @param classes the classes to use to mock
 * @return a map of class to mock
 */
public static MutableClassToInstanceMap<Object> strictMocks(Class<?>... classes) {
  return doMock(Arrays.asList(classes), true);
}