@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; }
@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()); }
/** * 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; }
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; }
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(); }
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); }
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; }
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); }
/** * 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; }
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>(); }
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(); }
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(); }
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(); }
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(); }
public SingleConsumerContextImpl(ClassToInstanceMap<BindingAwareService> serviceProvider) { this.alreadyRetrievedServices = MutableClassToInstanceMap.create(); this.serviceProvider = serviceProvider; }
@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; }
public ServiceRegistry() { this.services=MutableClassToInstanceMap.<Service>create(); this.builders=new LinkedHashMap<Class<?>, ServiceBuilder<?>>(); this.delegate=RuntimeDelegate.getInstance(); }
private TemplateManagerBuilder() { this.handlerClasses=Lists.newArrayList(); this.handlers=MutableClassToInstanceMap.<ResourceHandler>create(); }
public static <B> ClassToInstanceStorage<B> create() { return create(MutableClassToInstanceMap.<B>create()); }
public static <B> ClassToInstanceStorage<B> createLinked() { return create(MutableClassToInstanceMap.create(new LinkedHashMap<Class<? extends B>, B>())); }
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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }