Java Code Examples for com.google.common.collect.ClassToInstanceMap

The following are top voted examples for showing how to use com.google.common.collect.ClassToInstanceMap. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: FinanceAnalytics   File: ComponentMapProvider.java   View source code 6 votes vote down vote up
@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;
}
 
Example 2
Project: java-util-examples   File: ClassToInstanceMapExample.java   View source code 6 votes vote down vote up
@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());
}
 
Example 3
Project: bazel   File: BuildConfiguration.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Project: levelup-java-examples   File: ClassToInstanceMapExample.java   View source code 6 votes vote down vote up
@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());
}
 
Example 5
Project: rigel   File: HighlightField.java   View source code 6 votes vote down vote up
private List<String> getHighlights(ClassToInstanceMap<FieldDataSource<?>> context) {
    QueryResponse response = context.getInstance(QueryResponseDataSource.class).get();
    Schema<?> schema = context.getInstance(SchemaDataSource.class).get();

    String docId = schema.id.getField().getValue(context);
    if (docId == null) {
        return null;
    }
    Map<String, Map<String, List<String>>> hilighting = response.getHighlighting();
    if (hilighting == null) {
        return null;
    }
    Map<String, List<String>> hilightingForDoc =  hilighting.get(docId);
    if (hilightingForDoc == null) {
        return null;
    }
    return hilightingForDoc.get(getFieldName());
}
 
Example 6
Project: GitHub   File: StaticEnvironment.java   View source code 5 votes vote down vote up
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) {
  ClassToInstanceMap<Completable> components = state().components;
  @Nullable T instance = components.getInstance(type);
  if (instance == null) {
    instance = supplier.get();
    components.putInstance(type, instance);
  }
  return instance;
}
 
Example 7
Project: guava-demo   File: ClassToInstanceSample.java   View source code 5 votes vote down vote up
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);
}
 
Example 8
Project: tensorics-core   File: Coordinates.java   View source code 5 votes vote down vote up
/**
 * Creates a class to instance map, from the given coordinates. The map will contain the classes of the coordinates
 * as keys and the coordinates themselves as values. Duplicate keys (dimensions) are not allowed and will result in
 * an {@link IllegalArgumentException}.
 * 
 * @param coordinates the coordinates to be added to the map
 * @return an immutable map from dimensions (coordinate classes) to coordinate
 * @throws IllegalArgumentException if more than one coordinate per dimension are provided
 * @deprecated
 */
@Deprecated
public static <C> ClassToInstanceMap<C> mapOf(Iterable<? extends C> coordinates) {
    ImmutableClassToInstanceMap.Builder<C> coordinateBuilder = ImmutableClassToInstanceMap.builder();
    for (C coordinate : coordinates) {
        @SuppressWarnings("unchecked")
        Class<C> coordinateClass = (Class<C>) coordinate.getClass();
        coordinateBuilder.put(coordinateClass, coordinate);
    }
    return coordinateBuilder.build();
}
 
Example 9
Project: tensorics-core   File: ImmutableOptionRegistry.java   View source code 5 votes vote down vote up
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);
}
 
Example 10
Project: tensorics-core   File: ImmutableOptionRegistry.java   View source code 5 votes vote down vote up
private void addToMap(ClassToInstanceMap<T> mutableMap, Collection<T> toAdd) {
    for (T option : toAdd) {
        @SuppressWarnings("unchecked")
        Class<T> markerInterface = (Class<T>) option.getMarkerInterface();
        mutableMap.putInstance(markerInterface, option);
    }
}
 
Example 11
Project: sette-tool   File: SetteAnnotationUtils.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Project: error-prone   File: PlaceholderMethod.java   View source code 5 votes vote down vote up
static PlaceholderMethod create(
    CharSequence name,
    UType returnType,
    ImmutableMap<UVariableDecl, ImmutableClassToInstanceMap<Annotation>> parameters,
    ClassToInstanceMap<Annotation> annotations) {
  final boolean allowsIdentity = annotations.getInstance(Placeholder.class).allowsIdentity();
  final Class<? extends Matcher<? super ExpressionTree>> matchesClass =
      annotations.containsKey(Matches.class)
          ? UTemplater.getValue(annotations.getInstance(Matches.class))
          : null;
  final Class<? extends Matcher<? super ExpressionTree>> notMatchesClass =
      annotations.containsKey(NotMatches.class)
          ? UTemplater.getValue(annotations.getInstance(NotMatches.class))
          : null;
  final Predicate<Tree.Kind> allowedKinds =
      annotations.containsKey(OfKind.class)
          ? Predicates.<Tree.Kind>in(Arrays.asList(annotations.getInstance(OfKind.class).value()))
          : Predicates.<Tree.Kind>alwaysTrue();
  class PlaceholderMatcher implements Serializable, Matcher<ExpressionTree> {

    @Override
    public boolean matches(ExpressionTree t, VisitorState state) {
      try {
        return (allowsIdentity || !(t instanceof PlaceholderParamIdent))
            && (matchesClass == null || matchesClass.newInstance().matches(t, state))
            && (notMatchesClass == null || !notMatchesClass.newInstance().matches(t, state))
            && allowedKinds.apply(t.getKind());
      } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
  }
  return new AutoValue_PlaceholderMethod(
      StringName.of(name),
      returnType,
      parameters,
      new PlaceholderMatcher(),
      ImmutableClassToInstanceMap.<Annotation, Annotation>copyOf(annotations));
}
 
Example 13
Project: error-prone   File: UnnecessarySetDefaultTest.java   View source code 5 votes vote down vote up
@Test
public void exhaustive() throws ReflectiveOperationException {
  Field f = ArbitraryInstances.class.getDeclaredField("DEFAULTS");
  f.setAccessible(true);
  ClassToInstanceMap<?> actual = (ClassToInstanceMap<?>) f.get(null);
  assertThat(UnnecessarySetDefault.DEFAULTS.keySet())
      .containsAnyIn(
          actual.keySet().stream().map(Class::getCanonicalName).collect(toImmutableList()));
}
 
Example 14
Project: cloudata   File: CloudataConnectorFactory.java   View source code 5 votes vote down vote up
@Override
public Connector create(final String connectorId, Map<String, String> requiredConfig) {
    checkNotNull(requiredConfig, "requiredConfig is null");
    checkNotNull(optionalConfig, "optionalConfig is null");

    try {
        // // A plugin is not required to use Guice; it is just very convenient
        // Bootstrap app = new Bootstrap(new JsonModule(), new ExampleModule(connectorId));
        //
        // Injector injector = app.strictConfig().doNotInitializeLogging()
        // .setRequiredConfigurationProperties(requiredConfig)
        // .setOptionalConfigurationProperties(optionalConfig).initialize();

        ClassToInstanceMap<Object> services = ImmutableClassToInstanceMap.builder()

        .put(ConnectorMetadata.class, new CloudataConnectorMetadata(connectorId, store))

        .put(ConnectorSplitManager.class, new CloudataSplitManager(nodeManager, connectorId))

        .put(ConnectorRecordSetProvider.class, new CloudataConnectorRecordSetProvider())

        .put(ConnectorHandleResolver.class, new CloudataConnectorHandleResolver()).build();

        CloudataConnector connector = new CloudataConnector(store, services);
        connectors.put(connectorId, connector);
        return connector;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
Example 15
Project: immutables   File: StaticEnvironment.java   View source code 5 votes vote down vote up
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) {
  ClassToInstanceMap<Completable> components = state().components;
  @Nullable T instance = components.getInstance(type);
  if (instance == null) {
    instance = supplier.get();
    components.putInstance(type, instance);
  }
  return instance;
}
 
Example 16
Project: rigel   File: FieldSet.java   View source code 5 votes vote down vote up
@Override
public void storeValue(Map<DataKey<?>, ? super Object> map, ClassToInstanceMap<FieldDataSource<?>> context) {
    R rawValue = field.getValue(context);
    if (eagerTransform) {
        map.put(this, formatRawValue(rawValue));
    } else {
        map.put(this, rawValue);
    }
}
 
Example 17
Project: rigel   File: ContentItemFactory.java   View source code 5 votes vote down vote up
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();
}
 
Example 18
Project: rigel   File: ContentItemFactory.java   View source code 5 votes vote down vote up
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();
}
 
Example 19
Project: rigel   File: ContentItemFactory.java   View source code 5 votes vote down vote up
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();
}
 
Example 20
Project: rigel   File: ContentItemFactory.java   View source code 5 votes vote down vote up
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();
}
 
Example 21
Project: rigel   File: HighlightField.java   View source code 5 votes vote down vote up
@Override
public String getValue(ClassToInstanceMap<FieldDataSource<?>> context) {
    List<String> highlights = getHighlights(context);
    if (highlights == null || highlights.size() == 0) {
        return null;
    }
    return highlights.get(0);
}
 
Example 22
Project: guava-mock   File: ArbitraryInstancesTest.java   View source code 4 votes vote down vote up
public void testGet_collections() {
  assertEquals(ImmutableSet.of().iterator(), ArbitraryInstances.get(Iterator.class));
  assertFalse(ArbitraryInstances.get(PeekingIterator.class).hasNext());
  assertFalse(ArbitraryInstances.get(ListIterator.class).hasNext());
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Iterable.class));
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Set.class));
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(ImmutableSet.class));
  assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(SortedSet.class));
  assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(ImmutableSortedSet.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(Collection.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableCollection.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(List.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableList.class));
  assertEquals(ImmutableMap.of(), ArbitraryInstances.get(Map.class));
  assertEquals(ImmutableMap.of(), ArbitraryInstances.get(ImmutableMap.class));
  assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(SortedMap.class));
  assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(ImmutableSortedMap.class));
  assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(Multiset.class));
  assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(ImmutableMultiset.class));
  assertTrue(ArbitraryInstances.get(SortedMultiset.class).isEmpty());
  assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(Multimap.class));
  assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(ImmutableMultimap.class));
  assertTrue(ArbitraryInstances.get(SortedSetMultimap.class).isEmpty());
  assertEquals(ImmutableTable.of(), ArbitraryInstances.get(Table.class));
  assertEquals(ImmutableTable.of(), ArbitraryInstances.get(ImmutableTable.class));
  assertTrue(ArbitraryInstances.get(RowSortedTable.class).isEmpty());
  assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(BiMap.class));
  assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(ImmutableBiMap.class));
  assertTrue(ArbitraryInstances.get(ImmutableClassToInstanceMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ClassToInstanceMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ListMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ImmutableListMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SetMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ImmutableSetMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(MapDifference.class).areEqual());
  assertTrue(ArbitraryInstances.get(SortedMapDifference.class).areEqual());
  assertEquals(Range.all(), ArbitraryInstances.get(Range.class));
  assertTrue(ArbitraryInstances.get(NavigableSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(NavigableMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(LinkedList.class).isEmpty());
  assertTrue(ArbitraryInstances.get(Deque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(Queue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BitSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(TreeSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(TreeMap.class).isEmpty());
  assertFreshInstanceReturned(
      LinkedList.class, Deque.class, Queue.class, PriorityQueue.class, BitSet.class,
      TreeSet.class, TreeMap.class);
}
 
Example 23
Project: googles-monorepo-demo   File: ArbitraryInstancesTest.java   View source code 4 votes vote down vote up
public void testGet_collections() {
  assertEquals(ImmutableSet.of().iterator(), ArbitraryInstances.get(Iterator.class));
  assertFalse(ArbitraryInstances.get(PeekingIterator.class).hasNext());
  assertFalse(ArbitraryInstances.get(ListIterator.class).hasNext());
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Iterable.class));
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(Set.class));
  assertEquals(ImmutableSet.of(), ArbitraryInstances.get(ImmutableSet.class));
  assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(SortedSet.class));
  assertEquals(ImmutableSortedSet.of(), ArbitraryInstances.get(ImmutableSortedSet.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(Collection.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableCollection.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(List.class));
  assertEquals(ImmutableList.of(), ArbitraryInstances.get(ImmutableList.class));
  assertEquals(ImmutableMap.of(), ArbitraryInstances.get(Map.class));
  assertEquals(ImmutableMap.of(), ArbitraryInstances.get(ImmutableMap.class));
  assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(SortedMap.class));
  assertEquals(ImmutableSortedMap.of(), ArbitraryInstances.get(ImmutableSortedMap.class));
  assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(Multiset.class));
  assertEquals(ImmutableMultiset.of(), ArbitraryInstances.get(ImmutableMultiset.class));
  assertTrue(ArbitraryInstances.get(SortedMultiset.class).isEmpty());
  assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(Multimap.class));
  assertEquals(ImmutableMultimap.of(), ArbitraryInstances.get(ImmutableMultimap.class));
  assertTrue(ArbitraryInstances.get(SortedSetMultimap.class).isEmpty());
  assertEquals(ImmutableTable.of(), ArbitraryInstances.get(Table.class));
  assertEquals(ImmutableTable.of(), ArbitraryInstances.get(ImmutableTable.class));
  assertTrue(ArbitraryInstances.get(RowSortedTable.class).isEmpty());
  assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(BiMap.class));
  assertEquals(ImmutableBiMap.of(), ArbitraryInstances.get(ImmutableBiMap.class));
  assertTrue(ArbitraryInstances.get(ImmutableClassToInstanceMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ClassToInstanceMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ListMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ImmutableListMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SetMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ImmutableSetMultimap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(MapDifference.class).areEqual());
  assertTrue(ArbitraryInstances.get(SortedMapDifference.class).areEqual());
  assertEquals(Range.all(), ArbitraryInstances.get(Range.class));
  assertTrue(ArbitraryInstances.get(NavigableSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(NavigableMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(LinkedList.class).isEmpty());
  assertTrue(ArbitraryInstances.get(Deque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(Queue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BitSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(TreeSet.class).isEmpty());
  assertTrue(ArbitraryInstances.get(TreeMap.class).isEmpty());
  assertFreshInstanceReturned(
      LinkedList.class, Deque.class, Queue.class, PriorityQueue.class, BitSet.class,
      TreeSet.class, TreeMap.class);
}
 
Example 24
Project: hashsdn-controller   File: BrokerImpl.java   View source code 4 votes vote down vote up
public BrokerImpl(final DOMRpcRouter router,final ClassToInstanceMap<BrokerService> services) {
    this(router, router, services);
}
 
Example 25
Project: hashsdn-controller   File: BrokerImpl.java   View source code 4 votes vote down vote up
public BrokerImpl(final DOMRpcService rpcService, final DOMRpcProviderService rpcProvider,
        final ClassToInstanceMap<BrokerService> services) {
    this.rpcService = Preconditions.checkNotNull(rpcService, "DOMRpcService must not be null");
    this.rpcProvider = Preconditions.checkNotNull(rpcProvider, "DOMRpcProviderService must not be null");
    this.services = ImmutableClassToInstanceMap.copyOf(services);
}
 
Example 26
Project: hashsdn-controller   File: SimpleDOMMountPoint.java   View source code 4 votes vote down vote up
public static final SimpleDOMMountPoint create(final YangInstanceIdentifier identifier, final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
    return new SimpleDOMMountPoint(identifier, services, ctx);
}
 
Example 27
Project: hashsdn-controller   File: SimpleDOMMountPoint.java   View source code 4 votes vote down vote up
private SimpleDOMMountPoint(final YangInstanceIdentifier identifier, final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
    this.identifier = identifier;
    this.services = ImmutableClassToInstanceMap.copyOf(services);
    this.schemaContext = ctx;
}
 
Example 28
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public static ConsumerContext createConsumerContext(BindingAwareConsumer consumer,
        ClassToInstanceMap<BindingAwareService> serviceProvider) {
    checkNotNull(consumer,"Consumer should not be null");
    checkNotNull(serviceProvider,"Service map should not be null");
    return new SingleConsumerContextImpl(serviceProvider);
}
 
Example 29
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public static ProviderContext createProviderContext(BindingAwareProvider provider,
        ClassToInstanceMap<BindingAwareService> serviceProvider) {
    checkNotNull(provider,"Provider should not be null");
    checkNotNull(serviceProvider,"Service map should not be null");
    return new SingleProviderContextImpl(serviceProvider);
}
 
Example 30
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public static ConsumerContext createConsumerContextAndInitialize(BindingAwareConsumer consumer,
        ClassToInstanceMap<BindingAwareService> serviceProvider) {
    ConsumerContext context = createConsumerContext(consumer, serviceProvider);
    consumer.onSessionInitialized(context);
    return context;
}
 
Example 31
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public static ProviderContext createProviderContextAndInitialize(BindingAwareProvider provider,
        ClassToInstanceMap<BindingAwareService> serviceProvider) {
    ProviderContext context = createProviderContext(provider, serviceProvider);
    provider.onSessionInitiated(context);
    return context;
}
 
Example 32
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public SingleConsumerContextImpl(ClassToInstanceMap<BindingAwareService> serviceProvider) {
    this.alreadyRetrievedServices = MutableClassToInstanceMap.create();
    this.serviceProvider = serviceProvider;
}
 
Example 33
Project: hashsdn-controller   File: BindingContextUtils.java   View source code 4 votes vote down vote up
public SingleProviderContextImpl(ClassToInstanceMap<BindingAwareService> serviceProvider) {
    super(serviceProvider);
}
 
Example 34
Project: hashsdn-controller   File: BindingDOMAdapterBuilder.java   View source code 4 votes vote down vote up
@Override
protected final T createInstance(final ClassToInstanceMap<DOMService> delegates) {
    Preconditions.checkState(codec != null);
    return createInstance(codec,delegates);
}
 
Example 35
Project: hashsdn-controller   File: BindingDOMDataBrokerAdapter.java   View source code 4 votes vote down vote up
@Override
protected DataBroker createInstance(final BindingToNormalizedNodeCodec codec,
        final ClassToInstanceMap<DOMService> delegates) {
    final DOMDataBroker domDataBroker = delegates.getInstance(DOMDataBroker.class);
    return new BindingDOMDataBrokerAdapter(domDataBroker, codec);
}
 
Example 36
Project: hashsdn-controller   File: BindingDOMRpcServiceAdapter.java   View source code 4 votes vote down vote up
@Override
protected RpcConsumerRegistry createInstance(final BindingToNormalizedNodeCodec codec,
        final ClassToInstanceMap<DOMService> delegates) {
    final DOMRpcService domRpc  = delegates.getInstance(DOMRpcService.class);
    return new BindingDOMRpcServiceAdapter(domRpc  , codec);
}
 
Example 37
Project: hashsdn-controller   File: BindingDOMNotificationPublishServiceAdapter.java   View source code 4 votes vote down vote up
@Override
protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
        final ClassToInstanceMap<DOMService> delegates) {
    final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
    return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
}
 
Example 38
Project: hashsdn-controller   File: BindingDOMNotificationServiceAdapter.java   View source code 4 votes vote down vote up
@Override
protected NotificationService createInstance(final BindingToNormalizedNodeCodec codec,
        final ClassToInstanceMap<DOMService> delegates) {
    final DOMNotificationService domNotification = delegates.getInstance(DOMNotificationService.class);
    return new BindingDOMNotificationServiceAdapter(codec.getCodecRegistry(), domNotification);
}
 
Example 39
Project: hashsdn-controller   File: DomBrokerImplModule.java   View source code 4 votes vote down vote up
@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;
}
 
Example 40
Project: FinanceAnalytics   File: DiscountingMulticurveBundleFnTest.java   View source code 4 votes vote down vote up
@BeforeClass
public void init() throws IOException {
  //builds graph, initializing mocks
  
  ClassToInstanceMap<Object> mocks = MockUtils.mocks(MOCK_CLASSES);
  
  initConfigSource(mocks.getInstance(ConfigSource.class));
  initConventionSource(mocks.getInstance(ConventionSource.class));
  initSecuritySource(mocks.getInstance(SecuritySource.class));
  initRegionSource(mocks.getInstance(RegionSource.class));
  
  mocks.putInstance(RootFinderConfiguration.class, ROOT_FINDER_CONFIG);
  mocks.putInstance(HolidaySource.class, new WeekendHolidaySource());

  mocks.putInstance(LegalEntitySource.class, mock(LegalEntitySource.class));
  mocks.putInstance(ConventionBundleSource.class, mock(ConventionBundleSource.class));
  ComponentMap components = ComponentMap.of(mocks);
  
  FunctionModelConfig config = config(
      arguments(
          function(DefaultDiscountingMulticurveBundleFn.class,
                   argument("impliedCurveNames", StringSet.of("Implied Deposit Curve KRW"))),
          function(DefaultCurveNodeConverterFn.class,
                   argument("timeSeriesDuration", RetrievalPeriod.of(Period.ofDays(1))))),
      implementations(CurveDefinitionFn.class, DefaultCurveDefinitionFn.class,
                      CurveSpecificationFn.class, DefaultCurveSpecificationFn.class,
                      CurveSpecificationMarketDataFn.class, DefaultCurveSpecificationMarketDataFn.class,
                      CurveNodeConverterFn.class, DefaultCurveNodeConverterFn.class,
                      FXMatrixFn.class, DefaultFXMatrixFn.class,
                      DiscountingMulticurveBundleFn.class, DefaultDiscountingMulticurveBundleFn.class,
                      DiscountingMulticurveBundleResolverFn.class, DefaultDiscountingMulticurveBundleResolverFn.class,
                      MarketDataFn.class, DefaultMarketDataFn.class));

  _multicurveBundleFn = FunctionModel.build(DiscountingMulticurveBundleResolverFn.class, config, components);
  
  ZonedDateTime valuationDate = ZonedDateTime.of(2014, 1, 10, 11, 0, 0, 0, ZoneId.of("America/Chicago"));
  MarketDataBundle marketDataBundle =
      MarketDataResourcesLoader.getPreloadedBundle(
          "/regression/curve_testing/usdMarketQuotes.properties",
                                                   "Ticker");

  _environment = new SimpleEnvironment(valuationDate, marketDataBundle);
  
  VersionCorrectionProvider vcProvider = new TestVersionCorrectionProvider();
  
  ServiceContext serviceContext = ServiceContext.of(mocks).with(VersionCorrectionProvider.class, vcProvider);
  ThreadLocalServiceContext.init(serviceContext);
  
  _usdDiscountingCCC = createUSDCurveConstructionConfig();
}